@@ -10,54 +10,40 @@ export let createTransformValue: (transform: any) => any;
1010export let createTextShadowValue : ( style : any ) => void | string ;
1111
1212// react-native-web exposes these style helpers only via internal modules. Metro
13- // has require() so we load them synchronously (unchanged); strict-ESM bundlers
14- // and SSR don't, which left them undefined and crashed _updatePropsJS (#9844), so
15- // there we import() the dist/cjs build instead (dist/exports' extensionless
16- // imports fail Node's ESM resolver). If neither resolves, the helpers stay
17- // undefined and the DOM branch is skipped, as on native.
18-
19- let loadedSynchronously = false ;
20-
21- if ( typeof require === 'function' ) {
22- try {
23- createReactDOMStyle =
24- // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, n/no-unpublished-require
25- require ( 'react-native-web/dist/exports/StyleSheet/compiler/createReactDOMStyle' ) . default ;
26- loadedSynchronously = createReactDOMStyle !== undefined ;
27- // eslint-disable-next-line no-empty
28- } catch ( _e ) { }
29-
30- try {
31- // React Native Web 0.19+
32- createTransformValue =
33- // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, n/no-unpublished-require
34- require ( 'react-native-web/dist/exports/StyleSheet/preprocess' ) . createTransformValue ;
35- // eslint-disable-next-line no-empty
36- } catch ( _e ) { }
37-
38- try {
39- createTextShadowValue =
40- // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, n/no-unpublished-require
41- require ( 'react-native-web/dist/exports/StyleSheet/preprocess' ) . createTextShadowValue ;
42- // eslint-disable-next-line no-empty
43- } catch ( _e ) { }
44- }
45-
46- if ( ! loadedSynchronously ) {
47- // The cjs export may arrive as `.default` (bundler/Node interop) or as the
48- // namespace itself; handle both.
49- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50- const interopDefault = ( moduleExports : any ) =>
51- moduleExports ?. default ?? moduleExports ;
52-
13+ // has require() so we load them synchronously; strict-ESM bundlers and SSR don't,
14+ // so require() throws and we fall back to import()ing the dist/cjs build
15+ // (dist/exports' extensionless imports fail Node's ESM resolver). If neither
16+ // resolves, the helpers stay undefined and the DOM branch is skipped, as on native.
17+ //
18+ // Kept as a single top-level try/catch (no top-level `if` or IIFE) so the module
19+ // stays tree-shakable - see the is-tree-shakable check.
20+ try {
21+ createReactDOMStyle =
22+ // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, n/no-unpublished-require
23+ require ( 'react-native-web/dist/exports/StyleSheet/compiler/createReactDOMStyle' ) . default ;
24+ // React Native Web 0.19+
25+ const preprocess =
26+ // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, n/no-unpublished-require
27+ require ( 'react-native-web/dist/exports/StyleSheet/preprocess' ) ;
28+ createTransformValue = preprocess . createTransformValue ;
29+ createTextShadowValue = preprocess . createTextShadowValue ;
30+ } catch ( _e ) {
31+ // No require() (strict ESM / SSR), or a helper module was missing: load the
32+ // helpers from the dist/cjs build instead.
5333 void ( async ( ) => {
34+ // The cjs export may arrive as `.default` (bundler/Node interop) or as the
35+ // namespace itself; handle both.
36+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37+ const interopDefault = ( moduleExports : any ) =>
38+ moduleExports ?. default ?? moduleExports ;
39+
5440 try {
5541 const styleModule = await import (
5642 // eslint-disable-next-line n/no-unpublished-import
5743 'react-native-web/dist/cjs/exports/StyleSheet/compiler/createReactDOMStyle.js'
5844 ) ;
5945 createReactDOMStyle = interopDefault ( styleModule ) ;
60- } catch ( _e ) {
46+ } catch ( _e2 ) {
6147 // Unresolved: the DOM update branch stays disabled, as on native.
6248 }
6349
@@ -70,7 +56,7 @@ if (!loadedSynchronously) {
7056 const preprocess = interopDefault ( preprocessModule ) ;
7157 createTransformValue = preprocess . createTransformValue ;
7258 createTextShadowValue = preprocess . createTextShadowValue ;
73- } catch ( _e ) {
59+ } catch ( _e2 ) {
7460 // Optional: leaving them undefined just skips transform/textShadow.
7561 }
7662 } ) ( ) ;
0 commit comments