@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.
- package/dist/adapter/runtime-build.d.ts +1 -0
- package/dist/adapter/vercel.js +9 -6
- package/dist/build/index.js +74 -31
- package/dist/build/route-metadata.d.ts +1 -1
- package/dist/cli/index.js +74 -31
- package/dist/client/chunks/{client-rdxyrw11.js → client-hjqd5m3b.js} +1 -1
- package/dist/client/chunks/{client-p0jqzfvc.js → client-whph3y67.js} +1 -1
- package/dist/client/chunks/{client-a7spxfnn.js → client-xf7r768c.js} +13 -1
- package/dist/client/define-route.d.ts +12 -0
- package/dist/client/internal/runtime-types.d.ts +7 -0
- package/dist/client/link.js +200 -40
- package/dist/client/route-element.d.ts +5 -0
- package/dist/client/router/history.d.ts +6 -0
- package/dist/client/router/link-utils.d.ts +7 -0
- package/dist/client/router/navigation-controller.d.ts +20 -2
- package/dist/client/router/pending.d.ts +17 -0
- package/dist/client/router/search/index.d.ts +2 -0
- package/dist/client/router/search/index.js +7 -3
- package/dist/client/router/types.d.ts +21 -1
- package/dist/client.js +19 -4
- package/dist/define-route.d.ts +37 -10
- package/dist/furin.js +88 -29
- package/dist/plugin/client-plugin.d.ts +1 -1
- package/dist/plugin/index.js +36 -17
- package/dist/plugin/route-manifest.d.ts +2 -1
- package/dist/plugin/strip-server-stages.d.ts +1 -1
- package/dist/server/internal.d.ts +1 -0
- package/dist/server/internal.js +42 -15
- package/dist/server/router/defined-route.d.ts +3 -0
- package/dist/server/router/types.d.ts +7 -1
- package/dist/server/static-export.js +45 -15
- package/dist/shared/pending.d.ts +13 -0
- package/dist/shared/search-params.d.ts +1 -0
- package/package.json +1 -1
- package/src/adapter/runtime-build.ts +4 -0
- package/src/adapter/vercel.ts +21 -8
- package/src/build/hydrate.ts +11 -2
- package/src/build/preload-manifest.ts +3 -1
- package/src/build/route-metadata.ts +3 -2
- package/src/client/define-route.ts +23 -3
- package/src/client/internal/runtime-types.ts +7 -0
- package/src/client/link.tsx +26 -4
- package/src/client/route-element.tsx +41 -15
- package/src/client/router/context.ts +29 -8
- package/src/client/router/history.ts +10 -0
- package/src/client/router/link-utils.ts +23 -0
- package/src/client/router/navigation-controller.ts +239 -19
- package/src/client/router/pending.ts +58 -0
- package/src/client/router/provider.tsx +5 -2
- package/src/client/router/search/index.ts +7 -2
- package/src/client/router/types.ts +29 -3
- package/src/define-route.ts +74 -26
- package/src/plugin/client-plugin.ts +5 -4
- package/src/plugin/route-config.ts +9 -2
- package/src/plugin/route-manifest.ts +11 -3
- package/src/plugin/route-tree.ts +2 -2
- package/src/plugin/strip-server-stages.ts +60 -35
- package/src/server/internal.ts +1 -0
- package/src/server/router/defined-route.ts +6 -0
- package/src/server/router/discovery.ts +5 -2
- package/src/server/router/types.ts +7 -1
- package/src/shared/pending.ts +16 -0
- package/src/shared/search-params.ts +1 -1
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
} from "../../shared/elysia-contract.ts";
|
|
10
10
|
import type { ErrorComponent } from "../../shared/error.ts";
|
|
11
11
|
import type { NotFoundComponent } from "../../shared/not-found.ts";
|
|
12
|
+
import type { RoutePending } from "../../shared/pending.ts";
|
|
12
13
|
import type { SearchParamsInput, SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
13
14
|
import type { RuntimeData, RuntimeRoute } from "../internal/runtime-types.ts";
|
|
14
15
|
import type { FurinServerErrorPayload } from "../server-error.ts";
|
|
@@ -262,6 +263,8 @@ export interface LinkBaseProps<To extends RouteTo>
|
|
|
262
263
|
resetScroll?: boolean;
|
|
263
264
|
/** Typed search params for this route. Auto-completed from the route's query schema. */
|
|
264
265
|
search?: RouteSearch<To>;
|
|
266
|
+
/** See `TargetNavigationOptions.shallow`. */
|
|
267
|
+
shallow?: boolean;
|
|
265
268
|
to: To;
|
|
266
269
|
}
|
|
267
270
|
|
|
@@ -305,7 +308,19 @@ export interface NavigationOptions {
|
|
|
305
308
|
resetScroll?: boolean;
|
|
306
309
|
}
|
|
307
310
|
|
|
308
|
-
|
|
311
|
+
/** Options of navigations that name their destination's `search` (not raw hrefs). */
|
|
312
|
+
export interface TargetNavigationOptions extends NavigationOptions {
|
|
313
|
+
/**
|
|
314
|
+
* Same route and params: commit the new URL and search in place, without
|
|
315
|
+
* running loaders or setting `isNavigating`. Another destination navigates
|
|
316
|
+
* normally. Back/forward still load the page unless the route's
|
|
317
|
+
* `loaderDeps` exclude the changed params; reloads always do. Keeps the scroll
|
|
318
|
+
* position unless `resetScroll` is set.
|
|
319
|
+
*/
|
|
320
|
+
shallow?: boolean;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export type NavigateInput<To extends NavigationTo> = RouteTarget<To> & TargetNavigationOptions;
|
|
309
324
|
export type Navigate = <To extends NavigationTo>(next: NavigateInput<To>) => Promise<void>;
|
|
310
325
|
|
|
311
326
|
/** An href string validated like a structured destination (see `CheckedRouteTo`). */
|
|
@@ -350,8 +365,17 @@ export interface RouterContextValue {
|
|
|
350
365
|
*/
|
|
351
366
|
invalidatePrefetch: (path: string, type: "page" | "layout") => void;
|
|
352
367
|
isNavigating: boolean;
|
|
353
|
-
|
|
354
|
-
|
|
368
|
+
/** `search`: the destination's validated search, when the caller knows it (enables `loaderDeps` and `shallow`). */
|
|
369
|
+
navigate: (
|
|
370
|
+
href: string,
|
|
371
|
+
opts?: {
|
|
372
|
+
replace?: boolean;
|
|
373
|
+
resetScroll?: boolean;
|
|
374
|
+
search?: SearchParamsInput;
|
|
375
|
+
shallow?: boolean;
|
|
376
|
+
}
|
|
377
|
+
) => Promise<void>;
|
|
378
|
+
prefetch: (href: string, opts?: { search?: SearchParamsInput; staleTime?: number }) => void;
|
|
355
379
|
/**
|
|
356
380
|
* Re-fetches the current page in-place: busts the prefetch cache entry, re-runs
|
|
357
381
|
* loaders, and updates the rendered tree — without adding a history entry or
|
|
@@ -394,6 +418,8 @@ export interface ClientSegmentBoundary {
|
|
|
394
418
|
/** False when a pathless directory shares index 0 but does not own the root fallback. */
|
|
395
419
|
isRoot?: boolean;
|
|
396
420
|
notFound?: NotFoundComponent;
|
|
421
|
+
/** Shown inside the layout at `depth` while a navigation into this route loads. */
|
|
422
|
+
pending?: RoutePending;
|
|
397
423
|
}
|
|
398
424
|
|
|
399
425
|
export interface ClientRoute {
|
package/src/define-route.ts
CHANGED
|
@@ -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
|
-
|
|
929
|
-
|
|
930
|
-
|
|
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
|
-
|
|
940
|
-
|
|
941
|
-
|
|
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
|
-
|
|
954
|
-
|
|
955
|
-
|
|
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
|
-
|
|
968
|
-
|
|
969
|
-
|
|
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
|
|
13
|
-
//
|
|
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 =
|
|
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
|
|
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
|
-
/**
|
|
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 = {
|
|
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
|
};
|
package/src/plugin/route-tree.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
73
|
+
policies: Node[]
|
|
74
74
|
): void {
|
|
75
75
|
const { removed, source } = module;
|
|
76
|
-
if (
|
|
77
|
-
// The
|
|
78
|
-
const
|
|
79
|
-
for (const
|
|
80
|
-
|
|
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({ ${
|
|
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
|
|
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
|
-
|
|
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 },
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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 (
|
|
184
|
-
return
|
|
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 ===
|
|
190
|
-
(key?.type === "Literal" && key.value ===
|
|
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
|
}
|
package/src/server/internal.ts
CHANGED
|
@@ -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);
|