@teyik0/furin 0.7.0-alpha.2 → 0.7.0-alpha.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.
@@ -15284,7 +15284,7 @@ var DYNAMIC_SEGMENT_RE = /\/:[^/]+|\/\*/;
15284
15284
  function hasRequestDependentInput(route, root) {
15285
15285
  return [root.route, ...route.routeChain].some((routeConfig) => routeConfig.query !== undefined);
15286
15286
  }
15287
- async function buildRoutePrerenders(routes, root, origin, basePath) {
15287
+ async function buildRoutePrerenders(routes, root, origin, basePath, deferRendering) {
15288
15288
  const prerenders = [];
15289
15289
  const searchRoutes = createSearchRouteMetadata(routes);
15290
15290
  const matchRoute = buildRouteMatcher(routes);
@@ -15309,7 +15309,7 @@ async function buildRoutePrerenders(routes, root, origin, basePath) {
15309
15309
  if (matchRoute(path)?.route !== route) {
15310
15310
  continue;
15311
15311
  }
15312
- if (root.route.requestLoader !== undefined || hasRequestLoader(route)) {
15312
+ if (deferRendering || root.route.requestLoader !== undefined || hasRequestLoader(route)) {
15313
15313
  prerenders.push({ path, route });
15314
15314
  continue;
15315
15315
  }
@@ -15699,7 +15699,7 @@ ${entryChunk}`, cssChunks, routes, root, serverEntry, modulePaths, projectRoot);
15699
15699
  let prerenders = [];
15700
15700
  if (serverEntry) {
15701
15701
  if (targetName === "vercel") {
15702
- prerenders = await buildRoutePrerenders(routes, root, "http://localhost", prefix);
15702
+ prerenders = await buildRoutePrerenders(routes, root, "http://localhost", prefix, true);
15703
15703
  } else {
15704
15704
  ssgCache = await buildSSGCacheSnapshot(routes, root, "http://localhost", prefix);
15705
15705
  }
@@ -16726,26 +16726,26 @@ export { initialization };
16726
16726
  export default { fetch: handle };
16727
16727
  `;
16728
16728
  }
16729
- async function buildPprFallbacks(apps, builds, specs, functionsDir, rootDir, targetDir) {
16729
+ async function buildProductionFallbacks(apps, builds, specs, functionsDir, rootDir, targetDir) {
16730
16730
  const jobs = builds.flatMap((build, index) => build.prerenders.filter((prerender) => prerender.result === undefined).map((prerender) => {
16731
16731
  const path = physicalPath(apps[index].prefix, prerender.path);
16732
- const spec = specs.find((candidate) => candidate.config.chain !== undefined && new RegExp(`^(?:${candidate.source})$`).test(path));
16732
+ const spec = specs.find((candidate) => new RegExp(`^(?:${candidate.source})$`).test(path));
16733
16733
  if (!spec) {
16734
- throw new Error(`[furin] Missing PPR build target for ${path}`);
16734
+ throw new Error(`[furin] Missing prerender build target for ${path}`);
16735
16735
  }
16736
16736
  return { path, prerender, spec };
16737
16737
  }));
16738
16738
  if (jobs.length === 0) {
16739
16739
  return;
16740
16740
  }
16741
- const resultPath = join16(targetDir, "ppr-results.json");
16741
+ const resultPath = join16(targetDir, "prerender-results.json");
16742
16742
  const requests = jobs.map(({ path, spec }) => `http://localhost/${spec.functionName}?${ISR_PATH_PARAM}=${encodeURIComponent(path)}`);
16743
16743
  const script = `
16744
16744
  const handler = (await import(${JSON.stringify(pathToFileURL2(join16(functionsDir, "__server.func/index.js")).href)})).default;
16745
16745
  const results = [];
16746
- for (const url of ${JSON.stringify(requests)}) {
16746
+ for (const [index, url] of ${JSON.stringify(requests)}.entries()) {
16747
16747
  const response = await handler.fetch(new Request(url));
16748
- if (response.status >= 400) throw new Error("PPR build failed for " + url + ": HTTP " + response.status);
16748
+ if (response.status >= 500 || (response.status >= 400 && ${JSON.stringify(jobs.map(({ spec }) => spec.config.chain !== undefined))}[index])) throw new Error("Production prerender failed for " + url + ": HTTP " + response.status);
16749
16749
  results.push({ body: await response.text(), headers: Object.fromEntries(response.headers), status: response.status });
16750
16750
  }
16751
16751
  await Bun.write(${JSON.stringify(resultPath)}, JSON.stringify(results));
@@ -16764,7 +16764,7 @@ process.exit(0);
16764
16764
  new Response(child.stderr).text()
16765
16765
  ]);
16766
16766
  if (exitCode !== 0) {
16767
- throw new Error(`[furin] PPR production prerender failed:
16767
+ throw new Error(`[furin] Production prerender failed:
16768
16768
  ${stderr}
16769
16769
  ${stdout}`);
16770
16770
  }
@@ -16943,7 +16943,7 @@ async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options)
16943
16943
  }
16944
16944
  const serverBundleBytes = serverBuild.outputs.filter((output) => output.path.endsWith(".js")).reduce((total, output) => total + output.size, 0);
16945
16945
  writeFileSync11(join16(serverFunctionDir, "index.js"), vercelBootstrapSource(serverBundleBytes));
16946
- await buildPprFallbacks(apps, builds, prerenderSpecs, functionsDir, rootDir, targetDir);
16946
+ await buildProductionFallbacks(apps, builds, prerenderSpecs, functionsDir, rootDir, targetDir);
16947
16947
  writeFileSync11(join16(serverFunctionDir, ".vc-config.json"), `${JSON.stringify({
16948
16948
  handler: "index.js",
16949
16949
  launcherType: "Nodejs",
@@ -3,7 +3,7 @@ import type { ResolvedRoute, RootLayout } from "../server/router/types.ts";
3
3
  export type SSGCacheSnapshot = Record<string, SsgCacheEntry>;
4
4
  export interface RoutePrerender {
5
5
  path: string;
6
- /** PPR targets are materialized later by the exact production bundle. */
6
+ /** Deferred targets are materialized later by the exact production bundle. */
7
7
  result?: SsgCacheEntry | Response;
8
8
  route: ResolvedRoute;
9
9
  }
@@ -12,6 +12,7 @@ export interface RoutePrerender {
12
12
  * known; dynamic routes contribute the values returned by staticParams(). ISR
13
13
  * routes with query schemas stay on-demand. PPR paths are collected here, then
14
14
  * rendered by the production bundle so React's postponed tree matches at runtime.
15
+ * Vercel defers all rendering to preserve the final application's runtime configuration.
15
16
  */
16
- export declare function buildRoutePrerenders(routes: ResolvedRoute[], root: RootLayout, origin: string, basePath: string): Promise<RoutePrerender[]>;
17
+ export declare function buildRoutePrerenders(routes: ResolvedRoute[], root: RootLayout, origin: string, basePath: string, deferRendering?: boolean): Promise<RoutePrerender[]>;
17
18
  export declare function buildSSGCacheSnapshot(routes: ResolvedRoute[], root: RootLayout, origin: string, basePath?: string): Promise<SSGCacheSnapshot>;
package/dist/cli/index.js CHANGED
@@ -15169,7 +15169,7 @@ var DYNAMIC_SEGMENT_RE = /\/:[^/]+|\/\*/;
15169
15169
  function hasRequestDependentInput(route, root) {
15170
15170
  return [root.route, ...route.routeChain].some((routeConfig) => routeConfig.query !== undefined);
15171
15171
  }
15172
- async function buildRoutePrerenders(routes, root, origin, basePath) {
15172
+ async function buildRoutePrerenders(routes, root, origin, basePath, deferRendering) {
15173
15173
  const prerenders = [];
15174
15174
  const searchRoutes = createSearchRouteMetadata(routes);
15175
15175
  const matchRoute = buildRouteMatcher(routes);
@@ -15194,7 +15194,7 @@ async function buildRoutePrerenders(routes, root, origin, basePath) {
15194
15194
  if (matchRoute(path)?.route !== route) {
15195
15195
  continue;
15196
15196
  }
15197
- if (root.route.requestLoader !== undefined || hasRequestLoader(route)) {
15197
+ if (deferRendering || root.route.requestLoader !== undefined || hasRequestLoader(route)) {
15198
15198
  prerenders.push({ path, route });
15199
15199
  continue;
15200
15200
  }
@@ -15584,7 +15584,7 @@ ${entryChunk}`, cssChunks, routes, root, serverEntry, modulePaths, projectRoot);
15584
15584
  let prerenders = [];
15585
15585
  if (serverEntry) {
15586
15586
  if (targetName === "vercel") {
15587
- prerenders = await buildRoutePrerenders(routes, root, "http://localhost", prefix);
15587
+ prerenders = await buildRoutePrerenders(routes, root, "http://localhost", prefix, true);
15588
15588
  } else {
15589
15589
  ssgCache = await buildSSGCacheSnapshot(routes, root, "http://localhost", prefix);
15590
15590
  }
@@ -16611,26 +16611,26 @@ export { initialization };
16611
16611
  export default { fetch: handle };
16612
16612
  `;
16613
16613
  }
16614
- async function buildPprFallbacks(apps, builds, specs, functionsDir, rootDir, targetDir) {
16614
+ async function buildProductionFallbacks(apps, builds, specs, functionsDir, rootDir, targetDir) {
16615
16615
  const jobs = builds.flatMap((build, index) => build.prerenders.filter((prerender) => prerender.result === undefined).map((prerender) => {
16616
16616
  const path = physicalPath(apps[index].prefix, prerender.path);
16617
- const spec = specs.find((candidate) => candidate.config.chain !== undefined && new RegExp(`^(?:${candidate.source})$`).test(path));
16617
+ const spec = specs.find((candidate) => new RegExp(`^(?:${candidate.source})$`).test(path));
16618
16618
  if (!spec) {
16619
- throw new Error(`[furin] Missing PPR build target for ${path}`);
16619
+ throw new Error(`[furin] Missing prerender build target for ${path}`);
16620
16620
  }
16621
16621
  return { path, prerender, spec };
16622
16622
  }));
16623
16623
  if (jobs.length === 0) {
16624
16624
  return;
16625
16625
  }
16626
- const resultPath = join14(targetDir, "ppr-results.json");
16626
+ const resultPath = join14(targetDir, "prerender-results.json");
16627
16627
  const requests = jobs.map(({ path, spec }) => `http://localhost/${spec.functionName}?${ISR_PATH_PARAM}=${encodeURIComponent(path)}`);
16628
16628
  const script = `
16629
16629
  const handler = (await import(${JSON.stringify(pathToFileURL2(join14(functionsDir, "__server.func/index.js")).href)})).default;
16630
16630
  const results = [];
16631
- for (const url of ${JSON.stringify(requests)}) {
16631
+ for (const [index, url] of ${JSON.stringify(requests)}.entries()) {
16632
16632
  const response = await handler.fetch(new Request(url));
16633
- if (response.status >= 400) throw new Error("PPR build failed for " + url + ": HTTP " + response.status);
16633
+ if (response.status >= 500 || (response.status >= 400 && ${JSON.stringify(jobs.map(({ spec }) => spec.config.chain !== undefined))}[index])) throw new Error("Production prerender failed for " + url + ": HTTP " + response.status);
16634
16634
  results.push({ body: await response.text(), headers: Object.fromEntries(response.headers), status: response.status });
16635
16635
  }
16636
16636
  await Bun.write(${JSON.stringify(resultPath)}, JSON.stringify(results));
@@ -16649,7 +16649,7 @@ process.exit(0);
16649
16649
  new Response(child.stderr).text()
16650
16650
  ]);
16651
16651
  if (exitCode !== 0) {
16652
- throw new Error(`[furin] PPR production prerender failed:
16652
+ throw new Error(`[furin] Production prerender failed:
16653
16653
  ${stderr}
16654
16654
  ${stdout}`);
16655
16655
  }
@@ -16828,7 +16828,7 @@ async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options)
16828
16828
  }
16829
16829
  const serverBundleBytes = serverBuild.outputs.filter((output) => output.path.endsWith(".js")).reduce((total, output) => total + output.size, 0);
16830
16830
  writeFileSync9(join14(serverFunctionDir, "index.js"), vercelBootstrapSource(serverBundleBytes));
16831
- await buildPprFallbacks(apps, builds, prerenderSpecs, functionsDir, rootDir, targetDir);
16831
+ await buildProductionFallbacks(apps, builds, prerenderSpecs, functionsDir, rootDir, targetDir);
16832
16832
  writeFileSync9(join14(serverFunctionDir, ".vc-config.json"), `${JSON.stringify({
16833
16833
  handler: "index.js",
16834
16834
  launcherType: "Nodejs",
package/dist/furin.js CHANGED
@@ -21491,7 +21491,7 @@ function installMutationHandlers(app) {
21491
21491
  table.inheritedChain[index],
21492
21492
  table.macroScope?.get(index)
21493
21493
  ] : app["~routes"][index]);
21494
- if (!nativeRoute || ["GET", "HEAD", "OPTIONS", "WS"].includes(nativeRoute[0])) {
21494
+ if (!nativeRoute || ["GET", "HEAD", "OPTIONS", "WS"].includes(nativeRoute[0]) || typeof nativeRoute[2] === "function" && "~mount" in nativeRoute[2]) {
21495
21495
  return compileHandler(index, immediate, route, aliases, table);
21496
21496
  }
21497
21497
  const [method, path, handle, owner, hooks, chain, inherited, macroScope] = nativeRoute;
@@ -3801,7 +3801,7 @@ function installMutationHandlers(app) {
3801
3801
  table.inheritedChain[index],
3802
3802
  table.macroScope?.get(index)
3803
3803
  ] : app["~routes"][index]);
3804
- if (!nativeRoute || ["GET", "HEAD", "OPTIONS", "WS"].includes(nativeRoute[0])) {
3804
+ if (!nativeRoute || ["GET", "HEAD", "OPTIONS", "WS"].includes(nativeRoute[0]) || typeof nativeRoute[2] === "function" && "~mount" in nativeRoute[2]) {
3805
3805
  return compileHandler(index, immediate, route, aliases, table);
3806
3806
  }
3807
3807
  const [method, path, handle, owner, hooks, chain, inherited, macroScope] = nativeRoute;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teyik0/furin",
3
- "version": "0.7.0-alpha.2",
3
+ "version": "0.7.0-alpha.3",
4
4
  "description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
5
5
  "keywords": [
6
6
  "react",
@@ -391,7 +391,7 @@ export async function buildRuntimeApp(
391
391
  let prerenders: RoutePrerender[] = [];
392
392
  if (serverEntry) {
393
393
  if (targetName === "vercel") {
394
- prerenders = await buildRoutePrerenders(routes, root, "http://localhost", prefix);
394
+ prerenders = await buildRoutePrerenders(routes, root, "http://localhost", prefix, true);
395
395
  } else {
396
396
  ssgCache = await buildSSGCacheSnapshot(routes, root, "http://localhost", prefix);
397
397
  }
@@ -538,7 +538,7 @@ export default { fetch: handle };
538
538
  `;
539
539
  }
540
540
 
541
- async function buildPprFallbacks(
541
+ async function buildProductionFallbacks(
542
542
  apps: RuntimeTargetApp[],
543
543
  builds: RuntimeAppBuild[],
544
544
  specs: PrerenderSpec[],
@@ -551,13 +551,9 @@ async function buildPprFallbacks(
551
551
  .filter((prerender) => prerender.result === undefined)
552
552
  .map((prerender) => {
553
553
  const path = physicalPath((apps[index] as RuntimeTargetApp).prefix, prerender.path);
554
- const spec = specs.find(
555
- (candidate) =>
556
- candidate.config.chain !== undefined &&
557
- new RegExp(`^(?:${candidate.source})$`).test(path)
558
- );
554
+ const spec = specs.find((candidate) => new RegExp(`^(?:${candidate.source})$`).test(path));
559
555
  if (!spec) {
560
- throw new Error(`[furin] Missing PPR build target for ${path}`);
556
+ throw new Error(`[furin] Missing prerender build target for ${path}`);
561
557
  }
562
558
  return { path, prerender, spec };
563
559
  })
@@ -565,7 +561,7 @@ async function buildPprFallbacks(
565
561
  if (jobs.length === 0) {
566
562
  return;
567
563
  }
568
- const resultPath = join(targetDir, "ppr-results.json");
564
+ const resultPath = join(targetDir, "prerender-results.json");
569
565
  const requests = jobs.map(
570
566
  ({ path, spec }) =>
571
567
  `http://localhost/${spec.functionName}?${ISR_PATH_PARAM}=${encodeURIComponent(path)}`
@@ -573,9 +569,9 @@ async function buildPprFallbacks(
573
569
  const script = `
574
570
  const handler = (await import(${JSON.stringify(pathToFileURL(join(functionsDir, "__server.func/index.js")).href)})).default;
575
571
  const results = [];
576
- for (const url of ${JSON.stringify(requests)}) {
572
+ for (const [index, url] of ${JSON.stringify(requests)}.entries()) {
577
573
  const response = await handler.fetch(new Request(url));
578
- if (response.status >= 400) throw new Error("PPR build failed for " + url + ": HTTP " + response.status);
574
+ if (response.status >= 500 || (response.status >= 400 && ${JSON.stringify(jobs.map(({ spec }) => spec.config.chain !== undefined))}[index])) throw new Error("Production prerender failed for " + url + ": HTTP " + response.status);
579
575
  results.push({ body: await response.text(), headers: Object.fromEntries(response.headers), status: response.status });
580
576
  }
581
577
  await Bun.write(${JSON.stringify(resultPath)}, JSON.stringify(results));
@@ -594,7 +590,7 @@ process.exit(0);
594
590
  new Response(child.stderr).text(),
595
591
  ]);
596
592
  if (exitCode !== 0) {
597
- throw new Error(`[furin] PPR production prerender failed:\n${stderr}\n${stdout}`);
593
+ throw new Error(`[furin] Production prerender failed:\n${stderr}\n${stdout}`);
598
594
  }
599
595
  const results = JSON.parse(readFileSync(resultPath, "utf8")) as {
600
596
  body: string;
@@ -812,7 +808,7 @@ export async function buildVercelTarget(
812
808
  .filter((output) => output.path.endsWith(".js"))
813
809
  .reduce((total, output) => total + output.size, 0);
814
810
  writeFileSync(join(serverFunctionDir, "index.js"), vercelBootstrapSource(serverBundleBytes));
815
- await buildPprFallbacks(apps, builds, prerenderSpecs, functionsDir, rootDir, targetDir);
811
+ await buildProductionFallbacks(apps, builds, prerenderSpecs, functionsDir, rootDir, targetDir);
816
812
 
817
813
  writeFileSync(
818
814
  join(serverFunctionDir, ".vc-config.json"),
@@ -12,7 +12,7 @@ export type SSGCacheSnapshot = Record<string, SsgCacheEntry>;
12
12
 
13
13
  export interface RoutePrerender {
14
14
  path: string;
15
- /** PPR targets are materialized later by the exact production bundle. */
15
+ /** Deferred targets are materialized later by the exact production bundle. */
16
16
  result?: SsgCacheEntry | Response;
17
17
  route: ResolvedRoute;
18
18
  }
@@ -31,12 +31,14 @@ function hasRequestDependentInput(route: ResolvedRoute, root: RootLayout): boole
31
31
  * known; dynamic routes contribute the values returned by staticParams(). ISR
32
32
  * routes with query schemas stay on-demand. PPR paths are collected here, then
33
33
  * rendered by the production bundle so React's postponed tree matches at runtime.
34
+ * Vercel defers all rendering to preserve the final application's runtime configuration.
34
35
  */
35
36
  export async function buildRoutePrerenders(
36
37
  routes: ResolvedRoute[],
37
38
  root: RootLayout,
38
39
  origin: string,
39
- basePath: string
40
+ basePath: string,
41
+ deferRendering?: boolean
40
42
  ): Promise<RoutePrerender[]> {
41
43
  const prerenders: RoutePrerender[] = [];
42
44
  const searchRoutes = createSearchRouteMetadata(routes);
@@ -65,7 +67,7 @@ export async function buildRoutePrerenders(
65
67
  if (matchRoute(path)?.route !== route) {
66
68
  continue;
67
69
  }
68
- if (root.route.requestLoader !== undefined || hasRequestLoader(route)) {
70
+ if (deferRendering || root.route.requestLoader !== undefined || hasRequestLoader(route)) {
69
71
  prerenders.push({ path, route });
70
72
  continue;
71
73
  }
@@ -45,7 +45,12 @@ export function installMutationHandlers(app: Elysia): void {
45
45
  table.macroScope?.get(index),
46
46
  ] as NonNullable<typeof route>)
47
47
  : app["~routes"][index]);
48
- if (!nativeRoute || ["GET", "HEAD", "OPTIONS", "WS"].includes(nativeRoute[0])) {
48
+ if (
49
+ !nativeRoute ||
50
+ ["GET", "HEAD", "OPTIONS", "WS"].includes(nativeRoute[0]) ||
51
+ // Elysia resolves mount placeholders and rewrites their Request paths during compilation.
52
+ (typeof nativeRoute[2] === "function" && "~mount" in nativeRoute[2])
53
+ ) {
49
54
  return compileHandler(index, immediate, route, aliases, table);
50
55
  }
51
56
  const [method, path, handle, owner, hooks, chain, inherited, macroScope] = nativeRoute;