2412
if (!resource) {
2413
// We asserted this above but Flow can't figure out that the type satisfies
2414
const ownerDocument = getDocumentFromRoot(resourceRoot);
2415
- resource = {
2415
+ resource = ({
2416
type: 'stylesheet',
2417
instance: null,
2418
count: 0,
2420
loading: NotLoaded,
2421
preload: null,
2422
},
2423
- };
2423
+ }: StylesheetResource);
2424
styles.set(key, resource);
2425
+ const instance = ownerDocument.querySelector(
2426
+ getStylesheetSelectorFromKey(key),
2427
+ );
2428
+ if (instance) {
2429
+ const loadingState: ?Promise<mixed> = (instance: any)._p;
2430
+ if (loadingState) {
2431
+ // This instance is inserted as part of a boundary reveal and is not yet
2432
+ // loaded
2433
+ } else {
2434
+ // This instance is already loaded
2435
+ resource.instance = instance;
2436
+ resource.state.loading = Loaded | Inserted;
2437
+ }
2438
+ }
2439
+
2440
if (!preloadPropsMap.has(key)) {
2426
- preloadStylesheet(
2427
- ownerDocument,
2428
- key,
2429
- preloadPropsFromStylesheet(qualifiedProps),
2430
- resource.state,
2431
- );
2441
+ const preloadProps = preloadPropsFromStylesheet(qualifiedProps);
2442
+ preloadPropsMap.set(key, preloadProps);
2443
+ if (!instance) {
2444
+ preloadStylesheet(
2445
+ ownerDocument,
2446
+ key,
2447
+ preloadProps,
2448
+ resource.state,
2449
+ );
2450
+ }
2451
}
2452
}
2453
if (currentProps && currentResource === null) {
2618
preloadProps: PreloadProps,
2619
state: StylesheetState,
2620
) {
2602
- preloadPropsMap.set(key, preloadProps);
2603
-
2604
- if (!ownerDocument.querySelector(getStylesheetSelectorFromKey(key))) {
2605
- // There is no matching stylesheet instance in the Document.
2606
- // We will insert a preload now to kick off loading because
2607
- // we expect this stylesheet to commit
2608
- const preloadEl = ownerDocument.querySelector(
2609
- getPreloadStylesheetSelectorFromKey(key),
2610
- );
2611
- if (preloadEl) {
2612
- // If we find a preload already it was SSR'd and we won't have an actual
2613
- // loading state to track. For now we will just assume it is loaded
2614
- state.loading = Loaded;
2615
- } else {
2616
- const instance = ownerDocument.createElement('link');
2617
- state.preload = instance;
2618
- instance.addEventListener('load', () => (state.loading |= Loaded));
2619
- instance.addEventListener('error', () => (state.loading |= Errored));
2620
- setInitialProperties(instance, 'link', preloadProps);
2621
- markNodeAsHoistable(instance);
2622
- (ownerDocument.head: any).appendChild(instance);
2623
- }
2621
+ const preloadEl = ownerDocument.querySelector(
2622
+ getPreloadStylesheetSelectorFromKey(key),
2623
+ );
2624
+ if (preloadEl) {
2625
+ // If we find a preload already it was SSR'd and we won't have an actual
2626
+ // loading state to track. For now we will just assume it is loaded
2627
+ state.loading = Loaded;
2628
+ } else {
2629
+ const instance = ownerDocument.createElement('link');
2630
+ state.preload = instance;
2631
+ instance.addEventListener('load', () => (state.loading |= Loaded));
2632
+ instance.addEventListener('error', () => (state.loading |= Errored));
2633
+ setInitialProperties(instance, 'link', preloadProps);
2634
+ markNodeAsHoistable(instance);
2635
+ (ownerDocument.head: any).appendChild(instance);
2636
}
2637
}
2638