@teyik0/furin 0.9.0-alpha.3 → 0.9.0-alpha.5

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 (75) hide show
  1. package/dist/adapter/runtime-build.d.ts +1 -0
  2. package/dist/build/index.js +65 -25
  3. package/dist/build/route-metadata.d.ts +1 -1
  4. package/dist/cli/index.js +65 -25
  5. package/dist/client/chunks/{client-rdxyrw11.js → client-hjqd5m3b.js} +1 -1
  6. package/dist/client/chunks/{client-d9v49jwz.js → client-whph3y67.js} +66 -3
  7. package/dist/client/chunks/{client-a7spxfnn.js → client-xf7r768c.js} +13 -1
  8. package/dist/client/define-route.d.ts +12 -0
  9. package/dist/client/internal/runtime-types.d.ts +7 -0
  10. package/dist/client/link.js +200 -40
  11. package/dist/client/query.d.ts +13 -0
  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.d.ts +1 -1
  21. package/dist/client.js +21 -4
  22. package/dist/define-route.d.ts +37 -10
  23. package/dist/furin.js +92 -43
  24. package/dist/plugin/client-plugin.d.ts +1 -1
  25. package/dist/plugin/index.js +36 -17
  26. package/dist/plugin/route-manifest.d.ts +2 -1
  27. package/dist/plugin/strip-server-stages.d.ts +1 -1
  28. package/dist/server/dev/graph.d.ts +0 -1
  29. package/dist/server/internal.d.ts +1 -0
  30. package/dist/server/internal.js +46 -22
  31. package/dist/server/router/defined-route.d.ts +3 -0
  32. package/dist/server/router/hmr.d.ts +0 -1
  33. package/dist/server/router/source-version.d.ts +0 -1
  34. package/dist/server/router/types.d.ts +7 -1
  35. package/dist/server/static-export.js +49 -22
  36. package/dist/server/sync/index.js +1 -1
  37. package/dist/shared/pending.d.ts +13 -0
  38. package/dist/shared/search-params.d.ts +1 -0
  39. package/dist/sync-client.js +1 -1
  40. package/package.json +1 -1
  41. package/src/adapter/runtime-build.ts +4 -0
  42. package/src/build/hydrate.ts +11 -2
  43. package/src/build/preload-manifest.ts +3 -1
  44. package/src/build/route-metadata.ts +3 -2
  45. package/src/client/define-route.ts +23 -3
  46. package/src/client/internal/runtime-types.ts +7 -0
  47. package/src/client/link.tsx +26 -4
  48. package/src/client/query-store.ts +2 -1
  49. package/src/client/query.tsx +87 -0
  50. package/src/client/route-element.tsx +41 -15
  51. package/src/client/router/context.ts +29 -8
  52. package/src/client/router/history.ts +10 -0
  53. package/src/client/router/link-utils.ts +23 -0
  54. package/src/client/router/navigation-controller.ts +239 -19
  55. package/src/client/router/pending.ts +58 -0
  56. package/src/client/router/provider.tsx +5 -2
  57. package/src/client/router/search/index.ts +7 -2
  58. package/src/client/router/types.ts +29 -3
  59. package/src/client.ts +1 -1
  60. package/src/define-route.ts +74 -26
  61. package/src/plugin/client-plugin.ts +5 -4
  62. package/src/plugin/route-config.ts +9 -2
  63. package/src/plugin/route-manifest.ts +11 -3
  64. package/src/plugin/route-tree.ts +2 -2
  65. package/src/plugin/strip-server-stages.ts +60 -35
  66. package/src/server/dev/graph.ts +2 -7
  67. package/src/server/dev/runtime.ts +1 -2
  68. package/src/server/internal.ts +1 -0
  69. package/src/server/router/defined-route.ts +6 -0
  70. package/src/server/router/discovery.ts +5 -2
  71. package/src/server/router/hmr.ts +1 -5
  72. package/src/server/router/source-version.ts +3 -6
  73. package/src/server/router/types.ts +7 -1
  74. package/src/shared/pending.ts +16 -0
  75. package/src/shared/search-params.ts +1 -1
@@ -8,6 +8,7 @@ import { getSchemaValidator, isTypeBoxObjectSchema } from "./shared/elysia-contr
8
8
  import type { ErrorComponent } from "./shared/error.ts";
9
9
  import type { NotFoundComponent } from "./shared/not-found.ts";
10
10
  import type { RemountDependency, RemountDeps } from "./shared/page-key.ts";
11
+ import type { PendingComponent, PendingOptions, RoutePending } from "./shared/pending.ts";
11
12
 
12
13
  type NoFields = NonNullable<unknown>;
13
14
  type Awaitable<T> = Promise<T> | T;
@@ -172,7 +173,17 @@ type RenderingConfig = SharedRouteConfig &
172
173
  }
173
174
  );
174
175
 
176
+ /** Synchronous: a promise would compare equal to any other promise. */
177
+ type LoaderDependencies = object & { readonly then?: never };
178
+
175
179
  export type DefineRouteConfig<Params = NoFields, Query = NoFields> = RenderingConfig & {
180
+ /**
181
+ * Page routes: the part of the validated query the loaders read. A client
182
+ * navigation that keeps the path and these deps (compared deeply) reuses
183
+ * the loaded page and only updates the URL and `query`. Loaders still
184
+ * receive the full query and always run on the server for documents.
185
+ */
186
+ loaderDeps?: (query: Query) => LoaderDependencies;
176
187
  remountDeps?: RemountDeps<Params, Query>;
177
188
  };
178
189
 
@@ -194,6 +205,7 @@ interface ErasedStaticParamsContext {
194
205
  }
195
206
 
196
207
  type RouteMetadata = RenderingConfig & {
208
+ loaderDeps?: (query: never) => LoaderDependencies;
197
209
  remountDeps?: (context: never) => readonly RemountDependency[];
198
210
  staticParams?: (context: ErasedStaticParamsContext) => Awaitable<readonly unknown[]>;
199
211
  };
@@ -633,6 +645,15 @@ type FileConfiguredRoute<
633
645
  >
634
646
  >;
635
647
 
648
+ /** `loaderDeps` describes a page response: layout configs cannot declare it. */
649
+ interface NoLoaderDepsOption {
650
+ loaderDeps?: FurinTypeError<"loaderDeps belongs to page routes: declare it on the page config">;
651
+ }
652
+
653
+ type KindConfigOption<Kind extends RouteKind> = [Kind] extends ["layout"]
654
+ ? NoLoaderDepsOption
655
+ : unknown;
656
+
636
657
  /** Keyed routes take their parent layout from the pages tree. */
637
658
  interface NoLayoutOption {
638
659
  layout?: FurinTypeError<"defineRoute(id) reads the parent layout from the pages tree: remove layout">;
@@ -658,6 +679,7 @@ interface ChainRuntime {
658
679
  metadata: RouteMetadata;
659
680
  notFoundComponent: NotFoundComponent | undefined;
660
681
  paramsSchema: FurinSchema | undefined;
682
+ pending: RoutePending | undefined;
661
683
  querySchema: FurinSchema | undefined;
662
684
  requestLoader: unknown;
663
685
  }
@@ -665,12 +687,13 @@ interface ChainRuntime {
665
687
  // Named stages keep compile errors readable, e.g. "Property 'staticParams'
666
688
  // does not exist on type 'SsrRouteStage<...>'".
667
689
 
668
- /** `.error()` / `.notFound()` keep the stage they are called on. */
669
- type BoundaryMethods = "error" | "notFound";
690
+ /** `.error()` / `.notFound()` / `.pending()` keep the stage they are called on. */
691
+ type BoundaryMethods = "error" | "notFound" | "pending";
670
692
 
671
693
  interface BoundaryStage<Stage> {
672
694
  error: (component: ErrorComponent) => Stage;
673
695
  notFound: (component: NotFoundComponent) => Stage;
696
+ pending: (component: PendingComponent, options?: PendingOptions) => Stage;
674
697
  }
675
698
 
676
699
  /** SSR routes render per request: `staticParams()` needs mode `ssg` or `isr`. */
@@ -712,6 +735,7 @@ type RouteTerminal<State extends ChainState> = {
712
735
  __type: "FURIN_ROUTE";
713
736
  errorComponent: ErrorComponent | undefined;
714
737
  notFoundComponent: NotFoundComponent | undefined;
738
+ pending: RoutePending | undefined;
715
739
  head:
716
740
  | Head<State["params"], State["query"], State["parentData"], State["data"], State["mode"]>
717
741
  | undefined;
@@ -723,6 +747,7 @@ type RouteTerminal<State extends ChainState> = {
723
747
  query: State["query"];
724
748
  search: State["search"];
725
749
  };
750
+ loaderDeps: RouteMetadata["loaderDeps"];
726
751
  remountDeps: RouteMetadata["remountDeps"];
727
752
  requestLoader: RequestLoader<State["params"], State["query"], State["requestData"]> | undefined;
728
753
  revalidate: number | undefined;
@@ -795,6 +820,7 @@ function terminalFields(runtime: ChainRuntime) {
795
820
  metadata,
796
821
  notFoundComponent,
797
822
  paramsSchema,
823
+ pending,
798
824
  querySchema,
799
825
  requestLoader,
800
826
  } = runtime;
@@ -802,8 +828,10 @@ function terminalFields(runtime: ChainRuntime) {
802
828
  __type: "FURIN_ROUTE" as const,
803
829
  errorComponent,
804
830
  notFoundComponent,
831
+ pending,
805
832
  mode: metadata.mode,
806
833
  revalidate: metadata.revalidate,
834
+ loaderDeps: metadata.loaderDeps,
807
835
  remountDeps: metadata.remountDeps,
808
836
  staticParams: metadata.staticParams,
809
837
  tags: metadata.tags,
@@ -834,6 +862,17 @@ class RouteChain<State extends ChainState> {
834
862
  return new RouteChain<State>({ ...this.runtime, notFoundComponent: component }) as this;
835
863
  }
836
864
 
865
+ /**
866
+ * TanStack style: renders in place of this route (in its parent's outlet)
867
+ * while a client navigation into it outlasts `options.ms`, as `pendingComponent` does.
868
+ */
869
+ pending(component: PendingComponent, options?: PendingOptions): this {
870
+ return new RouteChain<State>({
871
+ ...this.runtime,
872
+ pending: { component, minMs: options?.minMs, ms: options?.ms },
873
+ }) as this;
874
+ }
875
+
837
876
  requestLoader<Data extends RequestLoaderData>(
838
877
  requestLoader: RequestLoader<State["params"], State["query"], Data>
839
878
  ): StaticParamsClosedStage<WithState<State, { requestData: Data }>> {
@@ -913,6 +952,7 @@ function configure(options: RouteMetadata & ConfigOptions): unknown {
913
952
  metadata: options,
914
953
  notFoundComponent: undefined,
915
954
  paramsSchema: options.params,
955
+ pending: undefined,
916
956
  querySchema: options.query,
917
957
  requestLoader: undefined,
918
958
  });
@@ -924,22 +964,24 @@ function configure(options: RouteMetadata & ConfigOptions): unknown {
924
964
  */
925
965
  class UnconfiguredRootRoute {
926
966
  config<QuerySchema extends FurinSchema, Mode extends RenderingMode>(
927
- options: ResolvedConfig<EmptyContract, undefined, QuerySchema> & {
928
- mode: Mode;
929
- params?: undefined;
930
- query: QuerySchema;
931
- }
967
+ options: ResolvedConfig<EmptyContract, undefined, QuerySchema> &
968
+ NoLoaderDepsOption & {
969
+ mode: Mode;
970
+ params?: undefined;
971
+ query: QuerySchema;
972
+ }
932
973
  ): ConfiguredRoute<EmptyContract, NoFields, undefined, QuerySchema, { query: QuerySchema }, Mode>;
933
974
  config<
934
975
  ParamsSchema extends FurinSchema,
935
976
  QuerySchema extends FurinSchema,
936
977
  Mode extends RenderingMode,
937
978
  >(
938
- options: ResolvedConfig<EmptyContract, ParamsSchema, QuerySchema> & {
939
- mode: Mode;
940
- params: ParamsSchema;
941
- query: QuerySchema;
942
- }
979
+ options: ResolvedConfig<EmptyContract, ParamsSchema, QuerySchema> &
980
+ NoLoaderDepsOption & {
981
+ mode: Mode;
982
+ params: ParamsSchema;
983
+ query: QuerySchema;
984
+ }
943
985
  ): ConfiguredRoute<
944
986
  EmptyContract,
945
987
  NoFields,
@@ -949,11 +991,12 @@ class UnconfiguredRootRoute {
949
991
  Mode
950
992
  >;
951
993
  config<ParamsSchema extends FurinSchema, Mode extends RenderingMode>(
952
- options: ResolvedConfig<EmptyContract, ParamsSchema, undefined> & {
953
- mode: Mode;
954
- params: ParamsSchema;
955
- query?: undefined;
956
- }
994
+ options: ResolvedConfig<EmptyContract, ParamsSchema, undefined> &
995
+ NoLoaderDepsOption & {
996
+ mode: Mode;
997
+ params: ParamsSchema;
998
+ query?: undefined;
999
+ }
957
1000
  ): ConfiguredRoute<
958
1001
  EmptyContract,
959
1002
  NoFields,
@@ -963,11 +1006,12 @@ class UnconfiguredRootRoute {
963
1006
  Mode
964
1007
  >;
965
1008
  config<Mode extends RenderingMode>(
966
- options: ResolvedConfig<EmptyContract, undefined, undefined> & {
967
- mode: Mode;
968
- params?: undefined;
969
- query?: undefined;
970
- }
1009
+ options: ResolvedConfig<EmptyContract, undefined, undefined> &
1010
+ NoLoaderDepsOption & {
1011
+ mode: Mode;
1012
+ params?: undefined;
1013
+ query?: undefined;
1014
+ }
971
1015
  ): ConfiguredRoute<EmptyContract, NoFields, undefined, undefined, undefined, Mode>;
972
1016
  config(options: RouteMetadata & ConfigOptions): unknown {
973
1017
  return configure(options);
@@ -984,7 +1028,8 @@ class UnconfiguredRootRoute {
984
1028
  class UnconfiguredFileRoute<Entry> {
985
1029
  config<QuerySchema extends FurinSchema, Mode extends RenderingMode>(
986
1030
  options: ResolvedConfig<FileRouteContract<Entry>, undefined, QuerySchema> &
987
- NoLayoutOption & {
1031
+ NoLayoutOption &
1032
+ KindConfigOption<FileRouteKind<Entry>> & {
988
1033
  mode: Mode;
989
1034
  params?: undefined;
990
1035
  query: QuerySchema;
@@ -996,7 +1041,8 @@ class UnconfiguredFileRoute<Entry> {
996
1041
  Mode extends RenderingMode,
997
1042
  >(
998
1043
  options: ResolvedConfig<FileRouteContract<Entry>, ParamsSchema, QuerySchema> &
999
- NoLayoutOption & {
1044
+ NoLayoutOption &
1045
+ KindConfigOption<FileRouteKind<Entry>> & {
1000
1046
  mode: Mode;
1001
1047
  params: ParamsSchema;
1002
1048
  query: QuerySchema;
@@ -1010,7 +1056,8 @@ class UnconfiguredFileRoute<Entry> {
1010
1056
  >;
1011
1057
  config<ParamsSchema extends FurinSchema, Mode extends RenderingMode>(
1012
1058
  options: ResolvedConfig<FileRouteContract<Entry>, ParamsSchema, undefined> &
1013
- NoLayoutOption & {
1059
+ NoLayoutOption &
1060
+ KindConfigOption<FileRouteKind<Entry>> & {
1014
1061
  mode: Mode;
1015
1062
  params: ParamsSchema;
1016
1063
  query?: undefined;
@@ -1024,7 +1071,8 @@ class UnconfiguredFileRoute<Entry> {
1024
1071
  >;
1025
1072
  config<Mode extends RenderingMode>(
1026
1073
  options: ResolvedConfig<FileRouteContract<Entry>, undefined, undefined> &
1027
- NoLayoutOption & {
1074
+ NoLayoutOption &
1075
+ KindConfigOption<FileRouteKind<Entry>> & {
1028
1076
  mode: Mode;
1029
1077
  params?: undefined;
1030
1078
  query?: undefined;
@@ -9,12 +9,13 @@ const BUN_BUILTIN_FILTER = /^bun:/;
9
9
  const ANY_FILTER = /.*/;
10
10
 
11
11
  // Browser stub for elysia: the server stays out of the bundle, but `t` is
12
- // Elysia's browser-safe schema builder, so a schema shared with the client
13
- // is the same JSON Schema on both sides. `typeModule` is its resolved path.
12
+ // Elysia's browser-safe schema builder and the errors are its own, so a module
13
+ // shared with the client gets the same values on both sides. `typeModule` is
14
+ // the resolved `elysia/type`; `elysia/error` is resolved from the same install.
14
15
  const elysiaStub = (typeModule: string) => `\
15
16
  export * as t from ${JSON.stringify(typeModule)};
17
+ export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, InvalidCookie, NotFound, ParseError, ValidationError, problem, status, validationDetail } from ${JSON.stringify(Bun.resolveSync("elysia/error", dirname(typeModule)))};
16
18
  export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
17
- export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
18
19
  export default {};
19
20
  `;
20
21
  const ELYSIA_STUB_PREFIX = "elysia-stub:";
@@ -74,7 +75,7 @@ interface ClientStripPluginOptions {
74
75
  /**
75
76
  * Furin's browser-graph plugin, shared by the dev server (bunfig
76
77
  * `[serve.static] plugins`) and the production client build:
77
- * 1. Stubs `elysia` for the browser with its schema builder only.
78
+ * 1. Stubs `elysia` for the browser with its schema builder and errors only.
78
79
  * 2. Stubs `bun:*` builtins with an empty module (safety net — DCE removes
79
80
  * loader imports before they reach the browser bundle in practice).
80
81
  * 3. Strips server-only code (loader, query, params) from page files before
@@ -302,17 +302,24 @@ function checkParams(
302
302
  );
303
303
  }
304
304
 
305
+ const BOUNDARY_CONVENTIONS = {
306
+ error: "an error.tsx",
307
+ notFound: "a not-found.tsx",
308
+ pending: "a loading.tsx",
309
+ } as const;
310
+ const BOUNDARY_METHODS = ["error", "notFound", "pending"] as const;
311
+
305
312
  /** Next.js-style apps declare boundaries as files, TanStack-style ones on the route. */
306
313
  function checkBoundaryMethods(
307
314
  file: string,
308
315
  instance: RouteInstanceSpec,
309
316
  parsed: ParsedRoute
310
317
  ): RouteConfigIssue | undefined {
311
- const method = ["error", "notFound"].find((name) => parsed.route.methods.has(name));
318
+ const method = BOUNDARY_METHODS.find((name) => parsed.route.methods.has(name));
312
319
  if (instance.style !== "nextjs" || method === undefined) {
313
320
  return;
314
321
  }
315
- const convention = method === "error" ? "an error.tsx" : "a not-found.tsx";
322
+ const convention = BOUNDARY_CONVENTIONS[method];
316
323
  return issueAt(
317
324
  file,
318
325
  parsed,
@@ -33,11 +33,12 @@ export interface ManifestRoute {
33
33
  sourcePath: string;
34
34
  }
35
35
 
36
- /** A Next.js-style `error` / `not-found` pair declared in one directory. */
36
+ /** The Next.js-style `error` / `not-found` / `loading` files declared in one directory. */
37
37
  export interface ManifestBoundary {
38
38
  directory: string;
39
39
  errorPath: string | undefined;
40
40
  notFoundPath: string | undefined;
41
+ pendingPath: string | undefined;
41
42
  }
42
43
 
43
44
  export interface RouteManifest {
@@ -265,6 +266,8 @@ function addNextFile(
265
266
  state.boundary.errorPath ??= sourcePath;
266
267
  } else if (base === "not-found") {
267
268
  state.boundary.notFoundPath ??= sourcePath;
269
+ } else if (base === "loading") {
270
+ state.boundary.pendingPath ??= sourcePath;
268
271
  }
269
272
  }
270
273
 
@@ -273,7 +276,12 @@ function scanNext(pagesDir: string): StyleScan {
273
276
  const boundaries: ManifestBoundary[] = [];
274
277
  let rootPath: string | undefined;
275
278
  const walk = (directory: string, segments: Segment[]): void => {
276
- const boundary: ManifestBoundary = { directory, errorPath: undefined, notFoundPath: undefined };
279
+ const boundary: ManifestBoundary = {
280
+ directory,
281
+ errorPath: undefined,
282
+ notFoundPath: undefined,
283
+ pendingPath: undefined,
284
+ };
277
285
  const state: NextScanState = { boundary, candidates, rootPath };
278
286
  for (const entry of sortedEntries(directory)) {
279
287
  const sourcePath = child(directory, entry.name);
@@ -285,7 +293,7 @@ function scanNext(pagesDir: string): StyleScan {
285
293
  }
286
294
  }
287
295
  rootPath ??= state.rootPath;
288
- if (boundary.errorPath || boundary.notFoundPath) {
296
+ if (boundary.errorPath || boundary.notFoundPath || boundary.pendingPath) {
289
297
  boundaries.push(boundary);
290
298
  }
291
299
  };
@@ -129,8 +129,8 @@ export function routeSnapshotSourcePaths(instance: RouteInstanceSpec): string[]
129
129
  return [
130
130
  ...(existsSync(rootPath) ? [rootPath] : []),
131
131
  ...routes.map(({ sourcePath }) => sourcePath),
132
- ...boundaries.flatMap(({ errorPath, notFoundPath }) =>
133
- [errorPath, notFoundPath].filter((path) => path !== undefined)
132
+ ...boundaries.flatMap(({ errorPath, notFoundPath, pendingPath }) =>
133
+ [errorPath, notFoundPath, pendingPath].filter((path) => path !== undefined)
134
134
  ),
135
135
  ]
136
136
  .map((path) => resolve(path))
@@ -61,26 +61,28 @@ function memberAccessStart(source: string, object: Node, property: Node): number
61
61
  export interface StrippedCode {
62
62
  /** Config bindings the stripped `.config()` calls referenced. */
63
63
  configBindings: Set<string>;
64
- /** Names the retained remount policy references. */
64
+ /** Names the retained client policies reference. */
65
65
  retained: Set<string>;
66
66
  }
67
67
 
68
- /** Drops a server stage, keeping only a `.config()` call's remount policy. */
68
+ /** Drops a server stage, keeping only a `.config()` call's client policies. */
69
69
  function stripServerStage(
70
70
  module: ModuleTransform,
71
71
  stripped: StrippedCode,
72
72
  range: SourceRange,
73
- remount: Node | null
73
+ policies: Node[]
74
74
  ): void {
75
75
  const { removed, source } = module;
76
- if (remount) {
77
- // The policy as edited so far: an isomorphic chain in it is already selected.
78
- const policy = source.slice(remount.start, remount.end);
79
- for (const name of referencedNames(remount, removed)) {
80
- stripped.retained.add(name);
76
+ if (policies.length > 0) {
77
+ // The policies as edited so far: an isomorphic chain in them is already selected.
78
+ const retained = policies.map((policy) => source.slice(policy.start, policy.end));
79
+ for (const policy of policies) {
80
+ for (const name of referencedNames(policy, removed)) {
81
+ stripped.retained.add(name);
82
+ }
81
83
  }
82
84
  // overwrite, not update: update keeps the text earlier steps inserted in the range.
83
- replaceRange(module, range.start, range.end, `.config({ ${policy} })`);
85
+ replaceRange(module, range.start, range.end, `.config({ ${retained.join(", ")} })`);
84
86
  } else {
85
87
  removeRange(module, range.start, range.end);
86
88
  }
@@ -100,27 +102,48 @@ export function removeChainedServerCalls(
100
102
  if (isRemoved(call, module.removed)) {
101
103
  continue;
102
104
  }
103
- let remount: Node | null = null;
105
+ let policies: Node[] = [];
104
106
  if (property.name === "config" && Array.isArray(call.arguments)) {
105
107
  const config = unwrapped(call.arguments[0]);
106
108
  if (config?.type === "ObjectExpression" && Array.isArray(config.properties)) {
107
109
  collectConfigBindings(config, declarations, stripped.configBindings);
108
- remount = resolveRemountProperty(
109
- config,
110
- declarations,
111
- stripped.configBindings,
112
- new Set(),
113
- filename
114
- );
110
+ policies = clientPolicies(config, declarations, stripped.configBindings, filename);
115
111
  }
116
112
  }
117
113
  const accessStart = memberAccessStart(source.original, object, property);
118
- stripServerStage(module, stripped, { end: call.end, start: accessStart }, remount);
114
+ stripServerStage(module, stripped, { end: call.end, start: accessStart }, policies);
119
115
  transformed = true;
120
116
  }
121
117
  return transformed;
122
118
  }
123
119
 
120
+ /** The `.config()` properties the browser keeps: `loaderDeps`, then `remountDeps`. */
121
+ function clientPolicies(
122
+ config: Node,
123
+ declarations: Map<string, LocalDeclaration>,
124
+ configBindings: Set<string>,
125
+ filename: string
126
+ ): Node[] {
127
+ const resolve = (name: string) =>
128
+ resolveConfigProperty(config, name, declarations, configBindings, new Set());
129
+ // Loader deps behind an unresolvable spread only cost the in-place optimisation.
130
+ const loaderDeps = resolve("loaderDeps");
131
+ const remount = resolve("remountDeps");
132
+ if (remount === UNRESOLVED) {
133
+ throw new Error(
134
+ `[furin] ${filename}: route config spreads must resolve to local object literals; declare remountDeps after dynamic spreads.`
135
+ );
136
+ }
137
+ const policies: Node[] = [];
138
+ if (loaderDeps !== null && loaderDeps !== UNRESOLVED) {
139
+ policies.push(loaderDeps);
140
+ }
141
+ if (remount !== null) {
142
+ policies.push(remount);
143
+ }
144
+ return policies;
145
+ }
146
+
124
147
  function declaredInitializer(declaration: LocalDeclaration | undefined): Expression | null {
125
148
  return declaration?.type === "VariableDeclarator" ? unwrapped(declaration.init) : null;
126
149
  }
@@ -144,50 +167,52 @@ function collectConfigBindings(
144
167
  }
145
168
  }
146
169
 
147
- function resolveRemountProperty(
170
+ /** A spread the plugin cannot read may hide the property. */
171
+ const UNRESOLVED: unique symbol = Symbol("unresolved");
172
+
173
+ /** The config property `name` resolves to, in object spread order. */
174
+ function resolveConfigProperty(
148
175
  config: Node | null,
176
+ name: string,
149
177
  declarations: Map<string, LocalDeclaration>,
150
178
  configBindings: Set<string>,
151
- visiting: Set<string>,
152
- filename: string
153
- ): Node | null {
179
+ visiting: Set<string>
180
+ ): Node | null | typeof UNRESOLVED {
154
181
  if (config?.type === "Identifier" && !visiting.has(config.name)) {
155
182
  visiting.add(config.name);
156
183
  configBindings.add(config.name);
157
184
  const declaration = declarations.get(config.name);
158
- const result = resolveRemountProperty(
185
+ const result = resolveConfigProperty(
159
186
  declaredInitializer(declaration),
187
+ name,
160
188
  declarations,
161
189
  configBindings,
162
- visiting,
163
- filename
190
+ visiting
164
191
  );
165
192
  visiting.delete(config.name);
166
193
  return result;
167
194
  }
168
195
  if (config?.type !== "ObjectExpression" || !Array.isArray(config.properties)) {
169
- throw new Error(
170
- `[furin] ${filename}: route config spreads must resolve to local object literals; declare remountDeps after dynamic spreads.`
171
- );
196
+ return UNRESOLVED;
172
197
  }
173
198
  for (let index = config.properties.length - 1; index >= 0; index -= 1) {
174
199
  const entry = unwrapped(config.properties[index]);
175
200
  if (entry?.type === "SpreadElement") {
176
- const remount = resolveRemountProperty(
201
+ const property = resolveConfigProperty(
177
202
  unwrapped(entry.argument),
203
+ name,
178
204
  declarations,
179
205
  configBindings,
180
- visiting,
181
- filename
206
+ visiting
182
207
  );
183
- if (remount) {
184
- return remount;
208
+ if (property) {
209
+ return property;
185
210
  }
186
211
  } else if (entry?.type === "Property") {
187
212
  const key = unwrapped(entry.key);
188
213
  if (
189
- (key?.type === "Identifier" && entry.computed !== true && key.name === "remountDeps") ||
190
- (key?.type === "Literal" && key.value === "remountDeps")
214
+ (key?.type === "Identifier" && entry.computed !== true && key.name === name) ||
215
+ (key?.type === "Literal" && key.value === name)
191
216
  ) {
192
217
  return entry;
193
218
  }
@@ -139,7 +139,6 @@ export class DevGraph<Snapshot> {
139
139
  #eventSequence = 0;
140
140
  #revision = 0;
141
141
  #snapshot: Snapshot;
142
- #sourceGeneration = 0;
143
142
 
144
143
  constructor(initialSnapshot: Snapshot) {
145
144
  this.#snapshot = initialSnapshot;
@@ -373,10 +372,6 @@ export class DevGraph<Snapshot> {
373
372
  }
374
373
  }
375
374
 
376
- invalidateModules(): void {
377
- this.#sourceGeneration += 1;
378
- }
379
-
380
375
  sourceVersion(path: string): string {
381
376
  const modulePath = normalizeModulePath(path);
382
377
  const fingerprint = this.#sourceFingerprint(modulePath, new Set());
@@ -397,9 +392,9 @@ export class DevGraph<Snapshot> {
397
392
  let ownFingerprint: string;
398
393
  try {
399
394
  const stats = statSync(path, { bigint: true });
400
- ownFingerprint = `${stats.mtimeNs}:${stats.size}:${this.#sourceGeneration}`;
395
+ ownFingerprint = `${stats.mtimeNs}:${stats.size}`;
401
396
  } catch {
402
- ownFingerprint = `missing:${this.#sourceGeneration}`;
397
+ ownFingerprint = "missing";
403
398
  }
404
399
  const dependencies = [...(this.#dependencies.get(path) ?? [])]
405
400
  .toSorted((left, right) => left.localeCompare(right))
@@ -9,7 +9,7 @@ import { createInstrumentationPlugin } from "../devtools/instrumentation.ts";
9
9
  import { type FurinInstance, withInstance } from "../instance.ts";
10
10
  import type { ModeOptions, ModeRuntime } from "../mode.ts";
11
11
  import { bindRuntimeRoutes, createRouteRenderer } from "../router/dispatch.ts";
12
- import { developmentPagePorts, invalidateStampedRouteModules } from "../router/hmr.ts";
12
+ import { developmentPagePorts } from "../router/hmr.ts";
13
13
  import { buildRouteMatcher } from "../router/patterns.ts";
14
14
  import { createSearchRouteMetadata } from "../router/schemas.ts";
15
15
  import type { ResolvedRoute, RootLayout } from "../router/types.ts";
@@ -269,7 +269,6 @@ export async function createDevRuntime(
269
269
  const hmrEntry = (await import(join(furinDir, "index.html"))).default;
270
270
  const refreshDevelopmentRoutes = (changedSources: readonly string[]): Promise<void> =>
271
271
  withInstance(instance, async () => {
272
- invalidateStampedRouteModules();
273
272
  try {
274
273
  const previousSnapshot = currentSnapshot();
275
274
  const repaired = repairedDevelopmentRoutes(previousSnapshot, changedSources, graph);
@@ -103,6 +103,7 @@ export interface CompileContext {
103
103
  errorPath?: string;
104
104
  fromRoute?: true;
105
105
  notFoundPath?: string;
106
+ pendingPath?: string;
106
107
  }>;
107
108
  }
108
109
  >;
@@ -3,6 +3,7 @@ import type { HeadOptions, RenderingMode } from "../../client.ts";
3
3
  import type { ErrorComponent } from "../../shared/error.ts";
4
4
  import type { NotFoundComponent } from "../../shared/not-found.ts";
5
5
  import type { RemountDependency } from "../../shared/page-key.ts";
6
+ import type { RoutePending } from "../../shared/pending.ts";
6
7
 
7
8
  interface DefinedRouteTerminal {
8
9
  __type: "FURIN_ROUTE";
@@ -12,9 +13,11 @@ interface DefinedRouteTerminal {
12
13
  head?: (...args: never[]) => HeadOptions;
13
14
  layout?: (...args: never[]) => React.ReactNode;
14
15
  loader?: (...args: never[]) => unknown;
16
+ loaderDeps?: (query: never) => object;
15
17
  mode?: RenderingMode;
16
18
  notFoundComponent?: NotFoundComponent;
17
19
  page?: (...args: never[]) => React.ReactNode;
20
+ pending?: RoutePending;
18
21
  remountDeps?: (context: never) => readonly RemountDependency[];
19
22
  requestLoader?: (...args: never[]) => unknown;
20
23
  revalidate?: number;
@@ -55,6 +58,7 @@ export function adaptDefinedLayout(
55
58
  notFoundComponent: route.notFoundComponent,
56
59
  params: route.schemas?.params,
57
60
  ...(parent ? { parent } : {}),
61
+ pending: route.pending,
58
62
  query: route.schemas?.query,
59
63
  requestLoader: route.requestLoader as RuntimeRoute["requestLoader"],
60
64
  revalidate: route.revalidate,
@@ -73,6 +77,7 @@ export function adaptDefinedPage(route: DefinedRouteTerminal, parent: RuntimeRou
73
77
  __type: "FURIN_ROUTE",
74
78
  params: route.schemas?.params,
75
79
  parent,
80
+ loaderDeps: route.loaderDeps as RuntimeRoute["loaderDeps"],
76
81
  query: route.schemas?.query,
77
82
  remountDeps: route.remountDeps as RuntimeRoute["remountDeps"],
78
83
  requestLoader: route.requestLoader as RuntimeRoute["requestLoader"],
@@ -83,6 +88,7 @@ export function adaptDefinedPage(route: DefinedRouteTerminal, parent: RuntimeRou
83
88
  loader: route.loader as RuntimePage["loader"],
84
89
  mode: route.mode,
85
90
  notFoundComponent: route.notFoundComponent,
91
+ pending: route.pending,
86
92
  revalidate: route.revalidate,
87
93
  staticParams: route.staticParams as RuntimePage["staticParams"],
88
94
  tags: copyTags(route.tags),
@@ -427,8 +427,8 @@ export function routeDefinedBoundaries(
427
427
  ];
428
428
  const pagesDir = root.path.slice(0, root.path.lastIndexOf("/"));
429
429
  return entries.flatMap(({ depth, path, route }): SegmentBoundary[] => {
430
- const { errorComponent, notFoundComponent } = route;
431
- if (path === undefined || !(errorComponent || notFoundComponent)) {
430
+ const { errorComponent, notFoundComponent, pending } = route;
431
+ if (path === undefined || !(errorComponent || notFoundComponent || pending)) {
432
432
  return [];
433
433
  }
434
434
  return [
@@ -440,6 +440,7 @@ export function routeDefinedBoundaries(
440
440
  notFound: notFoundComponent,
441
441
  notFoundPath: notFoundComponent ? path : undefined,
442
442
  path: path === root.path ? pagesDir : path,
443
+ pendingPath: pending ? path : undefined,
443
444
  },
444
445
  ];
445
446
  });
@@ -526,6 +527,8 @@ async function collectSegmentBoundaries(
526
527
  notFound: notFoundEntry?.component,
527
528
  notFoundPath: notFoundEntry?.path,
528
529
  path: boundary.directory,
530
+ // Never imported on the server: only the client renders the pending screen.
531
+ pendingPath: boundary.pendingPath,
529
532
  })
530
533
  );
531
534
  cache.set(boundary.directory, loaded);
@@ -38,7 +38,7 @@ import {
38
38
  import type { CurrentRoute, PagePorts } from "./dispatch.ts";
39
39
  import { resolveMode, resolveRouteRevalidate } from "./patterns.ts";
40
40
  import { createRouteDataErrorResponse, isPprRoute } from "./plugin.ts";
41
- import { invalidateRouteModuleSourceVersions, routeModuleSourceVersion } from "./source-version.ts";
41
+ import { routeModuleSourceVersion } from "./source-version.ts";
42
42
  import type { ResolvedRoute, RootLayout } from "./types.ts";
43
43
 
44
44
  type RouteModuleImport = (specifier: string) => Promise<CompiledModule>;
@@ -152,10 +152,6 @@ export function importStampedRouteModule(
152
152
  return devGraph(undefined).importModule(path, stamp, resolveImport);
153
153
  }
154
154
 
155
- export function invalidateStampedRouteModules(): void {
156
- invalidateRouteModuleSourceVersions();
157
- }
158
-
159
155
  function isResolvedRouteModuleCandidate(
160
156
  layoutPath: string,
161
157
  imported: CompiledModule,