13
import type {HintCode, HintModel} from '../server/ReactFlightServerConfigDOM';
14
15
import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
16
-const ReactDOMCurrentDispatcher = ReactDOMSharedInternals.Dispatcher;
16
+const ReactDOMCurrentDispatcher =
17
+ ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
18
19
import {getCrossOriginString} from './crossOriginStrings';
20
23
model: HintModel<Code>,
24
): void {
25
const dispatcher = ReactDOMCurrentDispatcher.current;
25
- if (dispatcher) {
26
- switch (code) {
27
- case 'D': {
28
- const refined = refineModel(code, model);
26
+ switch (code) {
27
+ case 'D': {
28
+ const refined = refineModel(code, model);
29
+ const href = refined;
30
+ dispatcher.prefetchDNS(href);
31
+ return;
32
+ }
33
+ case 'C': {
34
+ const refined = refineModel(code, model);
35
+ if (typeof refined === 'string') {
36
const href = refined;
30
- dispatcher.prefetchDNS(href);
31
- return;
37
+ dispatcher.preconnect(href);
38
+ } else {
39
+ const href = refined[0];
40
+ const crossOrigin = refined[1];
41
+ dispatcher.preconnect(href, crossOrigin);
42
}
33
- case 'C': {
34
- const refined = refineModel(code, model);
35
- if (typeof refined === 'string') {
36
- const href = refined;
37
- dispatcher.preconnect(href);
38
- } else {
39
- const href = refined[0];
40
- const crossOrigin = refined[1];
41
- dispatcher.preconnect(href, crossOrigin);
42
- }
43
- return;
43
+ return;
44
+ }
45
+ case 'L': {
46
+ const refined = refineModel(code, model);
47
+ const href = refined[0];
48
+ const as = refined[1];
49
+ if (refined.length === 3) {
50
+ const options = refined[2];
51
+ dispatcher.preload(href, as, options);
52
+ } else {
53
+ dispatcher.preload(href, as);
54
}
45
- case 'L': {
46
- const refined = refineModel(code, model);
55
+ return;
56
+ }
57
+ case 'm': {
58
+ const refined = refineModel(code, model);
59
+ if (typeof refined === 'string') {
60
+ const href = refined;
61
+ dispatcher.preloadModule(href);
62
+ } else {
63
const href = refined[0];
48
- const as = refined[1];
49
- if (refined.length === 3) {
50
- const options = refined[2];
51
- dispatcher.preload(href, as, options);
52
- } else {
53
- dispatcher.preload(href, as);
54
- }
55
- return;
64
+ const options = refined[1];
65
+ dispatcher.preloadModule(href, options);
66
}
57
- case 'm': {
58
- const refined = refineModel(code, model);
59
- if (typeof refined === 'string') {
60
- const href = refined;
61
- dispatcher.preloadModule(href);
62
- } else {
63
- const href = refined[0];
64
- const options = refined[1];
65
- dispatcher.preloadModule(href, options);
66
- }
67
- return;
68
- }
69
- case 'S': {
70
- const refined = refineModel(code, model);
71
- if (typeof refined === 'string') {
72
- const href = refined;
73
- dispatcher.preinitStyle(href);
74
- } else {
75
- const href = refined[0];
76
- const precedence = refined[1] === 0 ? undefined : refined[1];
77
- const options = refined.length === 3 ? refined[2] : undefined;
78
- dispatcher.preinitStyle(href, precedence, options);
79
- }
80
- return;
67
+ return;
68
+ }
69
+ case 'S': {
70
+ const refined = refineModel(code, model);
71
+ if (typeof refined === 'string') {
72
+ const href = refined;
73
+ dispatcher.preinitStyle(href);
74
+ } else {
75
+ const href = refined[0];
76
+ const precedence = refined[1] === 0 ? undefined : refined[1];
77
+ const options = refined.length === 3 ? refined[2] : undefined;
78
+ dispatcher.preinitStyle(href, precedence, options);
79
}
82
- case 'X': {
83
- const refined = refineModel(code, model);
84
- if (typeof refined === 'string') {
85
- const href = refined;
86
- dispatcher.preinitScript(href);
87
- } else {
88
- const href = refined[0];
89
- const options = refined[1];
90
- dispatcher.preinitScript(href, options);
91
- }
92
- return;
80
+ return;
81
+ }
82
+ case 'X': {
83
+ const refined = refineModel(code, model);
84
+ if (typeof refined === 'string') {
85
+ const href = refined;
86
+ dispatcher.preinitScript(href);
87
+ } else {
88
+ const href = refined[0];
89
+ const options = refined[1];
90
+ dispatcher.preinitScript(href, options);
91
}
94
- case 'M': {
95
- const refined = refineModel(code, model);
96
- if (typeof refined === 'string') {
97
- const href = refined;
98
- dispatcher.preinitModuleScript(href);
99
- } else {
100
- const href = refined[0];
101
- const options = refined[1];
102
- dispatcher.preinitModuleScript(href, options);
103
- }
104
- return;
92
+ return;
93
+ }
94
+ case 'M': {
95
+ const refined = refineModel(code, model);
96
+ if (typeof refined === 'string') {
97
+ const href = refined;
98
+ dispatcher.preinitModuleScript(href);
99
+ } else {
100
+ const href = refined[0];
101
+ const options = refined[1];
102
+ dispatcher.preinitModuleScript(href, options);
103
}
104
+ return;
105
}
106
}
107
}