@vistagenic/vista 0.3.3 → 0.3.5
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/bin/build-rsc.js +18 -0
- package/dist/bin/build.js +10 -0
- package/dist/bin/webpack.config.d.ts +3 -1
- package/dist/bin/webpack.config.js +3 -1
- package/dist/build/rsc/compiler.d.ts +3 -1
- package/dist/build/rsc/compiler.js +7 -3
- package/dist/build/rsc/react-client-reference-manifest.d.ts +7 -0
- package/dist/build/rsc/react-client-reference-manifest.js +132 -6
- package/dist/client/link.js +1 -1
- package/dist/client/navigation.js +2 -2
- package/dist/client/rsc-router.d.ts +1 -3
- package/dist/client/rsc-router.js +98 -45
- package/dist/deploy/adapters/cloudflare.js +2 -25
- package/dist/deploy/adapters/netlify.js +2 -14
- package/dist/deploy/utils.d.ts +6 -0
- package/dist/deploy/utils.js +64 -1
- package/dist/image/get-img-props.js +21 -11
- package/dist/image/image-config.d.ts +2 -0
- package/dist/image/image-config.js +17 -0
- package/dist/image/index.d.ts +18 -3
- package/dist/image/index.js +1 -1
- package/dist/image/react-server.d.ts +1 -2
- package/dist/image/react-server.js +1 -1
- package/dist/server/app-router-runtime.d.ts +1 -0
- package/dist/server/app-router-runtime.js +34 -9
- package/dist/server/hydration-chunks.d.ts +7 -0
- package/dist/server/hydration-chunks.js +49 -0
- package/dist/server/module-compile-hook.js +11 -0
- package/dist/server/rsc-engine.js +14 -61
- package/dist/server/rsc-upstream.js +10 -3
- package/dist/server/ssr-webpack-shim.d.ts +6 -0
- package/dist/server/ssr-webpack-shim.js +29 -0
- package/dist/server/static-generator.d.ts +2 -0
- package/dist/server/static-generator.js +28 -29
- package/package.json +1 -1
|
@@ -12,12 +12,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.injectInlineFlightBootstrap = injectInlineFlightBootstrap;
|
|
15
16
|
exports.generateStaticPages = generateStaticPages;
|
|
16
17
|
exports.revalidatePath = revalidatePath;
|
|
17
18
|
const path_1 = __importDefault(require("path"));
|
|
18
19
|
const fs_1 = __importDefault(require("fs"));
|
|
19
20
|
const child_process_1 = require("child_process");
|
|
20
21
|
const constants_1 = require("../constants");
|
|
22
|
+
const hydration_chunks_1 = require("./hydration-chunks");
|
|
21
23
|
const static_cache_1 = require("./static-cache");
|
|
22
24
|
const module_compile_hook_1 = require("./module-compile-hook");
|
|
23
25
|
const request_context_1 = require("./request-context");
|
|
@@ -409,6 +411,29 @@ function injectBeforeClosingTag(html, tagName, injection) {
|
|
|
409
411
|
}
|
|
410
412
|
return html;
|
|
411
413
|
}
|
|
414
|
+
function buildInlineFlightBootstrapScript(flightText) {
|
|
415
|
+
return `<script>window.${constants_1.RSC_DATA_FLAG}=${JSON.stringify(flightText)};</script>`;
|
|
416
|
+
}
|
|
417
|
+
/** Embed Flight on SSG HTML so the client can hydrate without a live /rsc server. */
|
|
418
|
+
function injectInlineFlightBootstrap(html, flightText) {
|
|
419
|
+
if (!flightText || html.includes(`window.${constants_1.RSC_DATA_FLAG}=`)) {
|
|
420
|
+
return html;
|
|
421
|
+
}
|
|
422
|
+
const script = ` ${buildInlineFlightBootstrapScript(flightText)}\n`;
|
|
423
|
+
const deferIdx = html.search(/<script\s+defer\b/i);
|
|
424
|
+
if (deferIdx !== -1) {
|
|
425
|
+
return `${html.slice(0, deferIdx)}${script}${html.slice(deferIdx)}`;
|
|
426
|
+
}
|
|
427
|
+
return injectBeforeClosingTag(html, 'body', `\n${script}`);
|
|
428
|
+
}
|
|
429
|
+
async function attachFlightPayload(page, flightData, _cwd) {
|
|
430
|
+
if (!flightData)
|
|
431
|
+
return;
|
|
432
|
+
page.flightData = flightData;
|
|
433
|
+
page.html = injectInlineFlightBootstrap(page.html, flightData);
|
|
434
|
+
// PPR shells are loading-only. Inlining the full-page Flight would leak
|
|
435
|
+
// resumed content (e.g. ppr-page-content) into the shell response.
|
|
436
|
+
}
|
|
412
437
|
function getCSSLinks(cwd) {
|
|
413
438
|
const links = ['<link rel="stylesheet" href="/styles.css" />'];
|
|
414
439
|
const chunksDir = path_1.default.join(cwd, constants_1.BUILD_DIR, 'static', 'chunks');
|
|
@@ -426,32 +451,12 @@ function getCSSLinks(cwd) {
|
|
|
426
451
|
return links.join('\n ');
|
|
427
452
|
}
|
|
428
453
|
function getChunkScripts(cwd) {
|
|
429
|
-
const chunksDir = path_1.default.join(cwd, constants_1.BUILD_DIR, 'static', 'chunks');
|
|
430
454
|
try {
|
|
431
|
-
|
|
432
|
-
return '';
|
|
433
|
-
}
|
|
434
|
-
const files = fs_1.default
|
|
435
|
-
.readdirSync(chunksDir)
|
|
436
|
-
.filter((entry) => entry.endsWith('.js') && !entry.endsWith('.map') && !entry.includes('.hot-update.'));
|
|
437
|
-
const priority = ['webpack.js', 'framework.js', 'vendor.js'];
|
|
438
|
-
files.sort((a, b) => {
|
|
439
|
-
const ai = priority.indexOf(a);
|
|
440
|
-
const bi = priority.indexOf(b);
|
|
441
|
-
if (ai !== -1 && bi !== -1)
|
|
442
|
-
return ai - bi;
|
|
443
|
-
if (ai !== -1)
|
|
444
|
-
return -1;
|
|
445
|
-
if (bi !== -1)
|
|
446
|
-
return 1;
|
|
447
|
-
return a.localeCompare(b);
|
|
448
|
-
});
|
|
449
|
-
return files
|
|
455
|
+
return (0, hydration_chunks_1.listHydrationChunkFiles)(cwd, false)
|
|
450
456
|
.map((file) => `<script defer src="${constants_1.STATIC_CHUNKS_PATH}${file}"></script>`)
|
|
451
457
|
.join('\n ');
|
|
452
458
|
}
|
|
453
459
|
catch {
|
|
454
|
-
// Ignore chunk discovery failures during static generation.
|
|
455
460
|
return '';
|
|
456
461
|
}
|
|
457
462
|
}
|
|
@@ -660,10 +665,7 @@ async function generateStaticPages(options) {
|
|
|
660
665
|
const page = await prerenderPage(urlPath, route, undefined, cwd, vistaDirRoot, appPprEnabled);
|
|
661
666
|
if (page) {
|
|
662
667
|
if (flightUpstream) {
|
|
663
|
-
|
|
664
|
-
if (flightData) {
|
|
665
|
-
page.flightData = flightData;
|
|
666
|
-
}
|
|
668
|
+
await attachFlightPayload(page, await flightUpstream.fetchFlight(urlPath), cwd);
|
|
667
669
|
}
|
|
668
670
|
(0, static_cache_1.setCachedPage)(urlPath, page);
|
|
669
671
|
(0, static_cache_1.writeStaticPageToDisk)(vistaDirRoot, urlPath, page);
|
|
@@ -686,10 +688,7 @@ async function generateStaticPages(options) {
|
|
|
686
688
|
const page = await prerenderPage(urlPath, route, params, cwd, vistaDirRoot, appPprEnabled);
|
|
687
689
|
if (page) {
|
|
688
690
|
if (flightUpstream) {
|
|
689
|
-
|
|
690
|
-
if (flightData) {
|
|
691
|
-
page.flightData = flightData;
|
|
692
|
-
}
|
|
691
|
+
await attachFlightPayload(page, await flightUpstream.fetchFlight(urlPath), cwd);
|
|
693
692
|
}
|
|
694
693
|
(0, static_cache_1.setCachedPage)(urlPath, page);
|
|
695
694
|
(0, static_cache_1.writeStaticPageToDisk)(vistaDirRoot, urlPath, page);
|