@teyik0/furin 0.8.0-alpha.0 → 0.9.0-alpha.1
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 +37 -0
- package/dist/adapter/bun/app.d.ts +1 -0
- package/dist/adapter/bun.d.ts +3 -1
- package/dist/adapter/runtime-build.d.ts +8 -5
- package/dist/adapter/vercel.js +8 -8
- package/dist/build/client.d.ts +2 -2
- package/dist/build/discover-mounts-process.d.ts +1 -1
- package/dist/build/discover-pages-process.d.ts +1 -0
- package/dist/build/discover-pages.d.ts +11 -0
- package/dist/build/discovery-module.d.ts +3 -0
- package/dist/build/discovery-plugins.d.ts +34 -0
- package/dist/build/elysia-aot.d.ts +1 -1
- package/dist/build/entry-template.ts +6 -1
- package/dist/build/hydrate.d.ts +3 -2
- package/dist/build/index.js +7688 -8458
- package/dist/build/preload-manifest.d.ts +2 -2
- package/dist/build/route-metadata.d.ts +31 -0
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/shared.d.ts +2 -2
- package/dist/build/types.d.ts +11 -0
- package/dist/cli/dev-worker.d.ts +1 -0
- package/dist/cli/dev-worker.ts +129 -0
- package/dist/cli/dev.d.ts +1 -0
- package/dist/cli/index.js +7814 -8473
- package/dist/client/browser-events-runtime.d.ts +2 -2
- package/dist/client/browser-events.d.ts +2 -0
- package/dist/client/chunks/{client-brdfd773.js → client-rjhxgt64.js} +187 -4
- package/dist/client/dev-error-overlay.ts +18 -1
- package/dist/client/link.js +127 -170
- package/dist/client/query-store.d.ts +5 -0
- package/dist/client/router/navigation-controller.d.ts +2 -0
- package/dist/client/router/use-fetch-interception.d.ts +1 -1
- package/dist/client/router/use-sync-stream.d.ts +1 -1
- package/dist/client/{router/sync-catch-up.d.ts → sync-catch-up.d.ts} +5 -3
- package/dist/client/sync-client.d.ts +74 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +533 -145
- package/dist/config.d.ts +6 -1
- package/dist/config.js +3 -1
- package/dist/define-route.d.ts +3 -3
- package/dist/furin.d.ts +2 -1
- package/dist/furin.js +1168 -393
- package/dist/plugin/index.js +5 -5
- package/dist/plugin/route-registry.d.ts +22 -2
- package/dist/rsc/build/index.d.ts +4 -3
- package/dist/server/dev/server-only-module.d.ts +5 -0
- package/dist/server/internal.js +241 -129
- package/dist/server/logging/ingest-plugin.d.ts +1 -2
- package/dist/server/production-server.js +36 -33
- package/dist/server/render/index.d.ts +0 -1
- package/dist/server/render/index.ts +0 -1
- package/dist/server/render/shell.d.ts +1 -13
- package/dist/server/render/shell.ts +1 -90
- package/dist/server/server-entry.d.ts +5 -0
- package/dist/server/server-entry.js +36 -0
- package/dist/server/static-export.js +241 -129
- package/dist/server/sync/adapter.d.ts +4 -3
- package/dist/server/sync/config.d.ts +7 -0
- package/dist/server/sync/connection.d.ts +13 -0
- package/dist/server/sync/drizzle/index.js +5 -4
- package/dist/server/sync/index.d.ts +3 -0
- package/dist/server/sync/index.js +1361 -243
- package/dist/server/sync/invalidate-sync.d.ts +6 -2
- package/dist/server/sync/local-client.d.ts +9 -0
- package/dist/server/sync/postgres/index.d.ts +1 -1
- package/dist/server/sync/postgres/index.js +2 -2
- package/dist/server/sync/prisma/index.js +2 -2
- package/dist/server/sync/redis/index.d.ts +1 -1
- package/dist/server/sync/redis/index.js +4 -3
- package/dist/server/sync/redis/scripts.d.ts +1 -1
- package/dist/server/sync/runtime.d.ts +3 -0
- package/dist/server/sync/sqlite/index.d.ts +1 -1
- package/dist/server/sync/sqlite/index.js +3 -2
- package/dist/shared/browser-events.d.ts +4 -0
- package/dist/shared/not-found.d.ts +1 -1
- package/dist/sync-client.d.ts +3 -0
- package/dist/sync-client.js +1600 -0
- package/package.json +14 -9
- package/src/adapter/README.md +7 -0
- package/src/adapter/build.ts +34 -33
- package/src/adapter/bun/app.ts +5 -0
- package/src/adapter/bun/server.ts +2 -2
- package/src/adapter/bun.ts +18 -2
- package/src/adapter/furin-app.d.ts +1 -0
- package/src/adapter/package.ts +1 -0
- package/src/adapter/runtime-build.ts +18 -12
- package/src/adapter/static.ts +17 -13
- package/src/build/client.ts +7 -5
- package/src/build/discover-mounts-process.ts +5 -1
- package/src/build/discover-pages-process.ts +151 -0
- package/src/build/discover-pages.ts +69 -0
- package/src/build/discovery-module.ts +70 -0
- package/src/build/discovery-plugins.ts +101 -0
- package/src/build/elysia-aot-worker.ts +9 -8
- package/src/build/elysia-aot.ts +110 -75
- package/src/build/entry-template.ts +6 -1
- package/src/build/hydrate.ts +11 -8
- package/src/build/index.ts +6 -50
- package/src/build/preload-manifest.ts +3 -3
- package/src/build/route-metadata.ts +90 -0
- package/src/build/route-types.ts +1 -1
- package/src/build/shared.ts +6 -8
- package/src/build/types.ts +9 -0
- package/src/cli/config.ts +4 -0
- package/src/cli/dev-worker.ts +129 -0
- package/src/cli/dev.ts +106 -0
- package/src/cli/index.ts +24 -1
- package/src/client/browser-events-runtime.ts +97 -23
- package/src/client/browser-events.ts +8 -0
- package/src/client/dev-error-overlay.ts +18 -1
- package/src/client/link.tsx +21 -22
- package/src/client/query-store.ts +54 -3
- package/src/client/router/context.ts +8 -7
- package/src/client/router/navigation-controller.ts +45 -12
- package/src/client/router/provider.tsx +11 -2
- package/src/client/router/use-fetch-interception.ts +1 -1
- package/src/client/router/use-sync-stream.ts +96 -44
- package/src/client/{router/sync-catch-up.ts → sync-catch-up.ts} +28 -12
- package/src/client/sync-client.ts +528 -0
- package/src/client/sync.ts +11 -4
- package/src/client.ts +10 -0
- package/src/config.ts +17 -10
- package/src/furin.ts +5 -0
- package/src/plugin/route-registry.ts +53 -7
- package/src/rsc/build/index.ts +6 -3
- package/src/server/browser-events/plugin.ts +79 -25
- package/src/server/dev/rewrite-module-specifiers.ts +2 -1
- package/src/server/dev/server-only-module.ts +23 -0
- package/src/server/dev/symbolicate.ts +4 -3
- package/src/server/dev-page-imports.ts +3 -1
- package/src/server/dev-page-plugin.ts +18 -1
- package/src/server/logging/ingest-plugin.ts +3 -9
- package/src/server/render/index.ts +0 -1
- package/src/server/render/shell.ts +1 -90
- package/src/server/server-entry.ts +39 -0
- package/src/server/sync/adapter.ts +7 -3
- package/src/server/sync/config.ts +12 -6
- package/src/server/sync/connection.ts +71 -0
- package/src/server/sync/index.ts +3 -0
- package/src/server/sync/invalidate-sync.ts +30 -5
- package/src/server/sync/local-client.ts +84 -0
- package/src/server/sync/plugin.ts +27 -20
- package/src/server/sync/postgres/index.ts +9 -2
- package/src/server/sync/redis/index.ts +5 -1
- package/src/server/sync/redis/scripts.ts +1 -1
- package/src/server/sync/runtime.ts +56 -18
- package/src/server/sync/sqlite/index.ts +6 -2
- package/src/server/sync/stream.ts +17 -5
- package/src/shared/browser-events.ts +1 -1
- package/src/shared/not-found.ts +1 -1
- package/src/sync-client.ts +14 -0
- package/dist/server/logger.d.ts +0 -10
- package/src/server/logger.ts +0 -34
package/src/cli/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { buildApp, generateRouteTypes } from "../build/index.ts";
|
|
|
6
6
|
import { BUILD_TARGETS, type FurinTarget } from "../config.ts";
|
|
7
7
|
import { normalizePrefix } from "../server/instance.ts";
|
|
8
8
|
import { loadCliConfig } from "./config.ts";
|
|
9
|
+
import { runDevelopment } from "./dev.ts";
|
|
9
10
|
import { normalizeStaticPreviewBasePath, startStaticPreview } from "./preview.ts";
|
|
10
11
|
|
|
11
12
|
const argv = process.argv.slice(2);
|
|
@@ -71,7 +72,9 @@ function extractCompileFlag(args: string[]): {
|
|
|
71
72
|
return { compileFlag, parseableArgs };
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
if (command === "
|
|
75
|
+
if (command === "dev") {
|
|
76
|
+
await runDevelopment(process.cwd(), argv.slice(1));
|
|
77
|
+
} else if (command === "preview") {
|
|
75
78
|
let rawValues: ReturnType<typeof parseArgs>["values"];
|
|
76
79
|
try {
|
|
77
80
|
rawValues = parseArgs({
|
|
@@ -120,6 +123,8 @@ if (command === "preview") {
|
|
|
120
123
|
options: {
|
|
121
124
|
analyze: { type: "boolean" },
|
|
122
125
|
config: { type: "string" },
|
|
126
|
+
external: { type: "string", multiple: true },
|
|
127
|
+
output: { type: "string" },
|
|
123
128
|
pagesDir: { type: "string" },
|
|
124
129
|
prefix: { type: "string" },
|
|
125
130
|
target: { type: "string" },
|
|
@@ -132,6 +137,8 @@ if (command === "preview") {
|
|
|
132
137
|
|
|
133
138
|
const values = rawValues as {
|
|
134
139
|
analyze?: boolean;
|
|
140
|
+
external?: string[];
|
|
141
|
+
output?: string;
|
|
135
142
|
target?: string;
|
|
136
143
|
pagesDir?: string;
|
|
137
144
|
prefix?: string;
|
|
@@ -166,10 +173,22 @@ if (command === "preview") {
|
|
|
166
173
|
const targets = Array.isArray(target) || target === "all" ? target : [target];
|
|
167
174
|
const targetLabel = targets === "all" ? targets : targets.map(targetName).join(", ");
|
|
168
175
|
|
|
176
|
+
const output = values.output ?? config.bun?.output;
|
|
177
|
+
if (output !== undefined && output !== "app" && output !== "server") {
|
|
178
|
+
bail(`Invalid Bun output "${output}". Valid: app, server`);
|
|
179
|
+
}
|
|
180
|
+
if (values.output !== undefined && targetLabel !== "bun") {
|
|
181
|
+
bail("--output requires --target bun");
|
|
182
|
+
}
|
|
183
|
+
if (values.external !== undefined && targetLabel !== "bun") {
|
|
184
|
+
bail("--external requires --target bun");
|
|
185
|
+
}
|
|
186
|
+
|
|
169
187
|
log(`Building Furin for ${targetLabel}…`);
|
|
170
188
|
|
|
171
189
|
const result = await buildApp({
|
|
172
190
|
analyze: values.analyze,
|
|
191
|
+
bun: output === undefined ? undefined : { output },
|
|
173
192
|
// --pagesDir/--prefix build a single explicit app; otherwise fall back to
|
|
174
193
|
// the config's `apps` list (then to server.ts scanning inside buildApp).
|
|
175
194
|
// normalizePrefix here so a bad --prefix fails before buildApp starts
|
|
@@ -188,6 +207,7 @@ if (command === "preview") {
|
|
|
188
207
|
optimizeImports: config.optimizeImports,
|
|
189
208
|
pagesDir: undefined,
|
|
190
209
|
plugins: config.plugins,
|
|
210
|
+
serverExternalPackages: values.external,
|
|
191
211
|
preload: config.preload,
|
|
192
212
|
reactCompiler: config.reactCompiler,
|
|
193
213
|
rootDir: config.rootDir,
|
|
@@ -230,6 +250,7 @@ if (command === "preview") {
|
|
|
230
250
|
`Furin CLI
|
|
231
251
|
|
|
232
252
|
USAGE
|
|
253
|
+
furin dev [--web | --desktop] [--port number]
|
|
233
254
|
furin build [options]
|
|
234
255
|
furin preview [options]
|
|
235
256
|
furin typegen [options]
|
|
@@ -241,6 +262,8 @@ BUILD OPTIONS
|
|
|
241
262
|
--prefix Mount prefix for the built app (e.g. /admin) — pairs with --pagesDir
|
|
242
263
|
--config Config file path
|
|
243
264
|
--compile server | embed Compile to binary: "server" keeps client on disk, "embed" is self-contained
|
|
265
|
+
--output app | server Bun only: inert app.js or listening server.js (default: server)
|
|
266
|
+
--external Bun only: package to exclude from server/RSC bundles (repeatable)
|
|
244
267
|
--analyze Write complete bundle metafiles to .furin/build/analysis
|
|
245
268
|
|
|
246
269
|
TYPEGEN OPTIONS
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { BrowserEventChannel, BrowserEventEnvelope } from "../shared/browser-events.ts";
|
|
2
2
|
|
|
3
3
|
type BrowserEventListener = (event: BrowserEventEnvelope) => void;
|
|
4
|
-
type BrowserEventConnectionStatus = "connected" | "connecting" | "reconnecting";
|
|
4
|
+
type BrowserEventConnectionStatus = "connected" | "connecting" | "reconnecting" | "unauthorized";
|
|
5
5
|
|
|
6
6
|
interface BrowserEventRuntime {
|
|
7
|
+
setSyncAuthentication: (authorized: boolean) => void;
|
|
7
8
|
subscribe: (
|
|
8
9
|
channel: BrowserEventChannel,
|
|
9
10
|
listener: BrowserEventListener
|
|
@@ -18,13 +19,15 @@ interface BrowserEventCandidate {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
interface SyncEventCandidate {
|
|
22
|
+
context?: unknown;
|
|
21
23
|
cursor?: unknown;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export function installBrowserEventsRuntime(
|
|
25
27
|
browser: Window,
|
|
26
28
|
moduleUrlValue: string,
|
|
27
|
-
transport?: "sse"
|
|
29
|
+
transport?: "sse",
|
|
30
|
+
sync?: boolean
|
|
28
31
|
): void {
|
|
29
32
|
const runtimeKey = Symbol.for("furin.browser-events.runtime");
|
|
30
33
|
const runtimeWindow = browser as Window &
|
|
@@ -53,7 +56,8 @@ export function installBrowserEventsRuntime(
|
|
|
53
56
|
return false;
|
|
54
57
|
}
|
|
55
58
|
if (candidate.channel === "sync") {
|
|
56
|
-
|
|
59
|
+
const data = candidate.data as SyncEventCandidate;
|
|
60
|
+
return typeof data.cursor === "string" || data.context === "changed";
|
|
57
61
|
}
|
|
58
62
|
return candidate.channel === "diagnostic" || candidate.channel === "devtools";
|
|
59
63
|
};
|
|
@@ -92,6 +96,9 @@ export function installBrowserEventsRuntime(
|
|
|
92
96
|
let eventSource: EventSource | undefined;
|
|
93
97
|
let status: BrowserEventConnectionStatus = "connecting";
|
|
94
98
|
let suspended = false;
|
|
99
|
+
let authPaused = false;
|
|
100
|
+
let authorized = !sync;
|
|
101
|
+
let authenticating: AbortController | undefined;
|
|
95
102
|
|
|
96
103
|
const updateStatus = (next: BrowserEventConnectionStatus): void => {
|
|
97
104
|
if (status === next) {
|
|
@@ -136,7 +143,68 @@ export function installBrowserEventsRuntime(
|
|
|
136
143
|
}
|
|
137
144
|
};
|
|
138
145
|
|
|
146
|
+
const retry = (): void => {
|
|
147
|
+
if (suspended || authPaused || reconnectTimer !== undefined) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
updateStatus("reconnecting");
|
|
151
|
+
const baseDelay = Math.min(250 * 2 ** reconnectAttempt, maxReconnectDelayMs);
|
|
152
|
+
const delay =
|
|
153
|
+
transport === "sse"
|
|
154
|
+
? baseDelay
|
|
155
|
+
: Math.min(Math.round(baseDelay * (0.8 + Math.random() * 0.4)), maxReconnectDelayMs);
|
|
156
|
+
reconnectAttempt += 1;
|
|
157
|
+
reconnectTimer = browser.setTimeout(() => {
|
|
158
|
+
reconnectTimer = undefined;
|
|
159
|
+
connect();
|
|
160
|
+
}, delay);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const authenticate = async (): Promise<void> => {
|
|
164
|
+
if (authenticating) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const current = new AbortController();
|
|
168
|
+
authenticating = current;
|
|
169
|
+
try {
|
|
170
|
+
const response = await browser.fetch(eventsUrl(), {
|
|
171
|
+
method: "HEAD",
|
|
172
|
+
credentials: "same-origin",
|
|
173
|
+
cache: "no-store",
|
|
174
|
+
signal: current.signal,
|
|
175
|
+
});
|
|
176
|
+
if (current.signal.aborted) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (response.status === 401 || response.status === 403) {
|
|
180
|
+
dispatch({ channel: "sync", data: { context: "changed" }, version: protocolVersion });
|
|
181
|
+
setSyncAuthentication(false);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (!response.ok) {
|
|
185
|
+
throw new Error(`Sync authentication failed: ${response.status}`);
|
|
186
|
+
}
|
|
187
|
+
authorized = true;
|
|
188
|
+
connect();
|
|
189
|
+
} catch {
|
|
190
|
+
if (!current.signal.aborted) {
|
|
191
|
+
retry();
|
|
192
|
+
}
|
|
193
|
+
} finally {
|
|
194
|
+
if (authenticating === current) {
|
|
195
|
+
authenticating = undefined;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
139
200
|
const connect = (): void => {
|
|
201
|
+
if (suspended || authPaused) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (!authorized) {
|
|
205
|
+
authenticate();
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
140
208
|
if (transport === "sse") {
|
|
141
209
|
if (
|
|
142
210
|
suspended ||
|
|
@@ -165,12 +233,8 @@ export function installBrowserEventsRuntime(
|
|
|
165
233
|
return;
|
|
166
234
|
}
|
|
167
235
|
eventSource = undefined;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
reconnectTimer = browser.setTimeout(() => {
|
|
171
|
-
reconnectTimer = undefined;
|
|
172
|
-
connect();
|
|
173
|
-
}, delay);
|
|
236
|
+
authorized = !sync;
|
|
237
|
+
retry();
|
|
174
238
|
});
|
|
175
239
|
return;
|
|
176
240
|
}
|
|
@@ -198,23 +262,17 @@ export function installBrowserEventsRuntime(
|
|
|
198
262
|
if (suspended || reconnectTimer !== undefined) {
|
|
199
263
|
return;
|
|
200
264
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const delay = Math.min(
|
|
204
|
-
Math.round(baseDelay * (0.8 + Math.random() * 0.4)),
|
|
205
|
-
maxReconnectDelayMs
|
|
206
|
-
);
|
|
207
|
-
reconnectAttempt += 1;
|
|
208
|
-
reconnectTimer = browser.setTimeout(() => {
|
|
209
|
-
reconnectTimer = undefined;
|
|
210
|
-
connect();
|
|
211
|
-
}, delay);
|
|
265
|
+
authorized = !sync;
|
|
266
|
+
retry();
|
|
212
267
|
});
|
|
213
268
|
connection.addEventListener("error", () => connection.close());
|
|
214
269
|
};
|
|
215
270
|
|
|
216
271
|
const suspend = (): void => {
|
|
217
272
|
suspended = true;
|
|
273
|
+
authenticating?.abort();
|
|
274
|
+
authenticating = undefined;
|
|
275
|
+
authorized = !sync;
|
|
218
276
|
if (reconnectTimer !== undefined) {
|
|
219
277
|
browser.clearTimeout(reconnectTimer);
|
|
220
278
|
reconnectTimer = undefined;
|
|
@@ -225,17 +283,33 @@ export function installBrowserEventsRuntime(
|
|
|
225
283
|
eventSource = undefined;
|
|
226
284
|
};
|
|
227
285
|
const resume = (): void => {
|
|
286
|
+
if (authPaused) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
228
289
|
suspended = false;
|
|
229
290
|
if (socket === undefined && eventSource === undefined) {
|
|
230
291
|
updateStatus("connecting");
|
|
231
292
|
}
|
|
232
293
|
connect();
|
|
233
294
|
};
|
|
295
|
+
const setSyncAuthentication = (valid: boolean): void => {
|
|
296
|
+
if (valid) {
|
|
297
|
+
if (authPaused) {
|
|
298
|
+
authPaused = false;
|
|
299
|
+
resume();
|
|
300
|
+
}
|
|
301
|
+
} else if (!authPaused) {
|
|
302
|
+
authPaused = true;
|
|
303
|
+
suspend();
|
|
304
|
+
updateStatus("unauthorized");
|
|
305
|
+
}
|
|
306
|
+
};
|
|
234
307
|
browser.addEventListener("pagehide", suspend);
|
|
235
308
|
browser.addEventListener("pageshow", resume);
|
|
236
309
|
connect();
|
|
237
310
|
|
|
238
311
|
runtimeWindow[runtimeKey] = {
|
|
312
|
+
setSyncAuthentication,
|
|
239
313
|
subscribe(channel, listener) {
|
|
240
314
|
const channelListeners = listeners[channel];
|
|
241
315
|
channelListeners.add(listener);
|
|
@@ -252,10 +326,10 @@ export function installBrowserEventsRuntime(
|
|
|
252
326
|
};
|
|
253
327
|
}
|
|
254
328
|
|
|
255
|
-
export function browserEventsClientSource(): string {
|
|
256
|
-
return `(${installBrowserEventsRuntime.toString()})(window, import.meta.url);\n`;
|
|
329
|
+
export function browserEventsClientSource(sync?: boolean): string {
|
|
330
|
+
return `(${installBrowserEventsRuntime.toString()})(window, import.meta.url, undefined, ${sync === true});\n`;
|
|
257
331
|
}
|
|
258
332
|
|
|
259
333
|
export function browserEventsSseClientSource(): string {
|
|
260
|
-
return `(${installBrowserEventsRuntime.toString()})(window, import.meta.url, "sse");\n`;
|
|
334
|
+
return `(${installBrowserEventsRuntime.toString()})(window, import.meta.url, "sse", true);\n`;
|
|
261
335
|
}
|
|
@@ -3,12 +3,20 @@ import type { BrowserEventChannel, BrowserEventFor } from "../shared/browser-eve
|
|
|
3
3
|
const BROWSER_EVENT_RUNTIME_KEY = Symbol.for("furin.browser-events.runtime");
|
|
4
4
|
|
|
5
5
|
interface BrowserEventRuntime {
|
|
6
|
+
setSyncAuthentication?: (authorized: boolean) => void;
|
|
6
7
|
subscribe: <TChannel extends BrowserEventChannel>(
|
|
7
8
|
channel: TChannel,
|
|
8
9
|
listener: (event: BrowserEventFor<TChannel>) => void
|
|
9
10
|
) => () => void;
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
/** @internal Router refresh is the existing explicit resume action for cookie authentication. */
|
|
14
|
+
export function setBrowserSyncAuthentication(authorized: boolean): void {
|
|
15
|
+
(globalThis as BrowserEventGlobal)[BROWSER_EVENT_RUNTIME_KEY]?.setSyncAuthentication?.(
|
|
16
|
+
authorized
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
12
20
|
interface BrowserEventGlobal {
|
|
13
21
|
[BROWSER_EVENT_RUNTIME_KEY]?: BrowserEventRuntime;
|
|
14
22
|
}
|
|
@@ -52,13 +52,15 @@ const initialState = stateElement
|
|
|
52
52
|
: undefined;
|
|
53
53
|
const endpointSuffix = "/_furin/dev/overlay.js";
|
|
54
54
|
const blobFramePattern = /blob:https?:\/\/[^\s)]+?(?=:\d+:\d+\)?(?:\n|$))/g;
|
|
55
|
-
const sourceMapPattern =
|
|
55
|
+
const sourceMapPattern = /^\s*\/\/[#@]\s*sourceMappingURL=(\S+)\s*$/m;
|
|
56
56
|
const clientUrl = new URL(import.meta.url);
|
|
57
57
|
const inferredBasePath = clientUrl.pathname.endsWith(endpointSuffix)
|
|
58
58
|
? clientUrl.pathname.slice(0, -endpointSuffix.length)
|
|
59
59
|
: "";
|
|
60
60
|
const basePath = initialState?.basePath ?? inferredBasePath;
|
|
61
61
|
let currentEvent = initialState?.event;
|
|
62
|
+
let clientRenderFailed = false;
|
|
63
|
+
let recoverAfterUpdate = false;
|
|
62
64
|
let coldFailure = initialState !== undefined;
|
|
63
65
|
let host: HTMLDivElement | undefined;
|
|
64
66
|
|
|
@@ -178,9 +180,24 @@ async function reportClientError(detail: ClientErrorDetail): Promise<void> {
|
|
|
178
180
|
|
|
179
181
|
window.addEventListener("furin:client-error", (event) => {
|
|
180
182
|
const { detail } = event as CustomEvent<ClientErrorDetail>;
|
|
183
|
+
if (detail.phase === "client-render") {
|
|
184
|
+
clientRenderFailed = true;
|
|
185
|
+
}
|
|
181
186
|
reportClientError(detail).catch(() => undefined);
|
|
182
187
|
});
|
|
183
188
|
|
|
189
|
+
// Retry only failures from before this update, including when reporting is still
|
|
190
|
+
// in flight or server readiness has already dismissed the overlay.
|
|
191
|
+
window.addEventListener("furin:hmr-before-update", () => {
|
|
192
|
+
recoverAfterUpdate = clientRenderFailed;
|
|
193
|
+
});
|
|
194
|
+
window.addEventListener("furin:hmr-after-update", () => {
|
|
195
|
+
if (recoverAfterUpdate) {
|
|
196
|
+
recoverAfterUpdate = false;
|
|
197
|
+
window.location.reload();
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
184
201
|
if (currentEvent) {
|
|
185
202
|
render(currentEvent);
|
|
186
203
|
}
|
package/src/client/link.tsx
CHANGED
|
@@ -160,16 +160,15 @@ function LinkInteractive<To extends RouteTo>({
|
|
|
160
160
|
if (target !== null) {
|
|
161
161
|
prefetch(target, { staleTime: effectiveStaleTime });
|
|
162
162
|
}
|
|
163
|
-
|
|
164
|
-
}, [prefetch, logicalHref, effectiveStaleTime, router.basePath]);
|
|
163
|
+
}, [prefetch, effectiveStaleTime, router.basePath]);
|
|
165
164
|
|
|
166
|
-
// "render": preload immediately on mount
|
|
165
|
+
// "render": preload immediately on mount, and again when the target changes.
|
|
167
166
|
useEffect(() => {
|
|
168
167
|
if (effectivePreload === "render") {
|
|
169
168
|
triggerPrefetch();
|
|
170
169
|
}
|
|
171
170
|
// react-doctor-disable-next-line react-doctor/exhaustive-deps
|
|
172
|
-
}, [effectivePreload, triggerPrefetch]);
|
|
171
|
+
}, [effectivePreload, triggerPrefetch, logicalHref]);
|
|
173
172
|
|
|
174
173
|
// "viewport": preload when link enters viewport
|
|
175
174
|
useEffect(() => {
|
|
@@ -188,7 +187,7 @@ function LinkInteractive<To extends RouteTo>({
|
|
|
188
187
|
observer.observe(anchorRef.current);
|
|
189
188
|
return () => observer.disconnect();
|
|
190
189
|
// react-doctor-disable-next-line react-doctor/exhaustive-deps
|
|
191
|
-
}, [effectivePreload, triggerPrefetch]);
|
|
190
|
+
}, [effectivePreload, triggerPrefetch, logicalHref]);
|
|
192
191
|
|
|
193
192
|
// Clear any pending intent prefetch timer on unmount to avoid leaking
|
|
194
193
|
// setTimeout callbacks between test cases (or across re-renders).
|
|
@@ -232,7 +231,7 @@ function LinkInteractive<To extends RouteTo>({
|
|
|
232
231
|
// When there is no RouterProvider, fall back to a full-page navigation so
|
|
233
232
|
// the link is still functional (e.g. in storybooks or third-party pages).
|
|
234
233
|
if (typeof window !== "undefined" && router.navigate === CLIENT_FALLBACK_ROUTER.navigate) {
|
|
235
|
-
window.location.href
|
|
234
|
+
window.location.assign(href);
|
|
236
235
|
return;
|
|
237
236
|
}
|
|
238
237
|
// navigate() expects the logical href (no basePath prefix).
|
|
@@ -261,22 +260,22 @@ function LinkInteractive<To extends RouteTo>({
|
|
|
261
260
|
}
|
|
262
261
|
};
|
|
263
262
|
|
|
264
|
-
return
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
...
|
|
275
|
-
...
|
|
276
|
-
...
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
263
|
+
return (
|
|
264
|
+
<a
|
|
265
|
+
data-furin-link
|
|
266
|
+
href={href}
|
|
267
|
+
onClick={handleClick}
|
|
268
|
+
onFocus={handleFocus}
|
|
269
|
+
onMouseEnter={handleMouseEnter}
|
|
270
|
+
onMouseLeave={handleMouseLeave}
|
|
271
|
+
ref={anchorRef}
|
|
272
|
+
{...(isActive ? { "data-status": "active" } : {})}
|
|
273
|
+
{...anchorProps}
|
|
274
|
+
{...extraProps}
|
|
275
|
+
{...(disabled ? { "aria-disabled": true } : {})}
|
|
276
|
+
>
|
|
277
|
+
{resolvedChildren}
|
|
278
|
+
</a>
|
|
280
279
|
);
|
|
281
280
|
}
|
|
282
281
|
|
|
@@ -19,6 +19,7 @@ export interface ReadResult {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export interface ReadReference {
|
|
22
|
+
application?: object;
|
|
22
23
|
client: QueryStore;
|
|
23
24
|
load: (options: unknown) => Promise<ReadResult>;
|
|
24
25
|
url: string;
|
|
@@ -354,6 +355,49 @@ export class QueryStore {
|
|
|
354
355
|
return this.epoch;
|
|
355
356
|
}
|
|
356
357
|
|
|
358
|
+
/** Fence in-flight responses without removing active observers or their loaders. */
|
|
359
|
+
clear(preserveData?: boolean): void {
|
|
360
|
+
this.epoch += 1;
|
|
361
|
+
if (!preserveData) {
|
|
362
|
+
this.session = undefined;
|
|
363
|
+
}
|
|
364
|
+
this.projections.clear();
|
|
365
|
+
for (const entry of this.entries.values()) {
|
|
366
|
+
if (!preserveData) {
|
|
367
|
+
entry.base = undefined;
|
|
368
|
+
entry.identity = undefined;
|
|
369
|
+
}
|
|
370
|
+
entry.promise = undefined;
|
|
371
|
+
entry.stale = true;
|
|
372
|
+
entry.version += 1;
|
|
373
|
+
entry.snapshot = { data: entry.base, error: null, isFetching: false };
|
|
374
|
+
this.publish(entry);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
dispose(): void {
|
|
379
|
+
this.epoch += 1;
|
|
380
|
+
for (const entry of this.entries.values()) {
|
|
381
|
+
entry.listeners.clear();
|
|
382
|
+
}
|
|
383
|
+
this.entries.clear();
|
|
384
|
+
this.requests = [];
|
|
385
|
+
this.projections.clear();
|
|
386
|
+
this.listeners.clear();
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
setError(url: string, error: unknown): void {
|
|
390
|
+
const entry = this.entry(url);
|
|
391
|
+
entry.base = undefined;
|
|
392
|
+
entry.stale = false;
|
|
393
|
+
entry.version += 1;
|
|
394
|
+
entry.snapshot = { data: undefined, error, isFetching: false };
|
|
395
|
+
for (const projection of this.projections) {
|
|
396
|
+
projection.transforms.delete(entry);
|
|
397
|
+
}
|
|
398
|
+
this.publish(entry);
|
|
399
|
+
}
|
|
400
|
+
|
|
357
401
|
version(url: string): number {
|
|
358
402
|
return this.entry(url).version;
|
|
359
403
|
}
|
|
@@ -402,7 +446,7 @@ export class QueryStore {
|
|
|
402
446
|
const { epoch } = this;
|
|
403
447
|
entry.snapshot = { ...entry.snapshot, isFetching: true };
|
|
404
448
|
this.publish(entry);
|
|
405
|
-
|
|
449
|
+
const promise = Promise.resolve()
|
|
406
450
|
.then(() => entry.load?.())
|
|
407
451
|
.then((result) => {
|
|
408
452
|
if (!result || epoch !== this.epoch || version !== entry.version || this.pending(entry)) {
|
|
@@ -420,6 +464,9 @@ export class QueryStore {
|
|
|
420
464
|
}
|
|
421
465
|
})
|
|
422
466
|
.finally(() => {
|
|
467
|
+
if (entry.promise !== promise) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
423
470
|
entry.promise = undefined;
|
|
424
471
|
entry.snapshot = { ...entry.snapshot, isFetching: false };
|
|
425
472
|
this.publish(entry);
|
|
@@ -431,14 +478,18 @@ export class QueryStore {
|
|
|
431
478
|
this.fetch(url);
|
|
432
479
|
}
|
|
433
480
|
});
|
|
434
|
-
|
|
481
|
+
entry.promise = promise;
|
|
482
|
+
return promise;
|
|
435
483
|
}
|
|
436
484
|
|
|
437
485
|
invalidate(identities: readonly QueryIdentity[]): boolean {
|
|
438
486
|
const tags = new Set(identities.map(queryTag));
|
|
439
487
|
let affected = false;
|
|
440
488
|
for (const [url, entry] of this.entries) {
|
|
441
|
-
if (
|
|
489
|
+
if (
|
|
490
|
+
(entry.identity && queryTags(entry.identity).some((tag) => tags.has(tag))) ||
|
|
491
|
+
(!entry.identity && entry.load && identities.length > 0)
|
|
492
|
+
) {
|
|
442
493
|
affected = true;
|
|
443
494
|
this.invalidateEntry(url, entry);
|
|
444
495
|
}
|
|
@@ -81,9 +81,10 @@ export function useRouterStore(): RouterStore {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
export function useTypedNavigation(context: StableRouter): Pick<Router, "navigate" | "prefetch"> {
|
|
84
|
+
const { navigate: navigateHref, prefetch: prefetchHref, searchRoutes } = context;
|
|
84
85
|
const navigate: RouterNavigate = useCallback(
|
|
85
86
|
(next: string | (RuntimeRouteTarget & NavigationOptions), opts?: NavigationOptions) => {
|
|
86
|
-
const href = typeof next === "string" ? next : resolveRouteTarget(next,
|
|
87
|
+
const href = typeof next === "string" ? next : resolveRouteTarget(next, searchRoutes);
|
|
87
88
|
const policy = navigationHrefPolicy(
|
|
88
89
|
href,
|
|
89
90
|
typeof window === "undefined" ? undefined : window.location.origin
|
|
@@ -96,22 +97,22 @@ export function useTypedNavigation(context: StableRouter): Pick<Router, "navigat
|
|
|
96
97
|
return Promise.resolve();
|
|
97
98
|
}
|
|
98
99
|
if (typeof next === "string") {
|
|
99
|
-
return
|
|
100
|
+
return navigateHref(href, opts);
|
|
100
101
|
}
|
|
101
102
|
const options =
|
|
102
103
|
next.replace === undefined && next.resetScroll === undefined
|
|
103
104
|
? undefined
|
|
104
105
|
: { replace: next.replace, resetScroll: next.resetScroll };
|
|
105
|
-
return
|
|
106
|
+
return navigateHref(href, options);
|
|
106
107
|
},
|
|
107
|
-
[
|
|
108
|
+
[navigateHref, searchRoutes]
|
|
108
109
|
);
|
|
109
110
|
const prefetch: Prefetch = useCallback(
|
|
110
111
|
(
|
|
111
112
|
next: string | (RuntimeRouteTarget & { staleTime?: number }),
|
|
112
113
|
opts?: { staleTime?: number }
|
|
113
114
|
) => {
|
|
114
|
-
const href = typeof next === "string" ? next : resolveRouteTarget(next,
|
|
115
|
+
const href = typeof next === "string" ? next : resolveRouteTarget(next, searchRoutes);
|
|
115
116
|
const policy = navigationHrefPolicy(
|
|
116
117
|
href,
|
|
117
118
|
typeof window === "undefined" ? undefined : window.location.origin
|
|
@@ -119,9 +120,9 @@ export function useTypedNavigation(context: StableRouter): Pick<Router, "navigat
|
|
|
119
120
|
if (policy !== "internal") {
|
|
120
121
|
return;
|
|
121
122
|
}
|
|
122
|
-
|
|
123
|
+
prefetchHref(href, typeof next === "string" ? opts : { staleTime: next.staleTime });
|
|
123
124
|
},
|
|
124
|
-
[
|
|
125
|
+
[prefetchHref, searchRoutes]
|
|
125
126
|
);
|
|
126
127
|
return { navigate, prefetch };
|
|
127
128
|
}
|
|
@@ -101,9 +101,10 @@ export class NavigationController {
|
|
|
101
101
|
#version = 0;
|
|
102
102
|
/** In-flight navigation; aborted when superseded or when it ends uncommitted. */
|
|
103
103
|
#pendingAbort: AbortController | null = null;
|
|
104
|
-
/** Owns the visible page's deferred stream
|
|
104
|
+
/** Owns the visible page's deferred stream until replacement or an access-context change. */
|
|
105
105
|
#committedAbort: AbortController | null = null;
|
|
106
|
-
#
|
|
106
|
+
#contextAbort = new AbortController();
|
|
107
|
+
#pendingUserNavigation: { promise: Promise<void>; resolve: () => void } | null = null;
|
|
107
108
|
#renderedHistoryKey: string | undefined;
|
|
108
109
|
#pendingScroll: ScrollInstruction | null = null;
|
|
109
110
|
|
|
@@ -170,7 +171,12 @@ export class NavigationController {
|
|
|
170
171
|
const entry: PageCacheEntry = {
|
|
171
172
|
createdAt: Date.now(),
|
|
172
173
|
promise: this.#config
|
|
173
|
-
.fetchPage({
|
|
174
|
+
.fetchPage({
|
|
175
|
+
currentMatch: this.#currentMatch,
|
|
176
|
+
hmrRefresh: false,
|
|
177
|
+
href,
|
|
178
|
+
signal: this.#contextAbort.signal,
|
|
179
|
+
})
|
|
174
180
|
.then((result) => ({ generation, result, revision: undefined })),
|
|
175
181
|
staleTime: staleTime ?? this.#config.defaultStaleTime,
|
|
176
182
|
};
|
|
@@ -201,6 +207,25 @@ export class NavigationController {
|
|
|
201
207
|
}
|
|
202
208
|
};
|
|
203
209
|
|
|
210
|
+
/** Access changes must also prevent old navigations and deferred streams from publishing. */
|
|
211
|
+
invalidateContext(): void {
|
|
212
|
+
this.#version += 1;
|
|
213
|
+
const pendingAbort = this.#pendingAbort;
|
|
214
|
+
const committedAbort = this.#committedAbort;
|
|
215
|
+
const contextAbort = this.#contextAbort;
|
|
216
|
+
const pendingNavigation = this.#pendingUserNavigation;
|
|
217
|
+
this.#pendingAbort = null;
|
|
218
|
+
this.#committedAbort = null;
|
|
219
|
+
this.#contextAbort = new AbortController();
|
|
220
|
+
this.#pendingUserNavigation = null;
|
|
221
|
+
this.invalidatePath("/", "layout");
|
|
222
|
+
this.#setNavigating(false);
|
|
223
|
+
pendingAbort?.abort();
|
|
224
|
+
committedAbort?.abort();
|
|
225
|
+
contextAbort.abort();
|
|
226
|
+
pendingNavigation?.resolve();
|
|
227
|
+
}
|
|
228
|
+
|
|
204
229
|
/** Drops cached pages whose state reads an invalidated query. */
|
|
205
230
|
invalidateQueries(affected: (state: RouterState) => boolean): void {
|
|
206
231
|
this.#generation.bump((_href, state) => affected(state));
|
|
@@ -224,7 +249,7 @@ export class NavigationController {
|
|
|
224
249
|
async waitForUserNavigation(): Promise<void> {
|
|
225
250
|
while (this.#pendingUserNavigation) {
|
|
226
251
|
// biome-ignore lint/performance/noAwaitInLoops: superseded user navigations must settle in sequence before HMR may refresh the final URL
|
|
227
|
-
await this.#pendingUserNavigation;
|
|
252
|
+
await this.#pendingUserNavigation.promise;
|
|
228
253
|
}
|
|
229
254
|
}
|
|
230
255
|
|
|
@@ -271,16 +296,14 @@ export class NavigationController {
|
|
|
271
296
|
}
|
|
272
297
|
|
|
273
298
|
#beginUserNavigation(): () => void {
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
});
|
|
278
|
-
this.#pendingUserNavigation = promise;
|
|
299
|
+
this.#pendingUserNavigation?.resolve();
|
|
300
|
+
const navigation = Promise.withResolvers<void>();
|
|
301
|
+
this.#pendingUserNavigation = navigation;
|
|
279
302
|
return () => {
|
|
280
|
-
if (this.#pendingUserNavigation ===
|
|
303
|
+
if (this.#pendingUserNavigation === navigation) {
|
|
281
304
|
this.#pendingUserNavigation = null;
|
|
282
305
|
}
|
|
283
|
-
resolve();
|
|
306
|
+
navigation.resolve();
|
|
284
307
|
};
|
|
285
308
|
}
|
|
286
309
|
|
|
@@ -309,11 +332,21 @@ export class NavigationController {
|
|
|
309
332
|
this.#version += 1;
|
|
310
333
|
const version = this.#version;
|
|
311
334
|
const abort = this.#startAbort();
|
|
335
|
+
const cancelled = Promise.withResolvers<false>();
|
|
336
|
+
const onAbort = () => cancelled.resolve(false);
|
|
337
|
+
abort.signal.addEventListener("abort", onAbort, { once: true });
|
|
312
338
|
let committed = false;
|
|
313
339
|
this.#setNavigating(true);
|
|
314
340
|
try {
|
|
315
|
-
|
|
341
|
+
if (abort.signal.aborted) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
committed = await Promise.race([
|
|
345
|
+
this.#load(href, kind, version, abort.signal),
|
|
346
|
+
cancelled.promise,
|
|
347
|
+
]);
|
|
316
348
|
} finally {
|
|
349
|
+
abort.signal.removeEventListener("abort", onAbort);
|
|
317
350
|
this.#settleAbort(abort, committed);
|
|
318
351
|
finishUserNavigation?.();
|
|
319
352
|
if (this.#version === version) {
|