@wix/zero-config-implementation 1.77.0 → 1.78.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-DRWoSsTZ.js → index--6I20lGB.js} +23381 -24272
- package/dist/{index-CuKmaUAA.js → index-DAAmOM1c.js} +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/component-renderer.ts +90 -0
- package/src/react-runtime-loader.ts +21 -6
- package/dist/index-BGHyk7CU.js +0 -708
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as t, D as e, E as o, I as n, N as c, P as l, R as i, a as p, V as E, b as m, c as x, d as f, e as d, f as u, h as C, i as I, j as k, k as y, l as A, m as D, n as P, o as R, p as h, q as B, r as M, s as T, t as b, w } from "./index
|
|
1
|
+
import { B as t, D as e, E as o, I as n, N as c, P as l, R as i, a as p, V as E, b as m, c as x, d as f, e as d, f as u, h as C, i as I, j as k, k as y, l as A, m as D, n as P, o as R, p as h, q as B, r as M, s as T, t as b, w } from "./index--6I20lGB.js";
|
|
2
2
|
import "react";
|
|
3
3
|
export {
|
|
4
4
|
t as BaseError,
|
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.78.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",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@wix/builder-services-wrapper": "^1.
|
|
42
|
+
"@wix/builder-services-wrapper": "^1.56.0",
|
|
43
43
|
"@wix/react-component-schema": "1.7.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
]
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
|
-
"falconPackageHash": "
|
|
85
|
+
"falconPackageHash": "7ea33e17604c8d13038271d43e3350d8bb9d9531ec0110efca2a7144"
|
|
86
86
|
}
|
|
@@ -76,6 +76,7 @@ import {
|
|
|
76
76
|
setCreateElementInterceptor,
|
|
77
77
|
setJsxInterceptors,
|
|
78
78
|
} from './react-runtime-interceptor'
|
|
79
|
+
import { getActiveReactModule, setActiveReactModule } from './react-runtime-loader'
|
|
79
80
|
|
|
80
81
|
export const TRACE_ATTR = 'data-trace-id'
|
|
81
82
|
|
|
@@ -132,6 +133,84 @@ function createInterceptor(
|
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
|
|
136
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
137
|
+
// Dispatcher bridge
|
|
138
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
const REACT_18_INTERNALS_KEY = '__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED'
|
|
141
|
+
const REACT_19_INTERNALS_KEY = '__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE'
|
|
142
|
+
|
|
143
|
+
function readReactInternals(reactModule: unknown): Record<string, unknown> | undefined {
|
|
144
|
+
if (typeof reactModule !== 'object' || reactModule === null) {
|
|
145
|
+
return undefined
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const reactRecord = reactModule as Record<string, unknown>
|
|
149
|
+
const internals = reactRecord[REACT_18_INTERNALS_KEY] ?? reactRecord[REACT_19_INTERNALS_KEY]
|
|
150
|
+
return typeof internals === 'object' && internals !== null ? (internals as Record<string, unknown>) : undefined
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Forwards the host React's hook dispatcher to the user React so host-bound hook
|
|
155
|
+
* callers (e.g. WixServicesWrapper) resolve the dispatcher the user's react-dom
|
|
156
|
+
* installs during SSR. Returns a function that restores the host React.
|
|
157
|
+
*/
|
|
158
|
+
function bridgeHostDispatcherToUserReact(hostReact: unknown, userReact: unknown): () => void {
|
|
159
|
+
const hostInternals = readReactInternals(hostReact)
|
|
160
|
+
const userInternals = readReactInternals(userReact)
|
|
161
|
+
if (!hostInternals || !userInternals) {
|
|
162
|
+
return () => {}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// React 18 exposes a `{ current }` holder captured by reference at load time, so
|
|
166
|
+
// forward its `current` to the user holder rather than swapping the holder itself.
|
|
167
|
+
if (hostInternals.ReactCurrentDispatcher && userInternals.ReactCurrentDispatcher) {
|
|
168
|
+
const hostDispatcherHolder = hostInternals.ReactCurrentDispatcher as Record<string, unknown>
|
|
169
|
+
const userDispatcherHolder = userInternals.ReactCurrentDispatcher as Record<string, unknown>
|
|
170
|
+
if (hostDispatcherHolder === userDispatcherHolder) {
|
|
171
|
+
return () => {}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const previousDescriptor = Object.getOwnPropertyDescriptor(hostDispatcherHolder, 'current')
|
|
175
|
+
Object.defineProperty(hostDispatcherHolder, 'current', {
|
|
176
|
+
configurable: true,
|
|
177
|
+
get: () => userDispatcherHolder.current,
|
|
178
|
+
set: (dispatcher) => {
|
|
179
|
+
userDispatcherHolder.current = dispatcher
|
|
180
|
+
},
|
|
181
|
+
})
|
|
182
|
+
return () => {
|
|
183
|
+
Object.defineProperty(
|
|
184
|
+
hostDispatcherHolder,
|
|
185
|
+
'current',
|
|
186
|
+
previousDescriptor ?? { configurable: true, enumerable: true, value: null, writable: true },
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// React 19 keeps the dispatcher directly on the internals object as `H`, so
|
|
192
|
+
// forward that property to the user internals.
|
|
193
|
+
if ('H' in userInternals) {
|
|
194
|
+
const previousDescriptor = Object.getOwnPropertyDescriptor(hostInternals, 'H')
|
|
195
|
+
Object.defineProperty(hostInternals, 'H', {
|
|
196
|
+
configurable: true,
|
|
197
|
+
get: () => userInternals.H,
|
|
198
|
+
set: (dispatcher) => {
|
|
199
|
+
userInternals.H = dispatcher
|
|
200
|
+
},
|
|
201
|
+
})
|
|
202
|
+
return () => {
|
|
203
|
+
Object.defineProperty(
|
|
204
|
+
hostInternals,
|
|
205
|
+
'H',
|
|
206
|
+
previousDescriptor ?? { configurable: true, enumerable: true, value: undefined, writable: true },
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return () => {}
|
|
212
|
+
}
|
|
213
|
+
|
|
135
214
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
136
215
|
// Renderer
|
|
137
216
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -248,6 +327,12 @@ export function renderWithExtractors(
|
|
|
248
327
|
const interceptedJsxs = createInterceptor(originalJsxs as ElementCreator, listeners, getNextId, store)
|
|
249
328
|
const interceptedJsxDEV = createInterceptor(originalJsxDEV as ElementCreator, listeners, getNextId, store)
|
|
250
329
|
|
|
330
|
+
// The shim reads globalThis[REACT_KEY] on every hook call, so pointing it at
|
|
331
|
+
// userReact ensures ESM hooks use the same dispatcher that SSR drives.
|
|
332
|
+
const previousActiveReactModule = getActiveReactModule()
|
|
333
|
+
// Restores the host React's hook dispatcher, bridged to the user React below.
|
|
334
|
+
let restoreHostDispatcher: () => void = () => {}
|
|
335
|
+
|
|
251
336
|
try {
|
|
252
337
|
// @ts-expect-error Monkey-patch createElement for default-import callers
|
|
253
338
|
React.createElement = interceptedCreateElement
|
|
@@ -268,6 +353,9 @@ export function renderWithExtractors(
|
|
|
268
353
|
// Patch user-bundle React modules when they are distinct instances
|
|
269
354
|
if (userReact) {
|
|
270
355
|
userReact.createElement = interceptedCreateElement
|
|
356
|
+
setActiveReactModule(userReact)
|
|
357
|
+
// Host-bound hook callers (e.g. WixServicesWrapper) need the user React's dispatcher too.
|
|
358
|
+
restoreHostDispatcher = bridgeHostDispatcherToUserReact(React, userReact)
|
|
271
359
|
}
|
|
272
360
|
if (userJsxRuntime) {
|
|
273
361
|
userJsxRuntime.jsx = interceptedJsx
|
|
@@ -281,6 +369,8 @@ export function renderWithExtractors(
|
|
|
281
369
|
const element = renderingReact.createElement(Component, componentProps as Record<string, unknown>)
|
|
282
370
|
return (userRenderToStaticMarkup ?? renderToStaticMarkup)(element)
|
|
283
371
|
} finally {
|
|
372
|
+
restoreHostDispatcher()
|
|
373
|
+
setActiveReactModule(previousActiveReactModule)
|
|
284
374
|
// Restore originals
|
|
285
375
|
// @ts-expect-error Restore monkey-patched createElement
|
|
286
376
|
React.createElement = originalCreateElement
|
|
@@ -8,6 +8,7 @@ import type { RefElementModule } from './ref-elements/types'
|
|
|
8
8
|
const JSX_INTERCEPTOR_STATE_KEY = 'zero-config:jsx-interceptor'
|
|
9
9
|
const JSX_ORIGINALS_KEY = 'zero-config:jsx-originals'
|
|
10
10
|
const REACT_ORIGINALS_KEY = 'zero-config:react-originals'
|
|
11
|
+
const REACT_ORIGINALS_SYMBOL = Symbol.for(REACT_ORIGINALS_KEY)
|
|
11
12
|
const LOADER_REGISTERED_KEY = Symbol.for('zero-config:jsx-loader-registered')
|
|
12
13
|
const RUNTIME_STATE_KEY = Symbol.for('zero-config:ref-element-runtime-state')
|
|
13
14
|
const REF_ELEMENT_LOADER_REQUEST_TIMEOUT_MS = 1_000
|
|
@@ -128,9 +129,9 @@ export function ensureReactRuntimeLoader(): void {
|
|
|
128
129
|
jsxDEV: reactDevRuntime.jsxDEV,
|
|
129
130
|
jsxs: reactRuntime.jsxs,
|
|
130
131
|
}
|
|
131
|
-
;(globalThis as Record<PropertyKey, unknown>)[
|
|
132
|
+
;(globalThis as Record<PropertyKey, unknown>)[REACT_ORIGINALS_SYMBOL] = reactModule
|
|
132
133
|
|
|
133
|
-
const reactModuleUrl = `data:text/javascript,${encodeURIComponent(buildReactModuleShimSource(
|
|
134
|
+
const reactModuleUrl = `data:text/javascript,${encodeURIComponent(buildReactModuleShimSource(reactModule))}`
|
|
134
135
|
const interceptorModuleUrl = `data:text/javascript,${encodeURIComponent(buildJsxRuntimeInterceptorSource())}`
|
|
135
136
|
const loaderSource = buildReactRuntimeLoaderSource({
|
|
136
137
|
interceptorModuleUrl,
|
|
@@ -151,6 +152,14 @@ export function ensureReactRuntimeLoader(): void {
|
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
|
|
155
|
+
export function getActiveReactModule(): unknown {
|
|
156
|
+
return (globalThis as Record<symbol, unknown>)[REACT_ORIGINALS_SYMBOL]
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function setActiveReactModule(reactModule: unknown): void {
|
|
160
|
+
;(globalThis as Record<symbol, unknown>)[REACT_ORIGINALS_SYMBOL] = reactModule
|
|
161
|
+
}
|
|
162
|
+
|
|
154
163
|
export function readRegisteredRefElementModuleUrlsForTests(): string[] {
|
|
155
164
|
return [...readRefElementRuntimeState().registeredEsmModulesByResolvedUrl.keys()]
|
|
156
165
|
}
|
|
@@ -483,14 +492,20 @@ function isComponent(value: unknown): boolean {
|
|
|
483
492
|
return typeof value === 'object' && value !== null && '$$typeof' in value
|
|
484
493
|
}
|
|
485
494
|
|
|
486
|
-
function buildReactModuleShimSource(
|
|
487
|
-
const reactExportLines =
|
|
495
|
+
function buildReactModuleShimSource(reactModule: Record<string, unknown>): string {
|
|
496
|
+
const reactExportLines = Object.keys(reactModule)
|
|
488
497
|
.map((exportName) => {
|
|
489
498
|
if (exportName === 'createElement') {
|
|
490
499
|
return `export function createElement() {
|
|
491
500
|
var state = globalThis[STATE_KEY];
|
|
492
501
|
if (state && state.currentCreateElement) return state.currentCreateElement.apply(null, arguments);
|
|
493
|
-
return
|
|
502
|
+
return globalThis[REACT_KEY].createElement.apply(null, arguments);
|
|
503
|
+
}`
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (exportName.startsWith('use') && typeof reactModule[exportName] === 'function') {
|
|
507
|
+
return `export function ${exportName}() {
|
|
508
|
+
return globalThis[REACT_KEY].${exportName}.apply(null, arguments);
|
|
494
509
|
}`
|
|
495
510
|
}
|
|
496
511
|
|
|
@@ -502,7 +517,7 @@ function buildReactModuleShimSource(reactExportNames: string[]): string {
|
|
|
502
517
|
var REACT_KEY = Symbol.for(${JSON.stringify(REACT_ORIGINALS_KEY)});
|
|
503
518
|
var STATE_KEY = Symbol.for(${JSON.stringify(JSX_INTERCEPTOR_STATE_KEY)});
|
|
504
519
|
var reactModule = globalThis[REACT_KEY];
|
|
505
|
-
export default
|
|
520
|
+
export default new Proxy({}, { get: function(_, prop) { return globalThis[REACT_KEY][prop]; } });
|
|
506
521
|
${reactExportLines}
|
|
507
522
|
`
|
|
508
523
|
}
|