@lovrozagar/flare 0.1.2 → 0.2.0
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/README.md +42 -19
- package/package.json +8 -6
- package/src/broadcast/index.ts +1 -1
- package/src/broadcast/provider.tsx +2 -2
- package/src/caches/index.ts +26 -0
- package/src/components/await.tsx +36 -39
- package/src/components/dev-error-overlay.tsx +8 -9
- package/src/components/direction-script.tsx +2 -2
- package/src/components/locale-script.tsx +2 -2
- package/src/components/reset-css.tsx +1 -1
- package/src/components/ssr-context.tsx +7 -14
- package/src/components/theme-script.tsx +2 -2
- package/src/components/view-transition-css.tsx +1 -1
- package/src/defer/index.ts +22 -0
- package/src/direction/index.tsx +61 -36
- package/src/errors/index.ts +45 -11
- package/src/fonts/component.tsx +2 -1
- package/src/form/index.tsx +18 -12
- package/src/generators/index.ts +73 -30
- package/src/head-client/index.ts +7 -0
- package/src/history/index.ts +6 -0
- package/src/hydrate/index.tsx +90 -60
- package/src/hydration/index.ts +26 -6
- package/src/i18n/index.ts +11 -2
- package/src/image/index.tsx +7 -4
- package/src/intercept-outlet/index.tsx +6 -2
- package/src/lazy/index.tsx +50 -50
- package/src/link/index.tsx +97 -58
- package/src/loader-pipeline/index.ts +93 -35
- package/src/locale/cookie.ts +15 -0
- package/src/locale/index.tsx +24 -35
- package/src/locale.ts +1 -0
- package/src/middleware/builtins/api-proxy.ts +58 -4
- package/src/middleware/builtins/cdn-proxy.ts +24 -3
- package/src/middleware/builtins/i18n.ts +23 -25
- package/src/middleware/builtins/keepalive.ts +2 -3
- package/src/mount/index.ts +8 -1
- package/src/navigation/index.ts +575 -129
- package/src/navigation/types.ts +11 -1
- package/src/navigation-progress/index.tsx +17 -16
- package/src/ndjson-client/index.ts +42 -17
- package/src/ndjson-server/index.ts +78 -29
- package/src/outlet/index.tsx +192 -97
- package/src/outlet/types.ts +9 -1
- package/src/plugins/dev-cdn-cache.ts +18 -5
- package/src/plugins/dev-dashboard/client.tsx +130 -118
- package/src/plugins/dev-prerender.ts +6 -1
- package/src/plugins/dev-server.ts +12 -3
- package/src/plugins/image-plugin.ts +18 -4
- package/src/plugins/index.ts +10 -7
- package/src/plugins/prerender-plugin.ts +3 -3
- package/src/plugins/server-fn.ts +15 -20
- package/src/plugins/solid-jsx.d.ts +3 -3
- package/src/plugins/sx-ast/atomic.ts +5 -5
- package/src/plugins/sx-ast/index.ts +9 -0
- package/src/plugins/sx.d.ts +4 -5
- package/src/plugins/virtual.ts +11 -6
- package/src/prerender/index.ts +68 -32
- package/src/protocol.ts +65 -0
- package/src/query-client/index.tsx +73 -14
- package/src/rewrite/index.ts +10 -4
- package/src/route-builder/create-layout.ts +1 -1
- package/src/route-builder/create-root-layout.ts +1 -1
- package/src/route-builder/types.ts +5 -1
- package/src/router-primitives/types.ts +2 -0
- package/src/security/index.ts +41 -5
- package/src/server/index.ts +1 -2
- package/src/server-fn/get-input.ts +90 -0
- package/src/server-fn/http-error.ts +13 -0
- package/src/server-fn/index.ts +94 -70
- package/src/server-fn-query.ts +9 -17
- package/src/server-handler/etag.ts +4 -2
- package/src/server-handler/headers.ts +1 -2
- package/src/server-handler/index.ts +164 -56
- package/src/server-handler/types.ts +2 -0
- package/src/service-worker/template.ts +10 -42
- package/src/ssr/head-prefix.ts +2 -1
- package/src/ssr/hoist-head-markers.ts +25 -0
- package/src/ssr/index.tsx +109 -92
- package/src/state-parser/index.ts +38 -26
- package/src/styles/index.ts +89 -60
- package/src/testing/index.ts +8 -3
- package/src/theme/index.tsx +35 -32
- package/src/tracing/timing.ts +6 -1
- package/src/url/index.ts +9 -0
package/src/i18n/index.ts
CHANGED
|
@@ -209,6 +209,14 @@ export interface Translator<
|
|
|
209
209
|
) => unknown;
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
function neutralizeRichValues(values: Record<string, unknown>): Record<string, unknown> {
|
|
213
|
+
const out: Record<string, unknown> = {};
|
|
214
|
+
for (const [key, value] of Object.entries(values)) {
|
|
215
|
+
out[key] = typeof value === "string" ? value.replaceAll("[[", "[\u200B[").replaceAll("]]", "]\u200B]") : value;
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
|
|
212
220
|
export function createTranslator<T extends Record<string, Record<string, string>>>(
|
|
213
221
|
loaded: T,
|
|
214
222
|
locale?: string,
|
|
@@ -235,8 +243,9 @@ export function createTranslator<T extends Record<string, Record<string, string>
|
|
|
235
243
|
const template = flat[key];
|
|
236
244
|
if (template === undefined) return key;
|
|
237
245
|
|
|
238
|
-
/*
|
|
239
|
-
|
|
246
|
+
/* ICU first, but neutralize `[[` / `]]` in user values so they cannot
|
|
247
|
+
inject rich-component markers into a trusted template. */
|
|
248
|
+
const formatted = values ? formatMessage(template, neutralizeRichValues(values), locale) : template;
|
|
240
249
|
|
|
241
250
|
/* Then parse rich text components */
|
|
242
251
|
const parts = parseRichText(formatted, components);
|
package/src/image/index.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { createMemo, createSignal,
|
|
1
|
+
import { createMemo, createSignal, omit } from "solid-js";
|
|
2
|
+
import type { JSX } from "@solidjs/web";
|
|
2
3
|
import { warn } from "../logger.ts";
|
|
3
4
|
|
|
4
5
|
/* ── Static image data ── */
|
|
@@ -99,7 +100,7 @@ export interface StaticResponsiveImageProps extends FlareImgProps {
|
|
|
99
100
|
|
|
100
101
|
export type ImageProps = FillImageProps | FixedImageProps | ResponsiveImageProps | StaticResponsiveImageProps;
|
|
101
102
|
|
|
102
|
-
/* Flattened internal type for
|
|
103
|
+
/* Flattened internal type for omit — avoids TS intersection issues with Omit */
|
|
103
104
|
interface ImagePropsInternal {
|
|
104
105
|
alt: string;
|
|
105
106
|
aspectRatio?: number;
|
|
@@ -326,7 +327,9 @@ function mergeStyles(
|
|
|
326
327
|
/* ── Image component ── */
|
|
327
328
|
|
|
328
329
|
export function Image(props: ImageProps): JSX.Element {
|
|
329
|
-
const
|
|
330
|
+
const local = props as unknown as ImagePropsInternal;
|
|
331
|
+
const rest = omit(
|
|
332
|
+
local,
|
|
330
333
|
"alt",
|
|
331
334
|
"aspectRatio",
|
|
332
335
|
"blurDataURL",
|
|
@@ -345,7 +348,7 @@ export function Image(props: ImageProps): JSX.Element {
|
|
|
345
348
|
"style",
|
|
346
349
|
"width",
|
|
347
350
|
"widths",
|
|
348
|
-
|
|
351
|
+
);
|
|
349
352
|
|
|
350
353
|
const [loaded, setLoaded] = createSignal(false);
|
|
351
354
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Show, useContext } from "solid-js";
|
|
2
|
+
import type { JSX } from "@solidjs/web";
|
|
2
3
|
import { RouterContext } from "../outlet/index.tsx";
|
|
3
4
|
import type { InterceptedState } from "../outlet/types.ts";
|
|
4
5
|
|
|
@@ -11,8 +12,11 @@ export interface InterceptOutletProps {
|
|
|
11
12
|
/**
|
|
12
13
|
* Renders intercepted route content. SSR-safe — returns null when outside
|
|
13
14
|
* FlareProvider (root layout renders in NoHydration during SSR).
|
|
15
|
+
*
|
|
16
|
+
* Unkeyed on purpose: the function child receives an accessor. Reading it in
|
|
17
|
+
* JSX re-invokes `children` when intercept identity changes (overlay A → B).
|
|
14
18
|
*/
|
|
15
19
|
export function InterceptOutlet(props: InterceptOutletProps): JSX.Element {
|
|
16
20
|
const ctx = useContext(RouterContext);
|
|
17
|
-
return (<Show when={ctx?.intercepted()}>{(state) => props.children(state())}</Show>) as JSX.Element;
|
|
21
|
+
return (<Show when={ctx?.intercepted()}>{(state) => <>{props.children(state())}</>}</Show>) as JSX.Element;
|
|
18
22
|
}
|
package/src/lazy/index.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { JSX } from "
|
|
2
|
-
import {
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import { Dynamic, isServer } from "@solidjs/web";
|
|
3
|
+
import { type Component, createSignal, onSettled, Show, sharedConfig, untrack } from "solid-js";
|
|
3
4
|
import { retryImport } from "../internal.ts";
|
|
4
5
|
import { warn } from "../logger.ts";
|
|
6
|
+
import { GLOBAL_LAZY_LOADED, GLOBAL_LAZY_PENDING } from "../protocol.ts";
|
|
5
7
|
|
|
6
8
|
export interface LazyOptions<P extends Record<string, unknown>> {
|
|
7
9
|
loader: () => Promise<{ default: Component<P> }>;
|
|
@@ -14,8 +16,8 @@ export interface ClientLazyOptions<P extends Record<string, unknown>> {
|
|
|
14
16
|
pending?: Component<P>;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
const PENDING_KEY =
|
|
18
|
-
const LOADED_KEY =
|
|
19
|
+
const PENDING_KEY = GLOBAL_LAZY_PENDING;
|
|
20
|
+
const LOADED_KEY = GLOBAL_LAZY_LOADED;
|
|
19
21
|
|
|
20
22
|
function getGlobalPending(): Set<Promise<void>> {
|
|
21
23
|
const g = globalThis as Record<string, unknown>;
|
|
@@ -29,13 +31,9 @@ function getGlobalLoaded(): Set<Promise<void>> {
|
|
|
29
31
|
return g[LOADED_KEY] as Set<Promise<void>>;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
/**
|
|
33
|
-
* Throws during component init — ErrorBoundary catches it.
|
|
34
|
-
* Must be rendered via Show/conditional so the throw happens during
|
|
35
|
-
* the component's initial render phase (not in an effect).
|
|
36
|
-
*/
|
|
34
|
+
/** Throw during render so `<Errored>` can catch. Read is untracked — error is a snapshot. */
|
|
37
35
|
function ThrowError(props: { error: Error }): JSX.Element {
|
|
38
|
-
throw props.error;
|
|
36
|
+
throw untrack(() => props.error);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
export function lazy<P extends Record<string, unknown>>(options: LazyOptions<P>): Component<P> {
|
|
@@ -58,44 +56,42 @@ export function lazy<P extends Record<string, unknown>>(options: LazyOptions<P>)
|
|
|
58
56
|
getGlobalPending().add(loadPromise);
|
|
59
57
|
|
|
60
58
|
return ((props: P) => {
|
|
61
|
-
const isSSR = !!sharedConfig.
|
|
59
|
+
const isSSR = isServer || !!sharedConfig.hydrating;
|
|
62
60
|
|
|
63
61
|
/* Pre-known error at render time → throw from component body */
|
|
64
62
|
if (loadError) throw loadError;
|
|
65
63
|
|
|
66
|
-
|
|
64
|
+
/* Store `{ C }` — Solid 2 treats a function initial value as a derived signal. */
|
|
65
|
+
const [component, setComponent] = createSignal<{ C: Component<P> } | undefined>(
|
|
66
|
+
isSSR || !loaded ? undefined : { C: loaded },
|
|
67
|
+
);
|
|
67
68
|
const [error, setError] = createSignal<Error | undefined>();
|
|
68
69
|
|
|
69
70
|
if (isSSR || !loaded) {
|
|
70
|
-
|
|
71
|
+
onSettled(() => {
|
|
71
72
|
if (loadError) {
|
|
72
73
|
setError(loadError);
|
|
73
74
|
} else if (loaded) {
|
|
74
|
-
setComponent(
|
|
75
|
+
setComponent({ C: loaded });
|
|
75
76
|
} else {
|
|
76
77
|
loadPromise?.then(() => {
|
|
77
78
|
if (loadError) setError(loadError);
|
|
78
|
-
else
|
|
79
|
+
else if (loaded) setComponent({ C: loaded });
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
82
|
});
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
const PendingFallback = pending
|
|
85
|
-
? (() => {
|
|
86
|
-
const P = pending;
|
|
87
|
-
return (<P {...props} />) as JSX.Element;
|
|
88
|
-
})()
|
|
89
|
-
: null;
|
|
90
|
-
|
|
91
85
|
return (
|
|
92
|
-
<Show
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
86
|
+
<Show
|
|
87
|
+
fallback={
|
|
88
|
+
<Show fallback={pending ? <Dynamic component={pending} {...props} /> : null} when={component()}>
|
|
89
|
+
{(entry) => <Dynamic component={entry().C} {...props} />}
|
|
90
|
+
</Show>
|
|
91
|
+
}
|
|
92
|
+
when={error()}
|
|
93
|
+
>
|
|
94
|
+
{(err) => <ThrowError error={err() as Error} />}
|
|
99
95
|
</Show>
|
|
100
96
|
) as JSX.Element;
|
|
101
97
|
}) as Component<P>;
|
|
@@ -109,7 +105,7 @@ export function clientLazy<P extends Record<string, unknown>>(
|
|
|
109
105
|
let loadError: Error | undefined;
|
|
110
106
|
let loadPromise: Promise<void> | undefined;
|
|
111
107
|
|
|
112
|
-
if (eager) {
|
|
108
|
+
if (eager && !isServer) {
|
|
113
109
|
loadPromise = retryImport(loader)
|
|
114
110
|
.then((mod) => {
|
|
115
111
|
loaded = mod.default;
|
|
@@ -120,12 +116,15 @@ export function clientLazy<P extends Record<string, unknown>>(
|
|
|
120
116
|
}
|
|
121
117
|
|
|
122
118
|
return ((props: P & { pending?: Component<P> }) => {
|
|
123
|
-
const isSSR = !!sharedConfig.
|
|
119
|
+
const isSSR = isServer || !!sharedConfig.hydrating;
|
|
124
120
|
|
|
125
121
|
/* Pre-known error at render time → throw from component body */
|
|
126
122
|
if (loadError) throw loadError;
|
|
127
123
|
|
|
128
|
-
|
|
124
|
+
/* Store `{ C }` — Solid 2 treats a function initial value as a derived signal. */
|
|
125
|
+
const [component, setComponent] = createSignal<{ C: Component<P> } | undefined>(
|
|
126
|
+
isSSR || !loaded ? undefined : { C: loaded },
|
|
127
|
+
);
|
|
129
128
|
const [error, setError] = createSignal<Error | undefined>();
|
|
130
129
|
|
|
131
130
|
const startLoading = () => {
|
|
@@ -141,7 +140,7 @@ export function clientLazy<P extends Record<string, unknown>>(
|
|
|
141
140
|
loadPromise
|
|
142
141
|
.then(() => {
|
|
143
142
|
if (loadError) setError(loadError);
|
|
144
|
-
else
|
|
143
|
+
else if (loaded) setComponent({ C: loaded });
|
|
145
144
|
})
|
|
146
145
|
.catch((e: unknown) => {
|
|
147
146
|
warn("lazy", "chunk retry failed", e);
|
|
@@ -156,9 +155,9 @@ export function clientLazy<P extends Record<string, unknown>>(
|
|
|
156
155
|
/* Already loaded — render immediately */
|
|
157
156
|
} else {
|
|
158
157
|
/* SSR hydration or not-yet-loaded: kick off after mount */
|
|
159
|
-
|
|
158
|
+
onSettled(() => {
|
|
160
159
|
if (loaded) {
|
|
161
|
-
setComponent(
|
|
160
|
+
setComponent({ C: loaded });
|
|
162
161
|
} else if (loadError) {
|
|
163
162
|
setError(loadError);
|
|
164
163
|
} else {
|
|
@@ -167,22 +166,23 @@ export function clientLazy<P extends Record<string, unknown>>(
|
|
|
167
166
|
});
|
|
168
167
|
}
|
|
169
168
|
|
|
170
|
-
const PendingComp = props.pending ?? factoryPending;
|
|
171
|
-
const PendingFallback = PendingComp
|
|
172
|
-
? (() => {
|
|
173
|
-
const P = PendingComp;
|
|
174
|
-
return (<P {...(props as P)} />) as JSX.Element;
|
|
175
|
-
})()
|
|
176
|
-
: null;
|
|
177
|
-
|
|
178
169
|
return (
|
|
179
|
-
<Show
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
170
|
+
<Show
|
|
171
|
+
fallback={
|
|
172
|
+
<Show
|
|
173
|
+
fallback={
|
|
174
|
+
<Show when={props.pending ?? factoryPending}>
|
|
175
|
+
{(Comp) => <Dynamic component={Comp()} {...(props as P)} />}
|
|
176
|
+
</Show>
|
|
177
|
+
}
|
|
178
|
+
when={component()}
|
|
179
|
+
>
|
|
180
|
+
{(entry) => <Dynamic component={entry().C} {...(props as P)} />}
|
|
181
|
+
</Show>
|
|
182
|
+
}
|
|
183
|
+
when={error()}
|
|
184
|
+
>
|
|
185
|
+
{(err) => <ThrowError error={err() as Error} />}
|
|
186
186
|
</Show>
|
|
187
187
|
) as JSX.Element;
|
|
188
188
|
}) as Component<P & { pending?: Component<P> }>;
|
package/src/link/index.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { createMemo,
|
|
1
|
+
import { createEffect, createMemo, createSignal, omit, Show } from "solid-js";
|
|
2
|
+
import type { JSX } from "@solidjs/web";
|
|
2
3
|
import { applyRewriteOutput, isExternal, navigate, prefetch } from "../navigation/index.ts";
|
|
3
4
|
import { useRouterContext } from "../outlet/index.tsx";
|
|
4
5
|
import type { RouteParamsProps, RoutePaths, RouteSearchProps } from "../route-builder/register.ts";
|
|
@@ -39,7 +40,7 @@ export type ExternalLinkProps = FlareAnchorProps & {
|
|
|
39
40
|
|
|
40
41
|
export type LinkProps<TPath extends RoutePaths = RoutePaths> = InternalLinkProps<TPath> | ExternalLinkProps;
|
|
41
42
|
|
|
42
|
-
/* Flattened internal type for
|
|
43
|
+
/* Flattened internal type for omit — avoids TS intersection issues with Omit */
|
|
43
44
|
interface LinkPropsInternal {
|
|
44
45
|
activeClass?: string;
|
|
45
46
|
activeProps?: FlareAnchorProps;
|
|
@@ -83,7 +84,9 @@ function isDangerousHref(href: string): boolean {
|
|
|
83
84
|
export function Link<TPath extends RoutePaths>(props: LinkProps<TPath>): JSX.Element {
|
|
84
85
|
const ctx = useRouterContext();
|
|
85
86
|
|
|
86
|
-
const
|
|
87
|
+
const local = props as unknown as LinkPropsInternal;
|
|
88
|
+
const rest = omit(
|
|
89
|
+
local,
|
|
87
90
|
"activeClass",
|
|
88
91
|
"activeProps",
|
|
89
92
|
"children",
|
|
@@ -107,19 +110,24 @@ export function Link<TPath extends RoutePaths>(props: LinkProps<TPath>): JSX.Ele
|
|
|
107
110
|
"target",
|
|
108
111
|
"to",
|
|
109
112
|
"viewTransition",
|
|
110
|
-
|
|
113
|
+
);
|
|
111
114
|
|
|
112
|
-
const
|
|
113
|
-
if (local.href !== undefined)
|
|
114
|
-
|
|
115
|
-
return local.href;
|
|
116
|
-
}
|
|
117
|
-
const raw = buildUrl({
|
|
115
|
+
const internalHref = createMemo(() => {
|
|
116
|
+
if (local.href !== undefined) return undefined;
|
|
117
|
+
return buildUrl({
|
|
118
118
|
hash: local.hash,
|
|
119
119
|
params: local.params,
|
|
120
120
|
search: local.search,
|
|
121
121
|
to: local.to ?? "",
|
|
122
122
|
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const resolvedHref = createMemo(() => {
|
|
126
|
+
if (local.href !== undefined) {
|
|
127
|
+
if (isDangerousHref(local.href)) return "#";
|
|
128
|
+
return local.href;
|
|
129
|
+
}
|
|
130
|
+
const raw = internalHref() ?? "";
|
|
123
131
|
if (isDangerousHref(raw)) return "#";
|
|
124
132
|
return applyRewriteOutput(raw);
|
|
125
133
|
});
|
|
@@ -132,8 +140,8 @@ export function Link<TPath extends RoutePaths>(props: LinkProps<TPath>): JSX.Ele
|
|
|
132
140
|
|
|
133
141
|
const routePrefetch = createMemo(() => {
|
|
134
142
|
if (local.href !== undefined) return undefined;
|
|
135
|
-
const h =
|
|
136
|
-
if (isExternal(h)) return undefined;
|
|
143
|
+
const h = internalHref();
|
|
144
|
+
if (!h || isExternal(h)) return undefined;
|
|
137
145
|
try {
|
|
138
146
|
const url = new URL(h, typeof window !== "undefined" ? window.location.href : "http://localhost/");
|
|
139
147
|
const match = matchRoute(ctx.routeTree, url.pathname, ctx.caseSensitive, toLocaleMatch(ctx.localeConfig));
|
|
@@ -226,15 +234,27 @@ export function Link<TPath extends RoutePaths>(props: LinkProps<TPath>): JSX.Ele
|
|
|
226
234
|
return;
|
|
227
235
|
}
|
|
228
236
|
|
|
237
|
+
let to = local.to ?? "";
|
|
238
|
+
let hash = local.hash;
|
|
239
|
+
if (!local.to && local.href !== undefined) {
|
|
240
|
+
try {
|
|
241
|
+
const url = new URL(h, typeof window !== "undefined" ? window.location.href : "http://localhost/");
|
|
242
|
+
to = url.pathname + url.search;
|
|
243
|
+
hash = hash ?? (url.hash || undefined);
|
|
244
|
+
} catch {
|
|
245
|
+
to = h;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
229
249
|
navigate({
|
|
230
|
-
hash
|
|
250
|
+
hash,
|
|
231
251
|
params: local.params,
|
|
232
252
|
replace: local.replace,
|
|
233
253
|
revalidate: local.revalidate,
|
|
234
254
|
scroll: local.scroll,
|
|
235
255
|
search: local.search,
|
|
236
256
|
shallow: local.shallow,
|
|
237
|
-
to
|
|
257
|
+
to,
|
|
238
258
|
viewTransition: local.viewTransition,
|
|
239
259
|
});
|
|
240
260
|
}
|
|
@@ -244,8 +264,14 @@ export function Link<TPath extends RoutePaths>(props: LinkProps<TPath>): JSX.Ele
|
|
|
244
264
|
if (local.href !== undefined) return;
|
|
245
265
|
const h = resolvedHref();
|
|
246
266
|
if (isExternal(h)) return;
|
|
247
|
-
/* params + search already resolved into h by resolvedHref() — passing them again would double-apply
|
|
248
|
-
|
|
267
|
+
/* params + search already resolved into h by resolvedHref() — passing them again would double-apply.
|
|
268
|
+
* Intent prefetches that URL's NDJSON shell. Viewport/render only warm JS once per route. */
|
|
269
|
+
const strategy = effectivePrefetch();
|
|
270
|
+
if (strategy === "viewport" || strategy === "render") {
|
|
271
|
+
prefetch({ modulesOnly: true, to: h });
|
|
272
|
+
} else {
|
|
273
|
+
prefetch({ to: h });
|
|
274
|
+
}
|
|
249
275
|
}
|
|
250
276
|
|
|
251
277
|
function handleIntent(): void {
|
|
@@ -288,49 +314,62 @@ export function Link<TPath extends RoutePaths>(props: LinkProps<TPath>): JSX.Ele
|
|
|
288
314
|
};
|
|
289
315
|
}
|
|
290
316
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
el
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
317
|
+
/* Capture the element; attach listeners in createEffect so cleanup is owned. */
|
|
318
|
+
const [anchor, setAnchor] = createSignal<HTMLAnchorElement | undefined>();
|
|
319
|
+
|
|
320
|
+
createEffect(
|
|
321
|
+
() => {
|
|
322
|
+
const el = anchor();
|
|
323
|
+
const strategy = effectivePrefetch();
|
|
324
|
+
const href = resolvedHref();
|
|
325
|
+
return {
|
|
326
|
+
disabled: !!local.disabled,
|
|
327
|
+
el,
|
|
328
|
+
external: isExternal(href),
|
|
329
|
+
hrefOnly: local.href !== undefined,
|
|
330
|
+
strategy,
|
|
331
|
+
};
|
|
332
|
+
},
|
|
333
|
+
({ disabled, el, external, hrefOnly, strategy }) => {
|
|
334
|
+
if (!el || disabled || hrefOnly || external) return;
|
|
335
|
+
|
|
336
|
+
if (strategy === "intent") {
|
|
337
|
+
el.addEventListener("focus", handleIntent);
|
|
338
|
+
el.addEventListener("touchstart", handleIntent, { passive: true });
|
|
339
|
+
return () => {
|
|
340
|
+
el.removeEventListener("focus", handleIntent);
|
|
341
|
+
el.removeEventListener("touchstart", handleIntent);
|
|
342
|
+
};
|
|
343
|
+
}
|
|
305
344
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
345
|
+
if (strategy === "viewport") {
|
|
346
|
+
let observer: IntersectionObserver | undefined;
|
|
347
|
+
const cancel = scheduleAfterLoad(() => {
|
|
348
|
+
if (typeof IntersectionObserver === "undefined") return;
|
|
349
|
+
observer = new IntersectionObserver(
|
|
350
|
+
(entries) => {
|
|
351
|
+
for (const entry of entries) {
|
|
352
|
+
if (entry.isIntersecting) {
|
|
353
|
+
triggerPrefetch();
|
|
354
|
+
observer?.unobserve(entry.target);
|
|
355
|
+
}
|
|
316
356
|
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
}
|
|
357
|
+
},
|
|
358
|
+
{ threshold: 0 },
|
|
359
|
+
);
|
|
360
|
+
observer.observe(el);
|
|
361
|
+
});
|
|
362
|
+
return () => {
|
|
363
|
+
cancel();
|
|
364
|
+
observer?.disconnect();
|
|
365
|
+
};
|
|
366
|
+
}
|
|
328
367
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
|
|
368
|
+
if (strategy === "render") {
|
|
369
|
+
return scheduleAfterLoad(() => triggerPrefetch());
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
);
|
|
334
373
|
|
|
335
374
|
function disabledStyle(): JSX.CSSProperties | string {
|
|
336
375
|
if (typeof local.style === "string") return `cursor:not-allowed;${local.style}`;
|
|
@@ -341,7 +380,7 @@ export function Link<TPath extends RoutePaths>(props: LinkProps<TPath>): JSX.Ele
|
|
|
341
380
|
return (
|
|
342
381
|
<Show
|
|
343
382
|
fallback={
|
|
344
|
-
<span {...rest} aria-disabled="true" class={classes()} style={disabledStyle()}
|
|
383
|
+
<span {...rest} aria-disabled="true" class={classes()} style={disabledStyle()} tabindex={-1}>
|
|
345
384
|
{local.children}
|
|
346
385
|
</span>
|
|
347
386
|
}
|
|
@@ -356,7 +395,7 @@ export function Link<TPath extends RoutePaths>(props: LinkProps<TPath>): JSX.Ele
|
|
|
356
395
|
href={resolvedHref()}
|
|
357
396
|
onClick={handleClick}
|
|
358
397
|
onMouseEnter={handleIntent}
|
|
359
|
-
ref={
|
|
398
|
+
ref={setAnchor}
|
|
360
399
|
rel={effectiveRel()}
|
|
361
400
|
target={local.target}
|
|
362
401
|
>
|