@rsc-kit/core 0.30.28 → 0.30.29

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/vite.d.ts CHANGED
@@ -421,6 +421,21 @@ export declare function bootsTheApp(file: string): boolean;
421
421
  * that changes what the worker holds is a new worker.
422
422
  */
423
423
  export declare function workerVersion(precache: string[], storedDir: string | null): string;
424
+ /**
425
+ * The PPR contract's build: what an edge checks a cached shell against.
426
+ *
427
+ * Not the client's build id, which is what a browser tab is told and covers
428
+ * only what the browser downloads - a release that changed only what the
429
+ * server renders kept it, and an edge holding the old shell would have joined
430
+ * it to the new server's holes. So it is that id and the bytes of every shell
431
+ * and its postponed state. A server change that reaches a shell is a new
432
+ * build to the edge; one that leaves them all byte for byte the same is not,
433
+ * because the shell the edge holds is then this build's. A tab is not made to
434
+ * reload for either.
435
+ */
436
+ export declare function pprBuildId(clientBuild: string, storedDir: string): string;
437
+ /** Where the host reads the PPR build back, beside the shells it describes. */
438
+ export declare const PPR_BUILD_FILE = "_ppr.build";
424
439
  export declare function smallStylesheetReader(assetsDir: string, setting: "auto" | true | number): (href: string) => string | null;
425
440
  /** A server action the bundle registered: where it is and what it is called. */
426
441
  export interface KnownAction {
package/dist/vite.js CHANGED
@@ -1608,6 +1608,41 @@ export function workerVersion(precache, storedDir) {
1608
1608
  }
1609
1609
  return version.digest("hex").slice(0, 12);
1610
1610
  }
1611
+ /**
1612
+ * The PPR contract's build: what an edge checks a cached shell against.
1613
+ *
1614
+ * Not the client's build id, which is what a browser tab is told and covers
1615
+ * only what the browser downloads - a release that changed only what the
1616
+ * server renders kept it, and an edge holding the old shell would have joined
1617
+ * it to the new server's holes. So it is that id and the bytes of every shell
1618
+ * and its postponed state. A server change that reaches a shell is a new
1619
+ * build to the edge; one that leaves them all byte for byte the same is not,
1620
+ * because the shell the edge holds is then this build's. A tab is not made to
1621
+ * reload for either.
1622
+ */
1623
+ export function pprBuildId(clientBuild, storedDir) {
1624
+ const id = createHash("sha256");
1625
+ id.update(clientBuild);
1626
+ const shells = [];
1627
+ const walk = (dir) => {
1628
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
1629
+ const path = join(dir, entry.name);
1630
+ if (entry.isDirectory())
1631
+ walk(path);
1632
+ else if (/\.(?:ppr\.html|postponed\.json)$/.test(entry.name))
1633
+ shells.push(path);
1634
+ }
1635
+ };
1636
+ if (existsSync(storedDir))
1637
+ walk(storedDir);
1638
+ for (const path of shells.sort()) {
1639
+ id.update("\n" + relative(storedDir, path) + "\n");
1640
+ id.update(readFileSync(path));
1641
+ }
1642
+ return id.digest("hex").slice(0, 16);
1643
+ }
1644
+ /** Where the host reads the PPR build back, beside the shells it describes. */
1645
+ export const PPR_BUILD_FILE = "_ppr.build";
1611
1646
  function writeServiceWorker(clientDir, frozen = [], offlineUrl = null,
1612
1647
  // The pages the build stored, which the worker serves cache-first. Their
1613
1648
  // bytes are part of what a version is - see below.
@@ -8077,7 +8112,12 @@ export function rscKit(options = {}) {
8077
8112
  const staticDir = clientOut
8078
8113
  ? join(dirname(clientOut), "server", NITRO_STATIC_DIR)
8079
8114
  : join(outDir, NITRO_STATIC_DIR);
8080
- const { frozen, results, shells, build } = await prerenderAfterBundles(bundle, staticDir, clientOut ?? publicAssetsDir, builder ? knownActionsOf(builder.config, projectRoot) : []);
8115
+ const { frozen, results, shells, build: clientBuild } = await prerenderAfterBundles(bundle, staticDir, clientOut ?? publicAssetsDir, builder ? knownActionsOf(builder.config, projectRoot) : []);
8116
+ // Before the pages are packed into a module or the assets, so the host
8117
+ // finds it wherever it reads the shells from.
8118
+ const build = clientBuild ? pprBuildId(clientBuild, staticDir) : undefined;
8119
+ if (build && existsSync(staticDir))
8120
+ writeFileSync(join(staticDir, PPR_BUILD_FILE), build);
8081
8121
  // The same pages once more, as a module. A Worker has no filesystem, and
8082
8122
  // until this existed every Cloudflare deploy rendered its "static" pages
8083
8123
  // live, silently - the reader found no directory and fell through. The