@vistagenic/vista 0.3.3 → 0.3.4

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.
Files changed (35) hide show
  1. package/dist/bin/build-rsc.js +18 -0
  2. package/dist/bin/build.js +10 -0
  3. package/dist/bin/webpack.config.d.ts +3 -1
  4. package/dist/bin/webpack.config.js +3 -1
  5. package/dist/build/rsc/compiler.d.ts +3 -1
  6. package/dist/build/rsc/compiler.js +7 -3
  7. package/dist/build/rsc/react-client-reference-manifest.d.ts +7 -0
  8. package/dist/build/rsc/react-client-reference-manifest.js +132 -6
  9. package/dist/client/link.js +1 -1
  10. package/dist/client/navigation.js +2 -2
  11. package/dist/client/rsc-router.d.ts +1 -3
  12. package/dist/client/rsc-router.js +98 -45
  13. package/dist/deploy/adapters/cloudflare.js +2 -25
  14. package/dist/deploy/adapters/netlify.js +2 -14
  15. package/dist/deploy/utils.d.ts +6 -0
  16. package/dist/deploy/utils.js +64 -1
  17. package/dist/image/get-img-props.js +21 -11
  18. package/dist/image/image-config.d.ts +2 -0
  19. package/dist/image/image-config.js +17 -0
  20. package/dist/image/index.d.ts +18 -3
  21. package/dist/image/index.js +1 -1
  22. package/dist/image/react-server.d.ts +1 -2
  23. package/dist/image/react-server.js +1 -1
  24. package/dist/server/app-router-runtime.d.ts +1 -0
  25. package/dist/server/app-router-runtime.js +34 -9
  26. package/dist/server/hydration-chunks.d.ts +7 -0
  27. package/dist/server/hydration-chunks.js +49 -0
  28. package/dist/server/module-compile-hook.js +11 -0
  29. package/dist/server/rsc-engine.js +14 -61
  30. package/dist/server/rsc-upstream.js +10 -3
  31. package/dist/server/ssr-webpack-shim.d.ts +6 -0
  32. package/dist/server/ssr-webpack-shim.js +29 -0
  33. package/dist/server/static-generator.d.ts +2 -0
  34. package/dist/server/static-generator.js +29 -29
  35. 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,30 @@ 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
+ if (page.shellHtml) {
435
+ page.shellHtml = injectInlineFlightBootstrap(page.shellHtml, flightData);
436
+ }
437
+ }
412
438
  function getCSSLinks(cwd) {
413
439
  const links = ['<link rel="stylesheet" href="/styles.css" />'];
414
440
  const chunksDir = path_1.default.join(cwd, constants_1.BUILD_DIR, 'static', 'chunks');
@@ -426,32 +452,12 @@ function getCSSLinks(cwd) {
426
452
  return links.join('\n ');
427
453
  }
428
454
  function getChunkScripts(cwd) {
429
- const chunksDir = path_1.default.join(cwd, constants_1.BUILD_DIR, 'static', 'chunks');
430
455
  try {
431
- if (!fs_1.default.existsSync(chunksDir)) {
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
456
+ return (0, hydration_chunks_1.listHydrationChunkFiles)(cwd, false)
450
457
  .map((file) => `<script defer src="${constants_1.STATIC_CHUNKS_PATH}${file}"></script>`)
451
458
  .join('\n ');
452
459
  }
453
460
  catch {
454
- // Ignore chunk discovery failures during static generation.
455
461
  return '';
456
462
  }
457
463
  }
@@ -660,10 +666,7 @@ async function generateStaticPages(options) {
660
666
  const page = await prerenderPage(urlPath, route, undefined, cwd, vistaDirRoot, appPprEnabled);
661
667
  if (page) {
662
668
  if (flightUpstream) {
663
- const flightData = await flightUpstream.fetchFlight(urlPath);
664
- if (flightData) {
665
- page.flightData = flightData;
666
- }
669
+ await attachFlightPayload(page, await flightUpstream.fetchFlight(urlPath), cwd);
667
670
  }
668
671
  (0, static_cache_1.setCachedPage)(urlPath, page);
669
672
  (0, static_cache_1.writeStaticPageToDisk)(vistaDirRoot, urlPath, page);
@@ -686,10 +689,7 @@ async function generateStaticPages(options) {
686
689
  const page = await prerenderPage(urlPath, route, params, cwd, vistaDirRoot, appPprEnabled);
687
690
  if (page) {
688
691
  if (flightUpstream) {
689
- const flightData = await flightUpstream.fetchFlight(urlPath);
690
- if (flightData) {
691
- page.flightData = flightData;
692
- }
692
+ await attachFlightPayload(page, await flightUpstream.fetchFlight(urlPath), cwd);
693
693
  }
694
694
  (0, static_cache_1.setCachedPage)(urlPath, page);
695
695
  (0, static_cache_1.writeStaticPageToDisk)(vistaDirRoot, urlPath, page);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vistagenic/vista",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "The React Framework for Visionaries - Rust-powered SSR with Server Components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",