@parcel/packager-react-static 2.16.2-canary.3489 → 2.16.3
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/lib/ReactStaticPackager.js +39 -20
- package/package.json +8 -8
- package/src/ReactStaticPackager.js +45 -24
|
@@ -171,6 +171,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
171
171
|
prerender
|
|
172
172
|
} = loadModule('react-dom/static.edge', __filename, 'react-client');
|
|
173
173
|
let React = loadModule('react', __filename, 'react-client');
|
|
174
|
+
let ReactDOM = loadModule('react-dom', __filename, 'react-server');
|
|
174
175
|
let {
|
|
175
176
|
createFromReadableStream
|
|
176
177
|
} = loadModule('react-server-dom-parcel/client.edge', __filename, 'react-client');
|
|
@@ -188,28 +189,15 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
188
189
|
...meta
|
|
189
190
|
}
|
|
190
191
|
};
|
|
191
|
-
let resources = [];
|
|
192
192
|
let bootstrapModules = [];
|
|
193
193
|
let entry;
|
|
194
|
-
|
|
194
|
+
let referencedBundles = bundleGraph.getReferencedBundles(bundle, {
|
|
195
195
|
includeInline: false,
|
|
196
196
|
includeIsolated: false
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
key: b.id,
|
|
201
|
-
rel: 'stylesheet',
|
|
202
|
-
href: (0, _utils().urlJoin)(b.target.publicUrl, b.name),
|
|
203
|
-
precedence: 'default'
|
|
204
|
-
}));
|
|
205
|
-
} else if (b.type === 'js' && b.env.isBrowser()) {
|
|
197
|
+
});
|
|
198
|
+
for (let b of referencedBundles) {
|
|
199
|
+
if (b.type === 'js' && b.env.isBrowser()) {
|
|
206
200
|
bootstrapModules.push((0, _utils().urlJoin)(b.target.publicUrl, b.name));
|
|
207
|
-
resources.push(React.createElement('script', {
|
|
208
|
-
key: b.id,
|
|
209
|
-
type: 'module',
|
|
210
|
-
async: true,
|
|
211
|
-
src: (0, _utils().urlJoin)(b.target.publicUrl, b.name)
|
|
212
|
-
}));
|
|
213
201
|
if (!entry) {
|
|
214
202
|
b.traverseAssets((a, ctx, actions) => {
|
|
215
203
|
if (Array.isArray(a.meta.directives) && a.meta.directives.includes('use client-entry')) {
|
|
@@ -220,7 +208,37 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
220
208
|
}
|
|
221
209
|
}
|
|
222
210
|
}
|
|
223
|
-
|
|
211
|
+
function Resources() {
|
|
212
|
+
let resources = [];
|
|
213
|
+
for (let b of referencedBundles) {
|
|
214
|
+
if (b.type === 'css') {
|
|
215
|
+
let href = (0, _utils().urlJoin)(b.target.publicUrl, b.name);
|
|
216
|
+
|
|
217
|
+
// Add preload hint so we start loading the stylesheet as soon
|
|
218
|
+
// as the RSC payload loads, without waiting for the component to mount.
|
|
219
|
+
ReactDOM.preload(href, {
|
|
220
|
+
as: 'style'
|
|
221
|
+
});
|
|
222
|
+
resources.push(React.createElement('link', {
|
|
223
|
+
key: b.id,
|
|
224
|
+
rel: 'stylesheet',
|
|
225
|
+
href,
|
|
226
|
+
precedence: 'default'
|
|
227
|
+
}));
|
|
228
|
+
} else if (b.type === 'js' && b.env.isBrowser()) {
|
|
229
|
+
resources.push(React.createElement('script', {
|
|
230
|
+
key: b.id,
|
|
231
|
+
type: 'module',
|
|
232
|
+
async: true,
|
|
233
|
+
src: (0, _utils().urlJoin)(b.target.publicUrl, b.name)
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return resources;
|
|
238
|
+
}
|
|
239
|
+
let stream = renderToReadableStream([React.createElement(Resources, {
|
|
240
|
+
key: 'resources'
|
|
241
|
+
}), React.createElement(Component, props)]);
|
|
224
242
|
let [s1, renderStream] = stream.tee();
|
|
225
243
|
let [injectStream, rscStream] = s1.tee();
|
|
226
244
|
let data;
|
|
@@ -291,8 +309,9 @@ async function loadBundleUncached(bundle, bundleGraph, getInlineBundleContents)
|
|
|
291
309
|
packagingBundles.set(entryBundle, getInlineBundleContents(entryBundle, bundleGraph));
|
|
292
310
|
}
|
|
293
311
|
let packagedBundle = await (0, _nullthrows().default)(packagingBundles.get(entryBundle));
|
|
312
|
+
let inlineType = (0, _nullthrows().default)(entryBundle.getMainEntry()).meta.inlineType;
|
|
294
313
|
let contents = await (0, _utils().blobToString)(packagedBundle.contents);
|
|
295
|
-
contents = `module.exports = ${contents}`;
|
|
314
|
+
contents = `module.exports = ${inlineType === 'string' ? JSON.stringify(contents) : contents}`;
|
|
296
315
|
return [[entryBundle.id, [entryBundle, (0, _nullthrows().default)(entryBundle.getMainEntry()), contents]]];
|
|
297
316
|
});
|
|
298
317
|
} else if ((entryBundle === null || entryBundle === void 0 ? void 0 : entryBundle.type) === 'js') {
|
|
@@ -597,7 +616,7 @@ function runModule(code, filename, id, require, parcelRequire) {
|
|
|
597
616
|
return module.exports;
|
|
598
617
|
}
|
|
599
618
|
function getCacheKey(asset) {
|
|
600
|
-
return asset.filePath + '#' + asset.env.context + (asset.uniqueKey ? '-' + asset.uniqueKey : '');
|
|
619
|
+
return (asset.pipeline || '') + asset.filePath + '#' + asset.env.context + (asset.uniqueKey ? '-' + asset.uniqueKey : '');
|
|
601
620
|
}
|
|
602
621
|
function getSpecifier(dep) {
|
|
603
622
|
if (typeof dep.meta.placeholder === 'string') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/packager-react-static",
|
|
3
|
-
"version": "2.16.
|
|
3
|
+
"version": "2.16.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"source": "src/ReactStaticPackager.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 16.0.0",
|
|
20
|
-
"parcel": "^2.
|
|
20
|
+
"parcel": "^2.16.3"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/node-resolver-core": "3.7.
|
|
24
|
-
"@parcel/plugin": "2.
|
|
25
|
-
"@parcel/rust": "2.16.
|
|
26
|
-
"@parcel/types": "2.
|
|
27
|
-
"@parcel/utils": "2.
|
|
23
|
+
"@parcel/node-resolver-core": "3.7.3",
|
|
24
|
+
"@parcel/plugin": "2.16.3",
|
|
25
|
+
"@parcel/rust": "2.16.3",
|
|
26
|
+
"@parcel/types": "2.16.3",
|
|
27
|
+
"@parcel/utils": "2.16.3",
|
|
28
28
|
"nullthrows": "^1.1.1",
|
|
29
29
|
"rsc-html-stream": "^0.0.6"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "73f691d67d22482440babb2d1846b7da2160f7cc"
|
|
32
32
|
}
|
|
@@ -134,6 +134,7 @@ export default (new Packager({
|
|
|
134
134
|
'react-client',
|
|
135
135
|
);
|
|
136
136
|
let React = loadModule('react', __filename, 'react-client');
|
|
137
|
+
let ReactDOM = loadModule('react-dom', __filename, 'react-server');
|
|
137
138
|
let {createFromReadableStream} = loadModule(
|
|
138
139
|
'react-server-dom-parcel/client.edge',
|
|
139
140
|
__filename,
|
|
@@ -153,33 +154,16 @@ export default (new Packager({
|
|
|
153
154
|
},
|
|
154
155
|
};
|
|
155
156
|
|
|
156
|
-
let resources = [];
|
|
157
157
|
let bootstrapModules = [];
|
|
158
158
|
let entry;
|
|
159
|
-
|
|
159
|
+
let referencedBundles = bundleGraph.getReferencedBundles(bundle, {
|
|
160
160
|
includeInline: false,
|
|
161
161
|
includeIsolated: false,
|
|
162
|
-
})
|
|
163
|
-
if (b.type === 'css') {
|
|
164
|
-
resources.push(
|
|
165
|
-
React.createElement('link', {
|
|
166
|
-
key: b.id,
|
|
167
|
-
rel: 'stylesheet',
|
|
168
|
-
href: urlJoin(b.target.publicUrl, b.name),
|
|
169
|
-
precedence: 'default',
|
|
170
|
-
}),
|
|
171
|
-
);
|
|
172
|
-
} else if (b.type === 'js' && b.env.isBrowser()) {
|
|
173
|
-
bootstrapModules.push(urlJoin(b.target.publicUrl, b.name));
|
|
174
|
-
resources.push(
|
|
175
|
-
React.createElement('script', {
|
|
176
|
-
key: b.id,
|
|
177
|
-
type: 'module',
|
|
178
|
-
async: true,
|
|
179
|
-
src: urlJoin(b.target.publicUrl, b.name),
|
|
180
|
-
}),
|
|
181
|
-
);
|
|
162
|
+
});
|
|
182
163
|
|
|
164
|
+
for (let b of referencedBundles) {
|
|
165
|
+
if (b.type === 'js' && b.env.isBrowser()) {
|
|
166
|
+
bootstrapModules.push(urlJoin(b.target.publicUrl, b.name));
|
|
183
167
|
if (!entry) {
|
|
184
168
|
b.traverseAssets((a, ctx, actions) => {
|
|
185
169
|
if (
|
|
@@ -194,8 +178,40 @@ export default (new Packager({
|
|
|
194
178
|
}
|
|
195
179
|
}
|
|
196
180
|
|
|
181
|
+
function Resources() {
|
|
182
|
+
let resources = [];
|
|
183
|
+
for (let b of referencedBundles) {
|
|
184
|
+
if (b.type === 'css') {
|
|
185
|
+
let href = urlJoin(b.target.publicUrl, b.name);
|
|
186
|
+
|
|
187
|
+
// Add preload hint so we start loading the stylesheet as soon
|
|
188
|
+
// as the RSC payload loads, without waiting for the component to mount.
|
|
189
|
+
ReactDOM.preload(href, {as: 'style'});
|
|
190
|
+
resources.push(
|
|
191
|
+
React.createElement('link', {
|
|
192
|
+
key: b.id,
|
|
193
|
+
rel: 'stylesheet',
|
|
194
|
+
href,
|
|
195
|
+
precedence: 'default',
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
} else if (b.type === 'js' && b.env.isBrowser()) {
|
|
199
|
+
resources.push(
|
|
200
|
+
React.createElement('script', {
|
|
201
|
+
key: b.id,
|
|
202
|
+
type: 'module',
|
|
203
|
+
async: true,
|
|
204
|
+
src: urlJoin(b.target.publicUrl, b.name),
|
|
205
|
+
}),
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return resources;
|
|
211
|
+
}
|
|
212
|
+
|
|
197
213
|
let stream = renderToReadableStream([
|
|
198
|
-
|
|
214
|
+
React.createElement(Resources, {key: 'resources'}),
|
|
199
215
|
React.createElement(Component, props),
|
|
200
216
|
]);
|
|
201
217
|
let [s1, renderStream] = stream.tee();
|
|
@@ -302,8 +318,12 @@ async function loadBundleUncached(
|
|
|
302
318
|
let packagedBundle = await nullthrows(
|
|
303
319
|
packagingBundles.get(entryBundle),
|
|
304
320
|
);
|
|
321
|
+
let inlineType = nullthrows(entryBundle.getMainEntry()).meta
|
|
322
|
+
.inlineType;
|
|
305
323
|
let contents = await blobToString(packagedBundle.contents);
|
|
306
|
-
contents = `module.exports = ${
|
|
324
|
+
contents = `module.exports = ${
|
|
325
|
+
inlineType === 'string' ? JSON.stringify(contents) : contents
|
|
326
|
+
}`;
|
|
307
327
|
return [
|
|
308
328
|
[
|
|
309
329
|
entryBundle.id,
|
|
@@ -667,6 +687,7 @@ function runModule(
|
|
|
667
687
|
|
|
668
688
|
function getCacheKey(asset: Asset) {
|
|
669
689
|
return (
|
|
690
|
+
(asset.pipeline || '') +
|
|
670
691
|
asset.filePath +
|
|
671
692
|
'#' +
|
|
672
693
|
asset.env.context +
|