@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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "registry": "https://registry.npmjs.org/",
5
5
  "access": "public"
6
6
  },
7
- "version": "1.55.0",
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.3.0"
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": "c126e4444503e4c9964e0cc024f257ef35ce557a7de53b5e282ed85a"
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. Identity
34
- * guards keep the single-React case a no-op.
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` (covers cases
138
- * where the host bundles its own React separately from the user's).
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
- // Identity guards below skip patching when the resolved modules are the same
178
- // objects already covered by the host-side patches.
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
- // user bundle path doesn't resolve react locally nothing to patch
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 element = React.createElement(Component, componentProps as Record<string, unknown>)
249
- return renderToStaticMarkup(element)
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