( href: string, precedence: ?string, options?: ?PreinitStyleOptions, )
| 4828 | } |
| 4829 | |
| 4830 | function preinitStyle( |
| 4831 | href: string, |
| 4832 | precedence: ?string, |
| 4833 | options?: ?PreinitStyleOptions, |
| 4834 | ) { |
| 4835 | previousDispatcher.S(/* preinitStyle */ href, precedence, options); |
| 4836 | |
| 4837 | const ownerDocument = getGlobalDocument(); |
| 4838 | if (ownerDocument && href) { |
| 4839 | const styles = getResourcesFromRoot(ownerDocument).hoistableStyles; |
| 4840 | |
| 4841 | const key = getStyleKey(href); |
| 4842 | precedence = precedence || 'default'; |
| 4843 | |
| 4844 | // Check if this resource already exists |
| 4845 | let resource = styles.get(key); |
| 4846 | if (resource) { |
| 4847 | // We can early return. The resource exists and there is nothing |
| 4848 | // more to do |
| 4849 | return; |
| 4850 | } |
| 4851 | |
| 4852 | const state = { |
| 4853 | loading: NotLoaded, |
| 4854 | preload: null, |
| 4855 | }; |
| 4856 | |
| 4857 | // Attempt to hydrate instance from DOM |
| 4858 | let instance: null | Instance = ownerDocument.querySelector( |
| 4859 | getStylesheetSelectorFromKey(key), |
| 4860 | ); |
| 4861 | if (instance) { |
| 4862 | state.loading = Loaded | Inserted; |
| 4863 | } else { |
| 4864 | // Construct a new instance and insert it |
| 4865 | const stylesheetProps = Object.assign( |
| 4866 | ({ |
| 4867 | rel: 'stylesheet', |
| 4868 | href, |
| 4869 | 'data-precedence': precedence, |
| 4870 | }: StylesheetProps), |
| 4871 | options, |
| 4872 | ); |
| 4873 | const preloadProps = preloadPropsMap.get(key); |
| 4874 | if (preloadProps) { |
| 4875 | adoptPreloadPropsForStylesheet(stylesheetProps, preloadProps); |
| 4876 | } |
| 4877 | const link = (instance = ownerDocument.createElement('link')); |
| 4878 | markNodeAsHoistable(link); |
| 4879 | setInitialProperties(link, 'link', stylesheetProps); |
| 4880 | |
| 4881 | (link: any)._p = new Promise((resolve, reject) => { |
| 4882 | link.onload = resolve; |
| 4883 | link.onerror = reject; |
| 4884 | }); |
| 4885 | link.addEventListener('load', () => { |
| 4886 | state.loading |= Loaded; |
| 4887 | }); |
nothing calls this directly
no test coverage detected