@teyik0/furin 0.9.0-alpha.4 → 0.9.0-alpha.6

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 (63) hide show
  1. package/dist/adapter/runtime-build.d.ts +1 -0
  2. package/dist/adapter/vercel.js +9 -6
  3. package/dist/build/index.js +74 -31
  4. package/dist/build/route-metadata.d.ts +1 -1
  5. package/dist/cli/index.js +74 -31
  6. package/dist/client/chunks/{client-rdxyrw11.js → client-hjqd5m3b.js} +1 -1
  7. package/dist/client/chunks/{client-p0jqzfvc.js → client-whph3y67.js} +1 -1
  8. package/dist/client/chunks/{client-a7spxfnn.js → client-xf7r768c.js} +13 -1
  9. package/dist/client/define-route.d.ts +12 -0
  10. package/dist/client/internal/runtime-types.d.ts +7 -0
  11. package/dist/client/link.js +200 -40
  12. package/dist/client/route-element.d.ts +5 -0
  13. package/dist/client/router/history.d.ts +6 -0
  14. package/dist/client/router/link-utils.d.ts +7 -0
  15. package/dist/client/router/navigation-controller.d.ts +20 -2
  16. package/dist/client/router/pending.d.ts +17 -0
  17. package/dist/client/router/search/index.d.ts +2 -0
  18. package/dist/client/router/search/index.js +7 -3
  19. package/dist/client/router/types.d.ts +21 -1
  20. package/dist/client.js +19 -4
  21. package/dist/define-route.d.ts +37 -10
  22. package/dist/furin.js +88 -29
  23. package/dist/plugin/client-plugin.d.ts +1 -1
  24. package/dist/plugin/index.js +36 -17
  25. package/dist/plugin/route-manifest.d.ts +2 -1
  26. package/dist/plugin/strip-server-stages.d.ts +1 -1
  27. package/dist/server/internal.d.ts +1 -0
  28. package/dist/server/internal.js +42 -15
  29. package/dist/server/router/defined-route.d.ts +3 -0
  30. package/dist/server/router/types.d.ts +7 -1
  31. package/dist/server/static-export.js +45 -15
  32. package/dist/shared/pending.d.ts +13 -0
  33. package/dist/shared/search-params.d.ts +1 -0
  34. package/package.json +1 -1
  35. package/src/adapter/runtime-build.ts +4 -0
  36. package/src/adapter/vercel.ts +21 -8
  37. package/src/build/hydrate.ts +11 -2
  38. package/src/build/preload-manifest.ts +3 -1
  39. package/src/build/route-metadata.ts +3 -2
  40. package/src/client/define-route.ts +23 -3
  41. package/src/client/internal/runtime-types.ts +7 -0
  42. package/src/client/link.tsx +26 -4
  43. package/src/client/route-element.tsx +41 -15
  44. package/src/client/router/context.ts +29 -8
  45. package/src/client/router/history.ts +10 -0
  46. package/src/client/router/link-utils.ts +23 -0
  47. package/src/client/router/navigation-controller.ts +239 -19
  48. package/src/client/router/pending.ts +58 -0
  49. package/src/client/router/provider.tsx +5 -2
  50. package/src/client/router/search/index.ts +7 -2
  51. package/src/client/router/types.ts +29 -3
  52. package/src/define-route.ts +74 -26
  53. package/src/plugin/client-plugin.ts +5 -4
  54. package/src/plugin/route-config.ts +9 -2
  55. package/src/plugin/route-manifest.ts +11 -3
  56. package/src/plugin/route-tree.ts +2 -2
  57. package/src/plugin/strip-server-stages.ts +60 -35
  58. package/src/server/internal.ts +1 -0
  59. package/src/server/router/defined-route.ts +6 -0
  60. package/src/server/router/discovery.ts +5 -2
  61. package/src/server/router/types.ts +7 -1
  62. package/src/shared/pending.ts +16 -0
  63. package/src/shared/search-params.ts +1 -1
@@ -33,6 +33,7 @@ export declare function buildCompileMetadata(root: BuildRoot | RootLayout, route
33
33
  errorPath?: string;
34
34
  fromRoute?: true;
35
35
  notFoundPath?: string;
36
+ pendingPath?: string;
36
37
  }>;
37
38
  }>;
38
39
  };
@@ -267,6 +267,9 @@ function expirationFor(route) {
267
267
  function prerenderAllowQuery(route) {
268
268
  return route.queryKeys === null ? undefined : [ISR_PATH_PARAM, ...route.queryKeys];
269
269
  }
270
+ function pprChain(route, functionName, pprResumeKey) {
271
+ return route.ppr ? { headers: { "x-furin-ppr-resume": pprResumeKey }, outputPath: functionName } : undefined;
272
+ }
270
273
  function createPrerenderSpecs(apps, pprResumeKey) {
271
274
  const specs = new Map;
272
275
  const names = new Map;
@@ -278,17 +281,16 @@ function createPrerenderSpecs(apps, pprResumeKey) {
278
281
  }
279
282
  const physicalPattern = physicalPath(app.prefix, route.pattern);
280
283
  const source = routePatternSource(app.prefix, route.pattern);
284
+ const functionName = functionNameForPath(physicalPattern, route.mode, names);
281
285
  specs.set(source, {
282
286
  config: {
283
287
  allowQuery: prerenderAllowQuery(route),
284
288
  expiration: expirationFor(route),
285
289
  passQuery: true,
286
- ...route.ppr ? {
287
- chain: { headers: { "x-furin-ppr-resume": pprResumeKey }, outputPath: "__server" }
288
- } : {}
290
+ chain: pprChain(route, functionName, pprResumeKey)
289
291
  },
290
292
  exact: !DYNAMIC_SEGMENT_RE.test(route.pattern),
291
- functionName: functionNameForPath(physicalPattern, route.mode, names),
293
+ functionName,
292
294
  pattern: physicalPattern,
293
295
  source
294
296
  });
@@ -303,15 +305,16 @@ function createPrerenderSpecs(apps, pprResumeKey) {
303
305
  const path = physicalPath(app.prefix, prerender.path);
304
306
  let spec = specs.get(routePatternSource(app.prefix, route.pattern));
305
307
  if (DYNAMIC_SEGMENT_RE.test(route.pattern)) {
308
+ const functionName = functionNameForPath(path, route.mode, names);
306
309
  spec = {
307
310
  config: {
308
311
  allowQuery: spec.config.allowQuery,
309
- chain: spec.config.chain,
312
+ chain: pprChain(route, functionName, pprResumeKey),
310
313
  expiration: expirationFor(route),
311
314
  passQuery: true
312
315
  },
313
316
  exact: true,
314
- functionName: functionNameForPath(path, route.mode, names),
317
+ functionName,
315
318
  pattern: path,
316
319
  source: exactPathSource(path)
317
320
  };
@@ -2019,6 +2019,8 @@ function addNextFile(state, base, segments, sourcePath) {
2019
2019
  state.boundary.errorPath ??= sourcePath;
2020
2020
  } else if (base === "not-found") {
2021
2021
  state.boundary.notFoundPath ??= sourcePath;
2022
+ } else if (base === "loading") {
2023
+ state.boundary.pendingPath ??= sourcePath;
2022
2024
  }
2023
2025
  }
2024
2026
  function scanNext(pagesDir) {
@@ -2026,7 +2028,12 @@ function scanNext(pagesDir) {
2026
2028
  const boundaries = [];
2027
2029
  let rootPath;
2028
2030
  const walk = (directory, segments) => {
2029
- const boundary = { directory, errorPath: undefined, notFoundPath: undefined };
2031
+ const boundary = {
2032
+ directory,
2033
+ errorPath: undefined,
2034
+ notFoundPath: undefined,
2035
+ pendingPath: undefined
2036
+ };
2030
2037
  const state = { boundary, candidates, rootPath };
2031
2038
  for (const entry of sortedEntries(directory)) {
2032
2039
  const sourcePath = child(directory, entry.name);
@@ -2037,7 +2044,7 @@ function scanNext(pagesDir) {
2037
2044
  }
2038
2045
  }
2039
2046
  rootPath ??= state.rootPath;
2040
- if (boundary.errorPath || boundary.notFoundPath) {
2047
+ if (boundary.errorPath || boundary.notFoundPath || boundary.pendingPath) {
2041
2048
  boundaries.push(boundary);
2042
2049
  }
2043
2050
  };
@@ -7145,14 +7152,16 @@ function memberAccessStart(source, object, property) {
7145
7152
  const separator = accessGap.replace(/\/\*[\s\S]*?\*\/|\/\/[^\r\n]*/g, (comment) => " ".repeat(comment.length)).lastIndexOf(".");
7146
7153
  return object.end + separator - (accessGap[separator - 1] === "?" ? 1 : 0);
7147
7154
  }
7148
- function stripServerStage(module, stripped, range, remount) {
7155
+ function stripServerStage(module, stripped, range, policies) {
7149
7156
  const { removed, source } = module;
7150
- if (remount) {
7151
- const policy = source.slice(remount.start, remount.end);
7152
- for (const name of referencedNames(remount, removed)) {
7153
- stripped.retained.add(name);
7157
+ if (policies.length > 0) {
7158
+ const retained = policies.map((policy) => source.slice(policy.start, policy.end));
7159
+ for (const policy of policies) {
7160
+ for (const name of referencedNames(policy, removed)) {
7161
+ stripped.retained.add(name);
7162
+ }
7154
7163
  }
7155
- replaceRange(module, range.start, range.end, `.config({ ${policy} })`);
7164
+ replaceRange(module, range.start, range.end, `.config({ ${retained.join(", ")} })`);
7156
7165
  } else {
7157
7166
  removeRange(module, range.start, range.end);
7158
7167
  }
@@ -7165,20 +7174,36 @@ function removeChainedServerCalls(module, bindings, chains, stripped) {
7165
7174
  if (isRemoved(call, module.removed)) {
7166
7175
  continue;
7167
7176
  }
7168
- let remount = null;
7177
+ let policies = [];
7169
7178
  if (property.name === "config" && Array.isArray(call.arguments)) {
7170
7179
  const config = unwrapped(call.arguments[0]);
7171
7180
  if (config?.type === "ObjectExpression" && Array.isArray(config.properties)) {
7172
7181
  collectConfigBindings(config, declarations, stripped.configBindings);
7173
- remount = resolveRemountProperty(config, declarations, stripped.configBindings, new Set, filename);
7182
+ policies = clientPolicies(config, declarations, stripped.configBindings, filename);
7174
7183
  }
7175
7184
  }
7176
7185
  const accessStart = memberAccessStart(source.original, object, property);
7177
- stripServerStage(module, stripped, { end: call.end, start: accessStart }, remount);
7186
+ stripServerStage(module, stripped, { end: call.end, start: accessStart }, policies);
7178
7187
  transformed = true;
7179
7188
  }
7180
7189
  return transformed;
7181
7190
  }
7191
+ function clientPolicies(config, declarations, configBindings, filename) {
7192
+ const resolve = (name) => resolveConfigProperty(config, name, declarations, configBindings, new Set);
7193
+ const loaderDeps = resolve("loaderDeps");
7194
+ const remount = resolve("remountDeps");
7195
+ if (remount === UNRESOLVED) {
7196
+ throw new Error(`[furin] ${filename}: route config spreads must resolve to local object literals; declare remountDeps after dynamic spreads.`);
7197
+ }
7198
+ const policies = [];
7199
+ if (loaderDeps !== null && loaderDeps !== UNRESOLVED) {
7200
+ policies.push(loaderDeps);
7201
+ }
7202
+ if (remount !== null) {
7203
+ policies.push(remount);
7204
+ }
7205
+ return policies;
7206
+ }
7182
7207
  function declaredInitializer(declaration) {
7183
7208
  return declaration?.type === "VariableDeclarator" ? unwrapped(declaration.init) : null;
7184
7209
  }
@@ -7196,28 +7221,29 @@ function collectConfigBindings(config, declarations, names) {
7196
7221
  }
7197
7222
  }
7198
7223
  }
7199
- function resolveRemountProperty(config, declarations, configBindings, visiting, filename) {
7224
+ var UNRESOLVED = Symbol("unresolved");
7225
+ function resolveConfigProperty(config, name, declarations, configBindings, visiting) {
7200
7226
  if (config?.type === "Identifier" && !visiting.has(config.name)) {
7201
7227
  visiting.add(config.name);
7202
7228
  configBindings.add(config.name);
7203
7229
  const declaration = declarations.get(config.name);
7204
- const result = resolveRemountProperty(declaredInitializer(declaration), declarations, configBindings, visiting, filename);
7230
+ const result = resolveConfigProperty(declaredInitializer(declaration), name, declarations, configBindings, visiting);
7205
7231
  visiting.delete(config.name);
7206
7232
  return result;
7207
7233
  }
7208
7234
  if (config?.type !== "ObjectExpression" || !Array.isArray(config.properties)) {
7209
- throw new Error(`[furin] ${filename}: route config spreads must resolve to local object literals; declare remountDeps after dynamic spreads.`);
7235
+ return UNRESOLVED;
7210
7236
  }
7211
7237
  for (let index = config.properties.length - 1;index >= 0; index -= 1) {
7212
7238
  const entry = unwrapped(config.properties[index]);
7213
7239
  if (entry?.type === "SpreadElement") {
7214
- const remount = resolveRemountProperty(unwrapped(entry.argument), declarations, configBindings, visiting, filename);
7215
- if (remount) {
7216
- return remount;
7240
+ const property = resolveConfigProperty(unwrapped(entry.argument), name, declarations, configBindings, visiting);
7241
+ if (property) {
7242
+ return property;
7217
7243
  }
7218
7244
  } else if (entry?.type === "Property") {
7219
7245
  const key = unwrapped(entry.key);
7220
- if (key?.type === "Identifier" && entry.computed !== true && key.name === "remountDeps" || key?.type === "Literal" && key.value === "remountDeps") {
7246
+ if (key?.type === "Identifier" && entry.computed !== true && key.name === name || key?.type === "Literal" && key.value === name) {
7221
7247
  return entry;
7222
7248
  }
7223
7249
  }
@@ -7311,8 +7337,8 @@ var ELYSIA_FILTER = /^elysia$/;
7311
7337
  var BUN_BUILTIN_FILTER = /^bun:/;
7312
7338
  var ANY_FILTER = /.*/;
7313
7339
  var elysiaStub = (typeModule) => `export * as t from ${JSON.stringify(typeModule)};
7340
+ export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, InvalidCookie, NotFound, ParseError, ValidationError, problem, status, validationDetail } from ${JSON.stringify(Bun.resolveSync("elysia/error", dirname9(typeModule)))};
7314
7341
  export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
7315
- export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
7316
7342
  export default {};
7317
7343
  `;
7318
7344
  var ELYSIA_STUB_PREFIX = "elysia-stub:";
@@ -7741,7 +7767,8 @@ function hydrateEntry(routes, rootLayout, basePath, clientLogging, modulePathKey
7741
7767
  for (const seg of route.segmentBoundaries ?? []) {
7742
7768
  const errorIdent = getBoundaryIdent(boundaryIdents, seg.errorPath);
7743
7769
  const notFoundIdent = getBoundaryIdent(boundaryIdents, seg.notFoundPath);
7744
- if (!(errorIdent || notFoundIdent)) {
7770
+ const pendingIdent = getBoundaryIdent(boundaryIdents, seg.pendingPath);
7771
+ if (!(errorIdent || notFoundIdent || pendingIdent)) {
7745
7772
  continue;
7746
7773
  }
7747
7774
  const parts = [`depth: ${seg.depth}`];
@@ -7753,6 +7780,9 @@ function hydrateEntry(routes, rootLayout, basePath, clientLogging, modulePathKey
7753
7780
  if (notFoundIdent) {
7754
7781
  parts.push(`notFound: ${notFoundIdent}.${notFoundExport}`);
7755
7782
  }
7783
+ if (pendingIdent) {
7784
+ parts.push(seg.fromRoute ? `pending: ${pendingIdent}.route.pending` : `pending: { component: ${pendingIdent}.default, minMs: ${pendingIdent}.pendingMinMs, ms: ${pendingIdent}.pendingMs }`);
7785
+ }
7756
7786
  if (seg.depth === 0 && seg.path.replaceAll("\\", "/") !== rootDirectory) {
7757
7787
  parts.push("isRoot: false");
7758
7788
  }
@@ -7771,7 +7801,7 @@ function hydrateEntry(routes, rootLayout, basePath, clientLogging, modulePathKey
7771
7801
  }).join(" ");
7772
7802
  const boundaryResult = boundaryLiterals.length > 0 ? `, segmentBoundaries: [${boundaryLiterals.join(", ")}]` : "";
7773
7803
  const pageComponentKey = JSON.stringify(`page:${modulePathKey(resolvedPage)}`);
7774
- const loadBody = `Promise.all([${lazyImports.join(", ")}]).then(([${importIdents.join(", ")}]) => { const __furin_page_route = __furin_page.route; let __furin_parent = root; ${layoutAssignments} return { default: { __type: "FURIN_PAGE", _route: { __type: "FURIN_ROUTE", parent: __furin_parent, remountDeps: __furin_page_route.remountDeps }, component: hotComponent(${pageComponentKey}, __furin_page_route.component) }${boundaryResult} }; })`;
7804
+ const loadBody = `Promise.all([${lazyImports.join(", ")}]).then(([${importIdents.join(", ")}]) => { const __furin_page_route = __furin_page.route; let __furin_parent = root; ${layoutAssignments} return { default: { __type: "FURIN_PAGE", _route: { __type: "FURIN_ROUTE", parent: __furin_parent, loaderDeps: __furin_page_route.loaderDeps, remountDeps: __furin_page_route.remountDeps }, component: hotComponent(${pageComponentKey}, __furin_page_route.component) }${boundaryResult} }; })`;
7775
7805
  const searchDefaultsEntry = searchDefaults ? `, searchDefaults: ${JSON.stringify(searchDefaults)}` : "";
7776
7806
  routeEntries.push(` { pattern: ${JSON.stringify(route.pattern)}, regex: new RegExp(${JSON.stringify(regexPattern)}), load: () => ${loadBody}${searchDefaultsEntry} }`);
7777
7807
  }
@@ -8098,7 +8128,7 @@ import { basename as basename3, resolve as resolve6 } from "path";
8098
8128
  var CLIENT_MODULE_KEY_RE = /(["'`])(__FURIN_CLIENT_MODULE_[a-z0-9]+__)\1/g;
8099
8129
  function routeModulePaths(route) {
8100
8130
  const layouts = (route.routeChain ?? []).slice(1).filter((entry) => entry.layout && entry.sourcePath).map((entry) => entry.sourcePath);
8101
- const boundaries = (route.segmentBoundaries ?? []).flatMap((segment) => [segment.errorPath, segment.notFoundPath].filter((path) => path !== undefined));
8131
+ const boundaries = (route.segmentBoundaries ?? []).flatMap((segment) => [segment.errorPath, segment.notFoundPath, segment.pendingPath].filter((path) => path !== undefined));
8102
8132
  return [route.path, ...layouts, ...boundaries];
8103
8133
  }
8104
8134
  function realPath(path) {
@@ -8347,6 +8377,9 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
8347
8377
  if (segment.notFoundPath) {
8348
8378
  fingerprintPaths.add(segment.notFoundPath);
8349
8379
  }
8380
+ if (segment.pendingPath) {
8381
+ fingerprintPaths.add(segment.pendingPath);
8382
+ }
8350
8383
  }
8351
8384
  }
8352
8385
  const sources = new Map;
@@ -8441,7 +8474,8 @@ function buildCompileMetadata(root, routes) {
8441
8474
  errorPath: boundary.errorPath ? toPosixPath(boundary.errorPath) : undefined,
8442
8475
  ...boundary.fromRoute ? { fromRoute: boundary.fromRoute } : {},
8443
8476
  notFoundPath: boundary.notFoundPath ? toPosixPath(boundary.notFoundPath) : undefined,
8444
- path: toPosixPath(boundary.path)
8477
+ path: toPosixPath(boundary.path),
8478
+ pendingPath: boundary.pendingPath ? toPosixPath(boundary.pendingPath) : undefined
8445
8479
  }))
8446
8480
  };
8447
8481
  }
@@ -9683,6 +9717,9 @@ function expirationFor(route) {
9683
9717
  function prerenderAllowQuery(route) {
9684
9718
  return route.queryKeys === null ? undefined : [ISR_PATH_PARAM, ...route.queryKeys];
9685
9719
  }
9720
+ function pprChain(route, functionName, pprResumeKey) {
9721
+ return route.ppr ? { headers: { "x-furin-ppr-resume": pprResumeKey }, outputPath: functionName } : undefined;
9722
+ }
9686
9723
  function createPrerenderSpecs(apps, pprResumeKey) {
9687
9724
  const specs = new Map;
9688
9725
  const names = new Map;
@@ -9694,17 +9731,16 @@ function createPrerenderSpecs(apps, pprResumeKey) {
9694
9731
  }
9695
9732
  const physicalPattern = physicalPath(app.prefix, route.pattern);
9696
9733
  const source = routePatternSource(app.prefix, route.pattern);
9734
+ const functionName = functionNameForPath(physicalPattern, route.mode, names);
9697
9735
  specs.set(source, {
9698
9736
  config: {
9699
9737
  allowQuery: prerenderAllowQuery(route),
9700
9738
  expiration: expirationFor(route),
9701
9739
  passQuery: true,
9702
- ...route.ppr ? {
9703
- chain: { headers: { "x-furin-ppr-resume": pprResumeKey }, outputPath: "__server" }
9704
- } : {}
9740
+ chain: pprChain(route, functionName, pprResumeKey)
9705
9741
  },
9706
9742
  exact: !DYNAMIC_SEGMENT_RE.test(route.pattern),
9707
- functionName: functionNameForPath(physicalPattern, route.mode, names),
9743
+ functionName,
9708
9744
  pattern: physicalPattern,
9709
9745
  source
9710
9746
  });
@@ -9719,15 +9755,16 @@ function createPrerenderSpecs(apps, pprResumeKey) {
9719
9755
  const path = physicalPath(app.prefix, prerender.path);
9720
9756
  let spec = specs.get(routePatternSource(app.prefix, route.pattern));
9721
9757
  if (DYNAMIC_SEGMENT_RE.test(route.pattern)) {
9758
+ const functionName = functionNameForPath(path, route.mode, names);
9722
9759
  spec = {
9723
9760
  config: {
9724
9761
  allowQuery: spec.config.allowQuery,
9725
- chain: spec.config.chain,
9762
+ chain: pprChain(route, functionName, pprResumeKey),
9726
9763
  expiration: expirationFor(route),
9727
9764
  passQuery: true
9728
9765
  },
9729
9766
  exact: true,
9730
- functionName: functionNameForPath(path, route.mode, names),
9767
+ functionName,
9731
9768
  pattern: path,
9732
9769
  source: exactPathSource(path)
9733
9770
  };
@@ -10163,12 +10200,18 @@ function checkParams(file, route, parsed) {
10163
10200
  return issueAt(file, parsed, parsed.route.config ?? parsed.route.head, `The path param${plural ? "s" : ""} ${missing.map(({ name }) => name).join(", ")} ${plural ? "are" : "is"} missing from this page's params schema. Each page declares every dynamic segment of its path, including those of its layouts. Add to config():${tImport}
10164
10201
  ${paramsSchema(missing)}`);
10165
10202
  }
10203
+ var BOUNDARY_CONVENTIONS = {
10204
+ error: "an error.tsx",
10205
+ notFound: "a not-found.tsx",
10206
+ pending: "a loading.tsx"
10207
+ };
10208
+ var BOUNDARY_METHODS = ["error", "notFound", "pending"];
10166
10209
  function checkBoundaryMethods(file, instance, parsed) {
10167
- const method = ["error", "notFound"].find((name) => parsed.route.methods.has(name));
10210
+ const method = BOUNDARY_METHODS.find((name) => parsed.route.methods.has(name));
10168
10211
  if (instance.style !== "nextjs" || method === undefined) {
10169
10212
  return;
10170
10213
  }
10171
- const convention = method === "error" ? "an error.tsx" : "a not-found.tsx";
10214
+ const convention = BOUNDARY_CONVENTIONS[method];
10172
10215
  return issueAt(file, parsed, parsed.route.head, `.${method}() is the TanStack style. In the nextjs style, default-export the component from ${convention} next to this route.`);
10173
10216
  }
10174
10217
  function checkRoute(file, instance, route, parsed) {
@@ -18,7 +18,7 @@ export interface BuildRoute extends Pick<ResolvedRoute, "layouts" | "mode" | "pa
18
18
  layout: boolean;
19
19
  sourcePath?: string;
20
20
  }[];
21
- segmentBoundaries: Pick<SegmentBoundary, "depth" | "path" | "errorPath" | "fromRoute" | "notFoundPath">[];
21
+ segmentBoundaries: Pick<SegmentBoundary, "depth" | "path" | "errorPath" | "fromRoute" | "notFoundPath" | "pendingPath">[];
22
22
  }
23
23
  export type BuildRouteInput = BuildRoute | ResolvedRoute;
24
24
  export type BuildRoot = Pick<RootLayout, "path" | "errorPath" | "notFoundPath"> & {
package/dist/cli/index.js CHANGED
@@ -2026,6 +2026,8 @@ function addNextFile(state, base, segments, sourcePath) {
2026
2026
  state.boundary.errorPath ??= sourcePath;
2027
2027
  } else if (base === "not-found") {
2028
2028
  state.boundary.notFoundPath ??= sourcePath;
2029
+ } else if (base === "loading") {
2030
+ state.boundary.pendingPath ??= sourcePath;
2029
2031
  }
2030
2032
  }
2031
2033
  function scanNext(pagesDir) {
@@ -2033,7 +2035,12 @@ function scanNext(pagesDir) {
2033
2035
  const boundaries = [];
2034
2036
  let rootPath;
2035
2037
  const walk = (directory, segments) => {
2036
- const boundary = { directory, errorPath: undefined, notFoundPath: undefined };
2038
+ const boundary = {
2039
+ directory,
2040
+ errorPath: undefined,
2041
+ notFoundPath: undefined,
2042
+ pendingPath: undefined
2043
+ };
2037
2044
  const state = { boundary, candidates, rootPath };
2038
2045
  for (const entry of sortedEntries(directory)) {
2039
2046
  const sourcePath = child(directory, entry.name);
@@ -2044,7 +2051,7 @@ function scanNext(pagesDir) {
2044
2051
  }
2045
2052
  }
2046
2053
  rootPath ??= state.rootPath;
2047
- if (boundary.errorPath || boundary.notFoundPath) {
2054
+ if (boundary.errorPath || boundary.notFoundPath || boundary.pendingPath) {
2048
2055
  boundaries.push(boundary);
2049
2056
  }
2050
2057
  };
@@ -7152,14 +7159,16 @@ function memberAccessStart(source, object, property) {
7152
7159
  const separator = accessGap.replace(/\/\*[\s\S]*?\*\/|\/\/[^\r\n]*/g, (comment) => " ".repeat(comment.length)).lastIndexOf(".");
7153
7160
  return object.end + separator - (accessGap[separator - 1] === "?" ? 1 : 0);
7154
7161
  }
7155
- function stripServerStage(module, stripped, range, remount) {
7162
+ function stripServerStage(module, stripped, range, policies) {
7156
7163
  const { removed, source } = module;
7157
- if (remount) {
7158
- const policy = source.slice(remount.start, remount.end);
7159
- for (const name of referencedNames(remount, removed)) {
7160
- stripped.retained.add(name);
7164
+ if (policies.length > 0) {
7165
+ const retained = policies.map((policy) => source.slice(policy.start, policy.end));
7166
+ for (const policy of policies) {
7167
+ for (const name of referencedNames(policy, removed)) {
7168
+ stripped.retained.add(name);
7169
+ }
7161
7170
  }
7162
- replaceRange(module, range.start, range.end, `.config({ ${policy} })`);
7171
+ replaceRange(module, range.start, range.end, `.config({ ${retained.join(", ")} })`);
7163
7172
  } else {
7164
7173
  removeRange(module, range.start, range.end);
7165
7174
  }
@@ -7172,20 +7181,36 @@ function removeChainedServerCalls(module, bindings, chains, stripped) {
7172
7181
  if (isRemoved(call, module.removed)) {
7173
7182
  continue;
7174
7183
  }
7175
- let remount = null;
7184
+ let policies = [];
7176
7185
  if (property.name === "config" && Array.isArray(call.arguments)) {
7177
7186
  const config = unwrapped(call.arguments[0]);
7178
7187
  if (config?.type === "ObjectExpression" && Array.isArray(config.properties)) {
7179
7188
  collectConfigBindings(config, declarations, stripped.configBindings);
7180
- remount = resolveRemountProperty(config, declarations, stripped.configBindings, new Set, filename);
7189
+ policies = clientPolicies(config, declarations, stripped.configBindings, filename);
7181
7190
  }
7182
7191
  }
7183
7192
  const accessStart = memberAccessStart(source.original, object, property);
7184
- stripServerStage(module, stripped, { end: call.end, start: accessStart }, remount);
7193
+ stripServerStage(module, stripped, { end: call.end, start: accessStart }, policies);
7185
7194
  transformed = true;
7186
7195
  }
7187
7196
  return transformed;
7188
7197
  }
7198
+ function clientPolicies(config, declarations, configBindings, filename) {
7199
+ const resolve = (name) => resolveConfigProperty(config, name, declarations, configBindings, new Set);
7200
+ const loaderDeps = resolve("loaderDeps");
7201
+ const remount = resolve("remountDeps");
7202
+ if (remount === UNRESOLVED) {
7203
+ throw new Error(`[furin] ${filename}: route config spreads must resolve to local object literals; declare remountDeps after dynamic spreads.`);
7204
+ }
7205
+ const policies = [];
7206
+ if (loaderDeps !== null && loaderDeps !== UNRESOLVED) {
7207
+ policies.push(loaderDeps);
7208
+ }
7209
+ if (remount !== null) {
7210
+ policies.push(remount);
7211
+ }
7212
+ return policies;
7213
+ }
7189
7214
  function declaredInitializer(declaration) {
7190
7215
  return declaration?.type === "VariableDeclarator" ? unwrapped(declaration.init) : null;
7191
7216
  }
@@ -7203,28 +7228,29 @@ function collectConfigBindings(config, declarations, names) {
7203
7228
  }
7204
7229
  }
7205
7230
  }
7206
- function resolveRemountProperty(config, declarations, configBindings, visiting, filename) {
7231
+ var UNRESOLVED = Symbol("unresolved");
7232
+ function resolveConfigProperty(config, name, declarations, configBindings, visiting) {
7207
7233
  if (config?.type === "Identifier" && !visiting.has(config.name)) {
7208
7234
  visiting.add(config.name);
7209
7235
  configBindings.add(config.name);
7210
7236
  const declaration = declarations.get(config.name);
7211
- const result = resolveRemountProperty(declaredInitializer(declaration), declarations, configBindings, visiting, filename);
7237
+ const result = resolveConfigProperty(declaredInitializer(declaration), name, declarations, configBindings, visiting);
7212
7238
  visiting.delete(config.name);
7213
7239
  return result;
7214
7240
  }
7215
7241
  if (config?.type !== "ObjectExpression" || !Array.isArray(config.properties)) {
7216
- throw new Error(`[furin] ${filename}: route config spreads must resolve to local object literals; declare remountDeps after dynamic spreads.`);
7242
+ return UNRESOLVED;
7217
7243
  }
7218
7244
  for (let index = config.properties.length - 1;index >= 0; index -= 1) {
7219
7245
  const entry = unwrapped(config.properties[index]);
7220
7246
  if (entry?.type === "SpreadElement") {
7221
- const remount = resolveRemountProperty(unwrapped(entry.argument), declarations, configBindings, visiting, filename);
7222
- if (remount) {
7223
- return remount;
7247
+ const property = resolveConfigProperty(unwrapped(entry.argument), name, declarations, configBindings, visiting);
7248
+ if (property) {
7249
+ return property;
7224
7250
  }
7225
7251
  } else if (entry?.type === "Property") {
7226
7252
  const key = unwrapped(entry.key);
7227
- if (key?.type === "Identifier" && entry.computed !== true && key.name === "remountDeps" || key?.type === "Literal" && key.value === "remountDeps") {
7253
+ if (key?.type === "Identifier" && entry.computed !== true && key.name === name || key?.type === "Literal" && key.value === name) {
7228
7254
  return entry;
7229
7255
  }
7230
7256
  }
@@ -7318,8 +7344,8 @@ var ELYSIA_FILTER = /^elysia$/;
7318
7344
  var BUN_BUILTIN_FILTER = /^bun:/;
7319
7345
  var ANY_FILTER = /.*/;
7320
7346
  var elysiaStub = (typeModule) => `export * as t from ${JSON.stringify(typeModule)};
7347
+ export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, InvalidCookie, NotFound, ParseError, ValidationError, problem, status, validationDetail } from ${JSON.stringify(Bun.resolveSync("elysia/error", dirname9(typeModule)))};
7321
7348
  export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
7322
- export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
7323
7349
  export default {};
7324
7350
  `;
7325
7351
  var ELYSIA_STUB_PREFIX = "elysia-stub:";
@@ -7748,7 +7774,8 @@ function hydrateEntry(routes, rootLayout, basePath, clientLogging, modulePathKey
7748
7774
  for (const seg of route.segmentBoundaries ?? []) {
7749
7775
  const errorIdent = getBoundaryIdent(boundaryIdents, seg.errorPath);
7750
7776
  const notFoundIdent = getBoundaryIdent(boundaryIdents, seg.notFoundPath);
7751
- if (!(errorIdent || notFoundIdent)) {
7777
+ const pendingIdent = getBoundaryIdent(boundaryIdents, seg.pendingPath);
7778
+ if (!(errorIdent || notFoundIdent || pendingIdent)) {
7752
7779
  continue;
7753
7780
  }
7754
7781
  const parts = [`depth: ${seg.depth}`];
@@ -7760,6 +7787,9 @@ function hydrateEntry(routes, rootLayout, basePath, clientLogging, modulePathKey
7760
7787
  if (notFoundIdent) {
7761
7788
  parts.push(`notFound: ${notFoundIdent}.${notFoundExport}`);
7762
7789
  }
7790
+ if (pendingIdent) {
7791
+ parts.push(seg.fromRoute ? `pending: ${pendingIdent}.route.pending` : `pending: { component: ${pendingIdent}.default, minMs: ${pendingIdent}.pendingMinMs, ms: ${pendingIdent}.pendingMs }`);
7792
+ }
7763
7793
  if (seg.depth === 0 && seg.path.replaceAll("\\", "/") !== rootDirectory) {
7764
7794
  parts.push("isRoot: false");
7765
7795
  }
@@ -7778,7 +7808,7 @@ function hydrateEntry(routes, rootLayout, basePath, clientLogging, modulePathKey
7778
7808
  }).join(" ");
7779
7809
  const boundaryResult = boundaryLiterals.length > 0 ? `, segmentBoundaries: [${boundaryLiterals.join(", ")}]` : "";
7780
7810
  const pageComponentKey = JSON.stringify(`page:${modulePathKey(resolvedPage)}`);
7781
- const loadBody = `Promise.all([${lazyImports.join(", ")}]).then(([${importIdents.join(", ")}]) => { const __furin_page_route = __furin_page.route; let __furin_parent = root; ${layoutAssignments} return { default: { __type: "FURIN_PAGE", _route: { __type: "FURIN_ROUTE", parent: __furin_parent, remountDeps: __furin_page_route.remountDeps }, component: hotComponent(${pageComponentKey}, __furin_page_route.component) }${boundaryResult} }; })`;
7811
+ const loadBody = `Promise.all([${lazyImports.join(", ")}]).then(([${importIdents.join(", ")}]) => { const __furin_page_route = __furin_page.route; let __furin_parent = root; ${layoutAssignments} return { default: { __type: "FURIN_PAGE", _route: { __type: "FURIN_ROUTE", parent: __furin_parent, loaderDeps: __furin_page_route.loaderDeps, remountDeps: __furin_page_route.remountDeps }, component: hotComponent(${pageComponentKey}, __furin_page_route.component) }${boundaryResult} }; })`;
7782
7812
  const searchDefaultsEntry = searchDefaults ? `, searchDefaults: ${JSON.stringify(searchDefaults)}` : "";
7783
7813
  routeEntries.push(` { pattern: ${JSON.stringify(route.pattern)}, regex: new RegExp(${JSON.stringify(regexPattern)}), load: () => ${loadBody}${searchDefaultsEntry} }`);
7784
7814
  }
@@ -8105,7 +8135,7 @@ import { basename as basename3, resolve as resolve6 } from "path";
8105
8135
  var CLIENT_MODULE_KEY_RE = /(["'`])(__FURIN_CLIENT_MODULE_[a-z0-9]+__)\1/g;
8106
8136
  function routeModulePaths(route) {
8107
8137
  const layouts = (route.routeChain ?? []).slice(1).filter((entry) => entry.layout && entry.sourcePath).map((entry) => entry.sourcePath);
8108
- const boundaries = (route.segmentBoundaries ?? []).flatMap((segment) => [segment.errorPath, segment.notFoundPath].filter((path) => path !== undefined));
8138
+ const boundaries = (route.segmentBoundaries ?? []).flatMap((segment) => [segment.errorPath, segment.notFoundPath, segment.pendingPath].filter((path) => path !== undefined));
8109
8139
  return [route.path, ...layouts, ...boundaries];
8110
8140
  }
8111
8141
  function realPath(path) {
@@ -8354,6 +8384,9 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
8354
8384
  if (segment.notFoundPath) {
8355
8385
  fingerprintPaths.add(segment.notFoundPath);
8356
8386
  }
8387
+ if (segment.pendingPath) {
8388
+ fingerprintPaths.add(segment.pendingPath);
8389
+ }
8357
8390
  }
8358
8391
  }
8359
8392
  const sources = new Map;
@@ -8448,7 +8481,8 @@ function buildCompileMetadata(root, routes) {
8448
8481
  errorPath: boundary.errorPath ? toPosixPath(boundary.errorPath) : undefined,
8449
8482
  ...boundary.fromRoute ? { fromRoute: boundary.fromRoute } : {},
8450
8483
  notFoundPath: boundary.notFoundPath ? toPosixPath(boundary.notFoundPath) : undefined,
8451
- path: toPosixPath(boundary.path)
8484
+ path: toPosixPath(boundary.path),
8485
+ pendingPath: boundary.pendingPath ? toPosixPath(boundary.pendingPath) : undefined
8452
8486
  }))
8453
8487
  };
8454
8488
  }
@@ -9690,6 +9724,9 @@ function expirationFor(route) {
9690
9724
  function prerenderAllowQuery(route) {
9691
9725
  return route.queryKeys === null ? undefined : [ISR_PATH_PARAM, ...route.queryKeys];
9692
9726
  }
9727
+ function pprChain(route, functionName, pprResumeKey) {
9728
+ return route.ppr ? { headers: { "x-furin-ppr-resume": pprResumeKey }, outputPath: functionName } : undefined;
9729
+ }
9693
9730
  function createPrerenderSpecs(apps, pprResumeKey) {
9694
9731
  const specs = new Map;
9695
9732
  const names = new Map;
@@ -9701,17 +9738,16 @@ function createPrerenderSpecs(apps, pprResumeKey) {
9701
9738
  }
9702
9739
  const physicalPattern = physicalPath(app.prefix, route.pattern);
9703
9740
  const source = routePatternSource(app.prefix, route.pattern);
9741
+ const functionName = functionNameForPath(physicalPattern, route.mode, names);
9704
9742
  specs.set(source, {
9705
9743
  config: {
9706
9744
  allowQuery: prerenderAllowQuery(route),
9707
9745
  expiration: expirationFor(route),
9708
9746
  passQuery: true,
9709
- ...route.ppr ? {
9710
- chain: { headers: { "x-furin-ppr-resume": pprResumeKey }, outputPath: "__server" }
9711
- } : {}
9747
+ chain: pprChain(route, functionName, pprResumeKey)
9712
9748
  },
9713
9749
  exact: !DYNAMIC_SEGMENT_RE.test(route.pattern),
9714
- functionName: functionNameForPath(physicalPattern, route.mode, names),
9750
+ functionName,
9715
9751
  pattern: physicalPattern,
9716
9752
  source
9717
9753
  });
@@ -9726,15 +9762,16 @@ function createPrerenderSpecs(apps, pprResumeKey) {
9726
9762
  const path = physicalPath(app.prefix, prerender.path);
9727
9763
  let spec = specs.get(routePatternSource(app.prefix, route.pattern));
9728
9764
  if (DYNAMIC_SEGMENT_RE.test(route.pattern)) {
9765
+ const functionName = functionNameForPath(path, route.mode, names);
9729
9766
  spec = {
9730
9767
  config: {
9731
9768
  allowQuery: spec.config.allowQuery,
9732
- chain: spec.config.chain,
9769
+ chain: pprChain(route, functionName, pprResumeKey),
9733
9770
  expiration: expirationFor(route),
9734
9771
  passQuery: true
9735
9772
  },
9736
9773
  exact: true,
9737
- functionName: functionNameForPath(path, route.mode, names),
9774
+ functionName,
9738
9775
  pattern: path,
9739
9776
  source: exactPathSource(path)
9740
9777
  };
@@ -10170,12 +10207,18 @@ function checkParams(file, route, parsed) {
10170
10207
  return issueAt(file, parsed, parsed.route.config ?? parsed.route.head, `The path param${plural ? "s" : ""} ${missing.map(({ name }) => name).join(", ")} ${plural ? "are" : "is"} missing from this page's params schema. Each page declares every dynamic segment of its path, including those of its layouts. Add to config():${tImport}
10171
10208
  ${paramsSchema(missing)}`);
10172
10209
  }
10210
+ var BOUNDARY_CONVENTIONS = {
10211
+ error: "an error.tsx",
10212
+ notFound: "a not-found.tsx",
10213
+ pending: "a loading.tsx"
10214
+ };
10215
+ var BOUNDARY_METHODS = ["error", "notFound", "pending"];
10173
10216
  function checkBoundaryMethods(file, instance, parsed) {
10174
- const method = ["error", "notFound"].find((name) => parsed.route.methods.has(name));
10217
+ const method = BOUNDARY_METHODS.find((name) => parsed.route.methods.has(name));
10175
10218
  if (instance.style !== "nextjs" || method === undefined) {
10176
10219
  return;
10177
10220
  }
10178
- const convention = method === "error" ? "an error.tsx" : "a not-found.tsx";
10221
+ const convention = BOUNDARY_CONVENTIONS[method];
10179
10222
  return issueAt(file, parsed, parsed.route.head, `.${method}() is the TanStack style. In the nextjs style, default-export the component from ${convention} next to this route.`);
10180
10223
  }
10181
10224
  function checkRoute(file, instance, route, parsed) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  navigationHrefPolicy
3
- } from "./client-a7spxfnn.js";
3
+ } from "./client-xf7r768c.js";
4
4
 
5
5
  // src/client/router/search-store.ts
6
6
  import { createContext } from "react";
@@ -2,7 +2,7 @@ import {
2
2
  isWithinPrefix,
3
3
  encodeInvalidationEntry,
4
4
  buildHref2
5
- } from "./client-a7spxfnn.js";
5
+ } from "./client-xf7r768c.js";
6
6
 
7
7
  // src/client/document.tsx
8
8
  import { createContext, createElement, useContext } from "react";
@@ -240,6 +240,18 @@ function resolveRouteTarget(target, routes) {
240
240
  const path = applyLinkParams(target.to, target.params);
241
241
  return buildHref2(path, target.search, target.hash, findSearchDefaultsForRouteTarget(path, routes));
242
242
  }
243
+ function resolveTargetSearch(path, search, routes) {
244
+ if (path.includes("?")) {
245
+ return;
246
+ }
247
+ const resolved = { ...findSearchDefaultsForRouteTarget(path, routes) };
248
+ for (const [key, value] of Object.entries(search ?? {})) {
249
+ if (value !== null && value !== undefined) {
250
+ resolved[key] = value;
251
+ }
252
+ }
253
+ return resolved;
254
+ }
243
255
  function buildHref2(to, search, hash, searchDefaults) {
244
256
  let url = to;
245
257
  if (search && Object.keys(search).length > 0) {
@@ -333,4 +345,4 @@ function toLogical2(physicalPathname, basePath) {
333
345
  return physicalPathname;
334
346
  }
335
347
 
336
- export { physicalPath, isWithinPrefix, encodeInvalidationEntry, findSearchDefaultsForRouteTarget, TRAILING_SLASHES_RE, navigationHrefPolicy, decodeHashFragment, isSameOriginFetchResult, applyLinkParams, resolveRouteTarget, buildHref2, applyRevalidateHeader2, applyRevalidateEntries, shouldAutoRefreshPath2, stripHashFromHref, normalizeHref2, shouldRefetch2, shouldInterceptClick2, toLogical2 };
348
+ export { physicalPath, isWithinPrefix, encodeInvalidationEntry, deepEqual, findSearchDefaultsForRouteTarget, TRAILING_SLASHES_RE, navigationHrefPolicy, decodeHashFragment, isSameOriginFetchResult, applyLinkParams, resolveRouteTarget, resolveTargetSearch, buildHref2, applyRevalidateHeader2, applyRevalidateEntries, shouldAutoRefreshPath2, stripHashFromHref, normalizeHref2, shouldRefetch2, shouldInterceptClick2, toLogical2 };