@wix/zero-config-implementation 1.55.0 → 1.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1261 -1250
- package/package.json +3 -3
- package/src/component-renderer.ts +29 -10
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"registry": "https://registry.npmjs.org/",
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.57.0",
|
|
8
8
|
"description": "Core library for extracting component manifests from JS and CSS files",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "dist/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@wix/react-component-schema": "1.
|
|
47
|
+
"@wix/react-component-schema": "1.4.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@faker-js/faker": "^10.2.0",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
]
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
|
-
"falconPackageHash": "
|
|
88
|
+
"falconPackageHash": "4bf67c86fbcf48e852357c95257847e893cf3fac4b102da995bb8c5c"
|
|
89
89
|
}
|
|
@@ -30,8 +30,11 @@
|
|
|
30
30
|
* location on disk — a separate React module instance. To cover this case,
|
|
31
31
|
* the renderer also calls `createRequire(compiledEntryPath)` to obtain the
|
|
32
32
|
* user-bundle's React (and `react/jsx-runtime` / `react/jsx-dev-runtime`)
|
|
33
|
-
* and applies the same interceptors to those modules' exports.
|
|
34
|
-
*
|
|
33
|
+
* and applies the same interceptors to those modules' exports. It also
|
|
34
|
+
* drives SSR with the user-bundle's `react-dom/server` so the dispatcher
|
|
35
|
+
* lands on the user React's internals — the same instance the user
|
|
36
|
+
* component reads from — and hooks like `useState` work naturally.
|
|
37
|
+
* Identity guards keep the single-React case a no-op.
|
|
35
38
|
*
|
|
36
39
|
* ## Intercepted Functions
|
|
37
40
|
*
|
|
@@ -134,8 +137,9 @@ function createInterceptor(
|
|
|
134
137
|
* @param store - Shared ExtractorStore, included in each CreateElementEvent
|
|
135
138
|
* @param compiledEntryPath - Optional path to the user's compiled bundle. When
|
|
136
139
|
* provided, the renderer additionally patches the React module instance
|
|
137
|
-
* that the bundle resolves from its own `node_modules`
|
|
138
|
-
*
|
|
140
|
+
* that the bundle resolves from its own `node_modules` and drives SSR
|
|
141
|
+
* with the user-bundle's `react-dom/server` (required when the host
|
|
142
|
+
* bundles its own React; otherwise hooks crash).
|
|
139
143
|
* @returns Static HTML string with trace IDs on DOM elements
|
|
140
144
|
*
|
|
141
145
|
* @example
|
|
@@ -174,9 +178,11 @@ export function renderWithExtractors(
|
|
|
174
178
|
// Resolve the user-bundle's React (and jsx-runtime variants) from the bundle's
|
|
175
179
|
// own location on disk. When the host (e.g. a CLI) bundled its own React, this
|
|
176
180
|
// resolves to a different module instance and must be patched separately.
|
|
177
|
-
//
|
|
178
|
-
//
|
|
181
|
+
// When the user's React is distinct, also resolve its `react-dom/server` and
|
|
182
|
+
// drive SSR with that — the dispatcher then lands on the same React instance
|
|
183
|
+
// the user component reads from, so hooks like `useState` work naturally.
|
|
179
184
|
let userReact: { createElement: ElementCreator } | undefined
|
|
185
|
+
let userRenderToStaticMarkup: typeof renderToStaticMarkup | undefined
|
|
180
186
|
let userJsxRuntime: Record<string, unknown> | undefined
|
|
181
187
|
let userJsxDevRuntime: Record<string, unknown> | undefined
|
|
182
188
|
let origUserCreateElement: ElementCreator | undefined
|
|
@@ -191,6 +197,16 @@ export function renderWithExtractors(
|
|
|
191
197
|
if (candidateReact !== (React as unknown as typeof candidateReact)) {
|
|
192
198
|
userReact = candidateReact
|
|
193
199
|
origUserCreateElement = candidateReact.createElement
|
|
200
|
+
try {
|
|
201
|
+
userRenderToStaticMarkup = (
|
|
202
|
+
userRequire('react-dom/server') as { renderToStaticMarkup: typeof renderToStaticMarkup }
|
|
203
|
+
).renderToStaticMarkup
|
|
204
|
+
} catch (cause) {
|
|
205
|
+
throw new Error(
|
|
206
|
+
`Component bundle at "${compiledEntryPath}" resolves a different React than the host; install "react-dom" alongside "react" so SSR can run against the user's React.`,
|
|
207
|
+
{ cause: cause as Error },
|
|
208
|
+
)
|
|
209
|
+
}
|
|
194
210
|
}
|
|
195
211
|
const candidateJsx = userRequire('react/jsx-runtime') as Record<string, unknown>
|
|
196
212
|
if (candidateJsx !== cjsRuntime) {
|
|
@@ -203,8 +219,10 @@ export function renderWithExtractors(
|
|
|
203
219
|
userJsxDevRuntime = candidateJsxDev
|
|
204
220
|
origUserJsxDEV = candidateJsxDev.jsxDEV
|
|
205
221
|
}
|
|
206
|
-
} catch {
|
|
207
|
-
//
|
|
222
|
+
} catch (error) {
|
|
223
|
+
// The wrapped react-dom error has userReact set; rethrow it.
|
|
224
|
+
// Otherwise the user bundle path doesn't resolve react locally — nothing to patch.
|
|
225
|
+
if (userReact) throw error
|
|
208
226
|
}
|
|
209
227
|
}
|
|
210
228
|
|
|
@@ -245,8 +263,9 @@ export function renderWithExtractors(
|
|
|
245
263
|
userJsxDevRuntime.jsxDEV = interceptedJsxDEV
|
|
246
264
|
}
|
|
247
265
|
|
|
248
|
-
const
|
|
249
|
-
|
|
266
|
+
const renderingReact = userReact ?? React
|
|
267
|
+
const element = renderingReact.createElement(Component, componentProps as Record<string, unknown>)
|
|
268
|
+
return (userRenderToStaticMarkup ?? renderToStaticMarkup)(element)
|
|
250
269
|
} finally {
|
|
251
270
|
// Restore originals
|
|
252
271
|
React.createElement = originalCreateElement
|