@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/host.js CHANGED
@@ -433,6 +433,8 @@ export function createRscHandler(options) {
433
433
  // own. Resolved on the first request: the engine reads it from a build
434
434
  // product it only has at runtime.
435
435
  let version = engine.buildId ? undefined : options.version;
436
+ // The PPR contract's build, read once - see pprBuild.
437
+ let pprBuildRead = null;
436
438
  const maxActionBody = options.maxActionBody ?? DEFAULT_MAX_ACTION_BODY;
437
439
  const compress = options.compress ?? true;
438
440
  // Annotated rather than inferred: the narrowing below is lost inside the
@@ -1255,14 +1257,14 @@ export function createRscHandler(options) {
1255
1257
  "Content-Type": HTML_TYPE,
1256
1258
  // Rendered for whoever asked. Never cacheable.
1257
1259
  "Cache-Control": PER_CLIENT,
1258
- ...(version ? { [PPR.build]: version } : {}),
1260
+ ...(pprBuildRead ? { [PPR.build]: pprBuildRead } : {}),
1259
1261
  }),
1260
1262
  });
1261
1263
  });
1262
1264
  }
1263
1265
  /**
1264
1266
  * The PPR contract's two endpoints, for a platform's edge. They exist only
1265
- * for a caller holding the release's PPR_TOKEN: unset, missing or wrong,
1267
+ * for a caller holding the PPR_TOKEN the platform set: unset, missing or wrong,
1266
1268
  * everything under /_ppr/ is a 404, as if there were nothing here - so an
1267
1269
  * app is safe wherever it runs, and only the platform can ask.
1268
1270
  *
@@ -1289,7 +1291,10 @@ export function createRscHandler(options) {
1289
1291
  async function pprContractAnswer(request, url) {
1290
1292
  const missing = new Response("Not found", { status: 404 });
1291
1293
  const read = options.prerendered;
1292
- if (!read || !version || !holdsSecret(request, PPR.token, PPR.tokenEnv))
1294
+ if (!read || !holdsSecret(request, PPR.token, PPR.tokenEnv))
1295
+ return missing;
1296
+ const build = await pprBuild(read);
1297
+ if (!build)
1293
1298
  return missing;
1294
1299
  if (url.pathname === PPR.shellPath && (request.method === "GET" || request.method === "HEAD")) {
1295
1300
  const pathname = contractPathname(url.searchParams.get("path"), url);
@@ -1298,14 +1303,14 @@ export function createRscHandler(options) {
1298
1303
  const shell = await shellAt(pathname, read);
1299
1304
  if (shell instanceof Response)
1300
1305
  return shell;
1301
- return new Response(request.method === "HEAD" ? null : JSON.stringify({ v: 1, build: version, html: shell, state: "" }), {
1306
+ return new Response(request.method === "HEAD" ? null : JSON.stringify({ v: 1, build, html: shell, state: "" }), {
1302
1307
  headers: {
1303
1308
  "Content-Type": "application/json",
1304
1309
  // Fixed for the build, so no ETag. And never stored on the way:
1305
1310
  // it was answered only for the token, and a cache between the
1306
1311
  // edge and here would hand it to callers without one.
1307
1312
  "Cache-Control": "private, no-store",
1308
- [PPR.build]: version,
1313
+ [PPR.build]: build,
1309
1314
  },
1310
1315
  });
1311
1316
  }
@@ -1319,6 +1324,15 @@ export function createRscHandler(options) {
1319
1324
  }
1320
1325
  return missing;
1321
1326
  }
1327
+ /**
1328
+ * The build the marker names, which the build wrote beside the shells - not
1329
+ * the client's id this host sends a browser, which a server-only change
1330
+ * keeps. See pprBuildId.
1331
+ */
1332
+ async function pprBuild(read) {
1333
+ pprBuildRead ??= (await read("_ppr.build"))?.trim() || null;
1334
+ return pprBuildRead;
1335
+ }
1322
1336
  /**
1323
1337
  * A contract path - absolute and decoded once - as the pathname this host
1324
1338
  * matches, or null for one that would not survive the trip unchanged: a