@teyik0/furin 0.5.0-alpha.2 → 0.7.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.
Files changed (230) hide show
  1. package/dist/adapter/runtime-build.d.ts +3 -1
  2. package/dist/build/client.d.ts +4 -1
  3. package/dist/build/entry-template.d.ts +5 -0
  4. package/dist/build/entry-template.ts +9 -0
  5. package/dist/build/hydrate.d.ts +1 -1
  6. package/dist/build/index.js +9589 -6685
  7. package/dist/build/preload-manifest.d.ts +17 -0
  8. package/dist/build/request-keys.d.ts +4 -0
  9. package/dist/build/types.d.ts +6 -0
  10. package/dist/cli/index.js +9539 -6644
  11. package/dist/client/browser-events-runtime.d.ts +2 -1
  12. package/dist/client/client-module.d.ts +26 -0
  13. package/dist/client/define-route.d.ts +9 -1
  14. package/dist/client/dev-error-overlay.ts +1 -0
  15. package/dist/client/document.d.ts +3 -0
  16. package/dist/client/hmr.d.ts +1 -1
  17. package/dist/client/internal/runtime-types.d.ts +2 -0
  18. package/dist/client/link.js +1011 -157
  19. package/dist/client/mutation.d.ts +38 -0
  20. package/dist/client/query-store.d.ts +85 -0
  21. package/dist/client/query.d.ts +14 -0
  22. package/dist/client/route-api.d.ts +11 -0
  23. package/dist/client/router/context.d.ts +3 -2
  24. package/dist/client/router/index.d.ts +1 -1
  25. package/dist/client/router/link-utils.d.ts +8 -1
  26. package/dist/client/router/navigation.d.ts +2 -9
  27. package/dist/client/router/optimistic.d.ts +41 -0
  28. package/dist/client/router/search/index.d.ts +3 -3
  29. package/dist/client/router/search-store.d.ts +1 -0
  30. package/dist/client/router/sync-catch-up.d.ts +3 -0
  31. package/dist/client/router/types.d.ts +49 -7
  32. package/dist/client/sync.d.ts +39 -22
  33. package/dist/client.d.ts +11 -33
  34. package/dist/client.js +1222 -57
  35. package/dist/config.d.ts +7 -0
  36. package/dist/config.js +1 -0
  37. package/dist/define-route.d.ts +231 -123
  38. package/dist/env.d.ts +2 -2
  39. package/dist/furin.d.ts +4 -2
  40. package/dist/furin.js +9717 -6796
  41. package/dist/plugin/hmr-dependencies.d.ts +2 -0
  42. package/dist/plugin/index.js +811 -145
  43. package/dist/plugin/transform-client-module.d.ts +16 -0
  44. package/dist/plugin/transform-client.d.ts +2 -0
  45. package/dist/plugin/transform-dev-page.d.ts +7 -0
  46. package/dist/plugin/transform-isomorphic.d.ts +1 -1
  47. package/dist/routes.d.ts +6 -0
  48. package/dist/rsc-client.js +87 -16
  49. package/dist/rsc.js +87 -16
  50. package/dist/server/auto-invalidate/registry.d.ts +5 -2
  51. package/dist/server/auto-invalidate/types.d.ts +2 -0
  52. package/dist/server/browser-events/plugin.d.ts +3 -0
  53. package/dist/server/cache/isr.d.ts +2 -4
  54. package/dist/server/cache/route-cache.d.ts +5 -0
  55. package/dist/server/dev/graph.d.ts +1 -0
  56. package/dist/server/dev/runtime.production.d.ts +1 -0
  57. package/dist/server/dev-page-plugin.d.ts +6 -19
  58. package/dist/server/internal.d.ts +5 -0
  59. package/dist/server/internal.js +105 -57
  60. package/dist/server/production-server.js +104 -56
  61. package/dist/server/render/assemble.d.ts +6 -6
  62. package/dist/server/render/document.d.ts +1 -1
  63. package/dist/server/render/element.d.ts +1 -1
  64. package/dist/server/render/loaders.d.ts +15 -5
  65. package/dist/server/render/mixed-cache.d.ts +6 -0
  66. package/dist/server/render/react-stream.d.ts +3 -0
  67. package/dist/server/render/ssr.d.ts +5 -4
  68. package/dist/server/render/template.d.ts +4 -0
  69. package/dist/server/router/defined-route.d.ts +2 -0
  70. package/dist/server/router/discovery.d.ts +1 -0
  71. package/dist/server/router/hmr.d.ts +1 -1
  72. package/dist/server/router/patterns.d.ts +3 -0
  73. package/dist/server/router/plugin.d.ts +3 -0
  74. package/dist/server/router/types.d.ts +4 -0
  75. package/dist/server/security/csp.d.ts +12 -0
  76. package/dist/server/sync/adapter.d.ts +25 -4
  77. package/dist/server/sync/atomic.d.ts +25 -0
  78. package/dist/server/sync/drizzle/index.d.ts +45 -0
  79. package/dist/server/sync/drizzle/index.js +540 -0
  80. package/dist/server/sync/execution-error.d.ts +2 -0
  81. package/dist/server/sync/index.d.ts +2 -1
  82. package/dist/server/sync/index.js +580 -124
  83. package/dist/server/sync/mutation-handler.d.ts +4 -0
  84. package/dist/server/sync/plugin.d.ts +34 -11
  85. package/dist/server/sync/postgres/execute.d.ts +3 -0
  86. package/dist/server/sync/postgres/index.d.ts +12 -1
  87. package/dist/server/sync/postgres/index.js +42 -13
  88. package/dist/server/sync/postgres/sql.d.ts +8 -0
  89. package/dist/server/sync/prisma/index.d.ts +24 -0
  90. package/dist/server/sync/prisma/index.js +340 -0
  91. package/dist/server/sync/queries.d.ts +21 -0
  92. package/dist/server/sync/query-context.d.ts +5 -0
  93. package/dist/server/sync/redis/index.js +3 -3
  94. package/dist/server/sync/redis/scripts.d.ts +1 -1
  95. package/dist/server/sync/response.d.ts +1 -0
  96. package/dist/server/sync/sqlite/index.d.ts +3 -0
  97. package/dist/server/sync/sqlite/index.js +10 -4
  98. package/dist/server/sync/stream.d.ts +2 -5
  99. package/dist/server/sync/validation.d.ts +4 -0
  100. package/dist/shared/defer.d.ts +31 -0
  101. package/dist/shared/error.d.ts +2 -2
  102. package/dist/shared/page-key.d.ts +7 -0
  103. package/dist/shared/query-bindings.d.ts +12 -0
  104. package/dist/shared/route-frame.d.ts +1 -0
  105. package/dist/shared/sync-query.d.ts +40 -0
  106. package/package.json +40 -16
  107. package/src/adapter/README.md +3 -0
  108. package/src/adapter/bun.ts +3 -0
  109. package/src/adapter/package.ts +16 -2
  110. package/src/adapter/runtime-build.ts +99 -14
  111. package/src/adapter/static.ts +17 -6
  112. package/src/adapter/vercel.ts +33 -23
  113. package/src/build/client.ts +23 -5
  114. package/src/build/entry-template.ts +9 -0
  115. package/src/build/hydrate.ts +18 -3
  116. package/src/build/preload-manifest.ts +100 -0
  117. package/src/build/production-instrumentation.ts +6 -3
  118. package/src/build/request-keys.ts +93 -0
  119. package/src/build/ssg-cache.ts +9 -4
  120. package/src/build/types.ts +4 -0
  121. package/src/cli/index.ts +1 -0
  122. package/src/client/boundaries.tsx +1 -1
  123. package/src/client/browser-events-runtime.ts +73 -16
  124. package/src/client/client-module.ts +57 -0
  125. package/src/client/define-route.ts +11 -2
  126. package/src/client/dev-error-overlay.ts +1 -0
  127. package/src/client/document.tsx +47 -20
  128. package/src/client/hmr.ts +4 -2
  129. package/src/client/internal/runtime-types.ts +2 -0
  130. package/src/client/link.tsx +8 -8
  131. package/src/client/mutation.ts +136 -0
  132. package/src/client/query-store.ts +418 -0
  133. package/src/client/query.tsx +67 -0
  134. package/src/client/route-api.tsx +75 -0
  135. package/src/client/router/boundary-tree.tsx +10 -6
  136. package/src/client/router/context.ts +57 -4
  137. package/src/client/router/index.ts +3 -0
  138. package/src/client/router/link-utils.ts +29 -1
  139. package/src/client/router/navigation.ts +3 -50
  140. package/src/client/router/optimistic.ts +233 -0
  141. package/src/client/router/provider.tsx +404 -96
  142. package/src/client/router/search/index.ts +37 -17
  143. package/src/client/router/search-store.ts +4 -0
  144. package/src/client/router/sync-catch-up.ts +7 -0
  145. package/src/client/router/types.ts +71 -9
  146. package/src/client/sync.ts +438 -65
  147. package/src/client.ts +20 -60
  148. package/src/config.ts +5 -0
  149. package/src/define-route.ts +442 -155
  150. package/src/env.d.ts +2 -2
  151. package/src/furin.ts +213 -38
  152. package/src/plugin/hmr-dependencies.ts +58 -0
  153. package/src/plugin/index.ts +38 -2
  154. package/src/plugin/route-config-autofix.ts +2 -2
  155. package/src/plugin/routes.ts +19 -8
  156. package/src/plugin/transform-client-module.ts +123 -0
  157. package/src/plugin/transform-client.ts +293 -13
  158. package/src/plugin/transform-dev-page.ts +231 -0
  159. package/src/plugin/transform-isomorphic.ts +11 -5
  160. package/src/routes.ts +8 -0
  161. package/src/rsc/shared.tsx +104 -18
  162. package/src/rsc/version.ts +5 -0
  163. package/src/server/auto-invalidate/registry.ts +56 -24
  164. package/src/server/auto-invalidate/runtime.ts +17 -0
  165. package/src/server/auto-invalidate/types.ts +6 -0
  166. package/src/server/browser-events/plugin.ts +112 -1
  167. package/src/server/cache/dev-loader.ts +1 -1
  168. package/src/server/cache/invalidation.ts +2 -0
  169. package/src/server/cache/isr-ssg.ts +1 -1
  170. package/src/server/cache/isr.ts +6 -34
  171. package/src/server/cache/route-cache.ts +40 -4
  172. package/src/server/cache/ssg.ts +1 -1
  173. package/src/server/dev/diagnostics.ts +4 -2
  174. package/src/server/dev/error.ts +2 -1
  175. package/src/server/dev/graph.ts +70 -7
  176. package/src/server/dev/runtime.production.ts +4 -0
  177. package/src/server/dev/symbolicate.ts +2 -0
  178. package/src/server/dev-page-plugin.ts +160 -63
  179. package/src/server/evlog.ts +1 -1
  180. package/src/server/internal.ts +5 -0
  181. package/src/server/render/assemble.ts +15 -11
  182. package/src/server/render/document.tsx +13 -2
  183. package/src/server/render/element.tsx +11 -6
  184. package/src/server/render/isr.ts +71 -33
  185. package/src/server/render/loaders.ts +328 -70
  186. package/src/server/render/mixed-cache.ts +327 -0
  187. package/src/server/render/not-found.ts +14 -11
  188. package/src/server/render/ppr-document.ts +47 -11
  189. package/src/server/render/ppr-route.ts +54 -20
  190. package/src/server/render/react-stream.ts +17 -0
  191. package/src/server/render/route-frame-transport.ts +3 -0
  192. package/src/server/render/ssg.ts +53 -19
  193. package/src/server/render/ssr.ts +105 -36
  194. package/src/server/render/static-params.ts +1 -1
  195. package/src/server/render/template.ts +23 -0
  196. package/src/server/router/defined-route.ts +3 -0
  197. package/src/server/router/discovery.ts +14 -0
  198. package/src/server/router/hmr.ts +109 -18
  199. package/src/server/router/patterns.ts +27 -0
  200. package/src/server/router/plugin.ts +94 -19
  201. package/src/server/router/source-version.ts +20 -2
  202. package/src/server/router/types.ts +4 -0
  203. package/src/server/security/csp.ts +44 -0
  204. package/src/server/sync/adapter.ts +41 -4
  205. package/src/server/sync/atomic.ts +303 -0
  206. package/src/server/sync/drizzle/index.ts +145 -0
  207. package/src/server/sync/execution-error.ts +1 -0
  208. package/src/server/sync/fingerprint.ts +2 -6
  209. package/src/server/sync/index.ts +6 -0
  210. package/src/server/sync/mutation-handler.ts +69 -0
  211. package/src/server/sync/plugin.ts +177 -60
  212. package/src/server/sync/postgres/execute.ts +20 -0
  213. package/src/server/sync/postgres/index.ts +60 -16
  214. package/src/server/sync/postgres/sql.ts +20 -0
  215. package/src/server/sync/prisma/index.ts +70 -0
  216. package/src/server/sync/queries.ts +75 -0
  217. package/src/server/sync/query-context.ts +85 -0
  218. package/src/server/sync/redis/index.ts +7 -3
  219. package/src/server/sync/redis/scripts.ts +1 -1
  220. package/src/server/sync/response.ts +21 -0
  221. package/src/server/sync/sqlite/index.ts +19 -8
  222. package/src/server/sync/stream.ts +14 -22
  223. package/src/server/sync/validation.ts +34 -0
  224. package/src/shared/defer.ts +48 -0
  225. package/src/shared/error.ts +2 -2
  226. package/src/shared/page-key.ts +36 -0
  227. package/src/shared/query-bindings.ts +138 -0
  228. package/src/shared/route-frame.ts +13 -1
  229. package/src/shared/route-map.ts +12 -2
  230. package/src/shared/sync-query.ts +138 -0
@@ -47,32 +47,40 @@
47
47
  * guaranteeing a single shared React instance regardless of CWD or
48
48
  * hot-reload state.
49
49
  *
50
- * All import/re-export occurrences of each quoted specifier are replaced using
51
- * a context-aware regex (requires a preceding `from` or `import` keyword) so
52
- * that modules which both import and re-export from the same package are fully
53
- * rewritten while string literals in non-import positions are left untouched.
50
+ * Static imports, re-exports, and literal dynamic imports are rewritten from
51
+ * the parsed module, leaving ordinary strings and comments untouched.
54
52
  */
55
53
 
56
- import { dirname, resolve } from "node:path";
54
+ import { statSync } from "node:fs";
55
+ import { dirname, isAbsolute, resolve } from "node:path";
57
56
  import { fileURLToPath } from "node:url";
57
+ import MagicString from "magic-string";
58
+ import { splitDevPage } from "../plugin/transform-dev-page.ts";
58
59
  import { transformIsomorphicFunctions } from "../plugin/transform-isomorphic.ts";
60
+ import { parseSource } from "../shared/parser.ts";
61
+ import type { AstNode } from "../shared/utils/ast-walk.ts";
62
+ import { walkAST } from "../shared/utils/ast-walk.ts";
59
63
  import { invalidateDevLoaderCacheBySource } from "./cache/dev-loader.ts";
60
64
  import { publishDevError } from "./dev/error.ts";
61
65
  import { developmentGraphs, resolveDevSourceImports } from "./dev/graph.ts";
62
66
  import { rewriteModuleSpecifiers } from "./dev/rewrite-module-specifiers.ts";
63
67
  import { DevTransformFailure } from "./dev/transform-failure.ts";
68
+ import { routeModuleSourceVersion } from "./router/source-version.ts";
64
69
 
65
70
  // Matches ?furin-server with an optional &t=<ms> cache-buster.
66
71
  const FURIN_SERVER_FILTER = /\?furin-server(?:&t=\d+)?$/;
72
+ const FURIN_RENDER_FILTER = /\?furin-render&t=\d+$/;
67
73
  const ANY_FILTER = /.*/;
68
74
  export const WORKSPACE_SOURCE_FILTER =
69
75
  /^(?!.*(?:[\\/]node_modules[\\/]|[\\/]\.bun[\\/]))(?!.*\.(?:test|spec)\.[jt]sx?$).*\.[jt]sx?$/;
70
76
  const T_PARAM_RE = /&t=(\d+)/;
71
77
  const STRIP_FURIN_SERVER_RE = /\?furin-server.*$/;
72
78
  const STRIP_T_PARAM_RE = /\?t=\d+$/;
79
+ const IMPORT_ATTRIBUTES_RE = /\b(?:with|assert)\s*\{/;
73
80
  const DELETED_DEV_PAGE_CONTENTS = "export const route = undefined;";
74
81
 
75
82
  let _pluginRegistered = false;
83
+ const pluginSourceStamps = new Map<string, string>();
76
84
 
77
85
  type SourceLoader = "js" | "jsx" | "ts" | "tsx";
78
86
 
@@ -235,69 +243,45 @@ function rewriteRelativeImportsWithVersion(
235
243
  }
236
244
 
237
245
  /**
238
- * Rewrites all remaining bare specifiers in the transpiled JS to absolute
239
- * on-disk paths resolved from `dir` (the page file's directory).
240
- *
241
- * Uses `Bun.Transpiler.scan()` on the original source to get the authoritative
242
- * list of *actual* import specifiers (parsing correctly handles template
243
- * literals, comments, etc.). For each bare specifier that is not already
244
- * handled by `rewriteSingletonImports`, it calls `Bun.resolveSync` and
245
- * replaces **every** import/re-export occurrence of the quoted specifier using
246
- * a context-aware regex with the `g` flag — mirroring the approach used by
247
- * `rewriteSingletonImports`. This correctly handles modules that both import
248
- * and re-export from the same package without leaving any bare specifier
249
- * behind. String literals that happen to contain the same text (inside
250
- * template literals, JSX props, etc.) are not touched because the regex
251
- * requires a preceding `from` or `import` keyword.
246
+ * Resolves static imports, re-exports, and literal dynamic imports from the
247
+ * page file's directory, including tsconfig aliases in virtual modules.
252
248
  *
253
249
  * @internal exported for testing
254
250
  */
255
- export function rewriteBareImports(source: string, transpiled: string, dir: string): string {
256
- const scanner = new Bun.Transpiler({ loader: "tsx" });
257
- let { imports } = scanner.scan(source);
258
- // Deduplicate: scan() may return the same specifier multiple times if it
259
- // appears in both `import` and `export ... from` positions.
260
- const seen = new Set<string>();
261
- imports = imports.filter((imp) => {
262
- if (seen.has(imp.path)) {
263
- return false;
264
- }
265
- seen.add(imp.path);
266
- return true;
267
- });
268
-
269
- let result = transpiled;
270
- for (const imp of imports) {
271
- const spec = imp.path;
272
- // Skip relative paths (already rewritten by rewriteRelativeImports before transpilation)
273
- // and already-absolute paths.
274
- if (spec.startsWith(".") || spec.startsWith("/") || spec.startsWith("file:")) {
275
- continue;
251
+ export function rewriteBareImports(transpiled: string, dir: string): string {
252
+ const output = new MagicString(transpiled);
253
+ walkAST(parseSource(transpiled, "js").program, (node) => {
254
+ if (
255
+ node.type !== "ImportDeclaration" &&
256
+ node.type !== "ExportNamedDeclaration" &&
257
+ node.type !== "ExportAllDeclaration" &&
258
+ node.type !== "ImportExpression"
259
+ ) {
260
+ return;
276
261
  }
277
- // Skip React singletons — already handled by rewriteSingletonImports.
278
- if (SINGLETON_PATHS.has(spec)) {
279
- continue;
262
+ const literal = node.source as AstNode | undefined;
263
+ const specifier = literal?.value;
264
+ if (
265
+ literal?.type !== "Literal" ||
266
+ typeof specifier !== "string" ||
267
+ specifier.startsWith(".") ||
268
+ isAbsolute(specifier) ||
269
+ specifier.startsWith("file:") ||
270
+ SINGLETON_PATHS.has(specifier)
271
+ ) {
272
+ return;
280
273
  }
281
274
 
282
275
  let resolved: string;
283
276
  try {
284
- resolved = toImportSpecifier(Bun.resolveSync(spec, dir));
277
+ resolved = toImportSpecifier(Bun.resolveSync(specifier, dir));
285
278
  } catch {
286
- // Not resolvable from the file's directory — leave as a bare specifier
287
- // so Bun falls back to CWD-relative resolution (adequate for most cases).
288
- continue;
279
+ // Leave unresolved imports to Bun's native resolution and diagnostics.
280
+ return;
289
281
  }
290
-
291
- // Replace ALL import/re-export occurrences of the bare specifier using a
292
- // context-aware regex with the `g` flag. This correctly handles modules
293
- // that both import and re-export from the same package. The regex only
294
- // matches when the specifier is preceded by `from` or `import` so string
295
- // literals in non-import positions are left untouched.
296
- // react-doctor-disable-next-line react-doctor/js-hoist-regexp
297
- const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(spec)}["']`, "g");
298
- result = result.replace(re, (_, g1: string) => `${g1}${JSON.stringify(resolved)}`);
299
- }
300
- return result;
282
+ output.update(literal.start, literal.end, JSON.stringify(resolved));
283
+ });
284
+ return output.toString();
301
285
  }
302
286
 
303
287
  function getSourceLoader(filePath: string): SourceLoader | null {
@@ -316,6 +300,57 @@ function getSourceLoader(filePath: string): SourceLoader | null {
316
300
  return null;
317
301
  }
318
302
 
303
+ // Bun.Transpiler drops static import attributes, turning text imports into file paths.
304
+ function restoreImportAttributes(source: string, transpiled: string, loader: SourceLoader): string {
305
+ if (!IMPORT_ATTRIBUTES_RE.test(source)) {
306
+ return transpiled;
307
+ }
308
+
309
+ const declarations = parseSource(source, loader).program.body as AstNode[];
310
+ const output = new MagicString(transpiled);
311
+ const emitted = parseSource(transpiled, "js").program.body as AstNode[];
312
+ const matched = new Set<AstNode>();
313
+ for (const declaration of declarations) {
314
+ if (declaration.importKind === "type" || declaration.exportKind === "type") {
315
+ continue;
316
+ }
317
+ const specifiers = declaration.specifiers as AstNode[] | undefined;
318
+ if (
319
+ specifiers?.length &&
320
+ specifiers.every(
321
+ (specifier) => specifier.importKind === "type" || specifier.exportKind === "type"
322
+ )
323
+ ) {
324
+ continue;
325
+ }
326
+ const sourcePath = (declaration.source as { value?: unknown } | undefined)?.value;
327
+ if (typeof sourcePath !== "string") {
328
+ continue;
329
+ }
330
+ const target = emitted.find(
331
+ (node) =>
332
+ !matched.has(node) &&
333
+ node.type === declaration.type &&
334
+ (node.source as { value?: unknown } | undefined)?.value === sourcePath
335
+ );
336
+ if (!target) {
337
+ continue;
338
+ }
339
+ matched.add(target);
340
+ const attributes = declaration.attributes as AstNode[] | undefined;
341
+ if (!attributes?.length || (target.attributes as AstNode[] | undefined)?.length) {
342
+ continue;
343
+ }
344
+ const [first] = attributes;
345
+ const last = attributes.at(-1);
346
+ const imported = target.source as AstNode | undefined;
347
+ if (first && last && imported) {
348
+ output.appendLeft(imported.end, ` with { ${source.slice(first.start, last.end)} }`);
349
+ }
350
+ }
351
+ return output.toString();
352
+ }
353
+
319
354
  function shouldSkipWorkspaceTransform(filePath: string): boolean {
320
355
  const normalized = filePath.replace(/\\/g, "/");
321
356
  return normalized.includes("/.furin/");
@@ -323,6 +358,28 @@ function shouldSkipWorkspaceTransform(filePath: string): boolean {
323
358
 
324
359
  function recordDevImports(source: string, filePath: string): void {
325
360
  const { imports } = resolveDevSourceImports(source, filePath, getSourceLoader(filePath) ?? "tsx");
361
+ for (const path of imports) {
362
+ if (!isAbsolute(path) || getSourceLoader(path)) {
363
+ continue;
364
+ }
365
+ // Plugin loaders match the original extension (e.g. .mdx), so a query
366
+ // suffix cannot version these modules. Evict only an edited source.
367
+ const stats = statSync(path, { bigint: true, throwIfNoEntry: false });
368
+ if (!stats) {
369
+ continue;
370
+ }
371
+ const stamp = `${stats.mtimeNs}:${stats.size}`;
372
+ const previous = pluginSourceStamps.get(path);
373
+ if (previous !== undefined && previous !== stamp) {
374
+ Reflect.deleteProperty(require.cache, path);
375
+ for (const cachedPath of Object.keys(require.cache)) {
376
+ if (toImportSpecifier(cachedPath) === toImportSpecifier(path)) {
377
+ Reflect.deleteProperty(require.cache, cachedPath);
378
+ }
379
+ }
380
+ }
381
+ pluginSourceStamps.set(path, stamp);
382
+ }
326
383
  for (const graph of developmentGraphs()) {
327
384
  graph.recordImports(toImportSpecifier(filePath), imports);
328
385
  }
@@ -364,7 +421,11 @@ function rethrowWithSourcePath(error: unknown, filePath: string): never {
364
421
  export function transformDevSource(
365
422
  raw: string,
366
423
  filePath: string,
367
- options: { rewriteBareImports: boolean; rewriteRelativeImports: boolean }
424
+ options: {
425
+ renderFragment?: boolean;
426
+ rewriteBareImports: boolean;
427
+ rewriteRelativeImports: boolean;
428
+ }
368
429
  ): string {
369
430
  const loader = getSourceLoader(filePath);
370
431
  if (!loader) {
@@ -375,17 +436,31 @@ export function transformDevSource(
375
436
  graph.clearSourceErrors(filePath);
376
437
  }
377
438
  try {
378
- recordDevImports(raw, filePath);
379
- const serverSource = transformIsomorphicFunctions(raw, filePath, "server").code;
439
+ if (!options.renderFragment) {
440
+ recordDevImports(raw, filePath);
441
+ }
442
+ const isomorphicSource = transformIsomorphicFunctions(raw, filePath, "server").code;
443
+ const split = options.renderFragment
444
+ ? undefined
445
+ : splitDevPage(
446
+ isomorphicSource,
447
+ filePath,
448
+ `${filePath}?furin-render&t=${routeModuleSourceVersion(filePath)}`
449
+ );
450
+ const serverSource = split?.contract ?? isomorphicSource;
380
451
  const sourceForTranspile = options.rewriteRelativeImports
381
452
  ? rewriteRelativeImportsWithVersion(serverSource, filePath, true)
382
453
  : serverSource;
383
454
  const transpiler = new Bun.Transpiler({ loader });
384
- const transpiled = transpiler.transformSync(sourceForTranspile, loader);
455
+ const transpiled = restoreImportAttributes(
456
+ sourceForTranspile,
457
+ transpiler.transformSync(sourceForTranspile, loader),
458
+ loader
459
+ );
385
460
 
386
461
  let result = transpiled;
387
462
  if (options.rewriteBareImports) {
388
- result = rewriteBareImports(serverSource, result, dirname(filePath));
463
+ result = rewriteBareImports(result, dirname(filePath));
389
464
  }
390
465
 
391
466
  result = rewriteSingletonImports(result);
@@ -445,6 +520,27 @@ export function registerDevPagePlugin(): void {
445
520
  Bun.plugin({
446
521
  name: "furin-dev-page-loader",
447
522
  setup(build) {
523
+ build.onResolve({ filter: FURIN_RENDER_FILTER }, (args) => ({
524
+ namespace: "furin-dev-render",
525
+ path: args.path,
526
+ }));
527
+ build.onLoad({ filter: ANY_FILTER, namespace: "furin-dev-render" }, async (args) => {
528
+ const filePath = args.path.slice(0, args.path.indexOf("?furin-render"));
529
+ const raw = await Bun.file(filePath).text();
530
+ const source = transformIsomorphicFunctions(raw, filePath, "server").code;
531
+ const split = splitDevPage(source, filePath, args.path);
532
+ if (!split) {
533
+ throw new Error(`[furin] Page changed while loading its render module: ${filePath}`);
534
+ }
535
+ return {
536
+ contents: transformDevSource(split.render, filePath, {
537
+ renderFragment: true,
538
+ rewriteBareImports: true,
539
+ rewriteRelativeImports: true,
540
+ }),
541
+ loader: "js",
542
+ };
543
+ });
448
544
  // Keep an already-loaded module generation usable if its source is
449
545
  // deleted while Bun finishes that same generation. A later generation
450
546
  // receives a tombstone instead of reviving the removed route.
@@ -457,6 +553,7 @@ export function registerDevPagePlugin(): void {
457
553
  build.onResolve({ filter: FURIN_SERVER_FILTER }, (args) => {
458
554
  const tMatch = T_PARAM_RE.exec(args.path);
459
555
  const filePath = args.path.replace(STRIP_FURIN_SERVER_RE, "");
556
+ // biome-ignore lint/suspicious/noUnnecessaryConditions: the timestamp query is optional.
460
557
  const resolvedPath = tMatch ? `${filePath}?t=${tMatch[1]}` : filePath;
461
558
  return { namespace: "furin-dev-page", path: resolvedPath };
462
559
  });
@@ -50,7 +50,7 @@ export function createFurinEvlog(options: FurinEvlogOptions) {
50
50
 
51
51
  return new Elysia({ name: "furin-evlog" })
52
52
  .derive("global", ({ request }) => {
53
- const log = requestLoggers.get(request);
53
+ const log = requestLoggers.get(request) ?? loggerStorage.useLogger();
54
54
  if (log === undefined) {
55
55
  throw new Error("[furin] Request logger was not initialized");
56
56
  }
@@ -1,4 +1,5 @@
1
1
  import type { AnyElysia } from "elysia";
2
+ import type { ClientPreloadManifest } from "../build/preload-manifest.ts";
2
3
  import type { SsgCacheEntry } from "./cache/index.ts";
3
4
  import {
4
5
  hasPendingISRRevalidations as hasPendingISR,
@@ -44,6 +45,8 @@ export interface CompileContext {
44
45
  nativeRoutes?: AnyElysia;
45
46
  /** Mount prefix this app was built for (`""` = root). */
46
47
  prefix?: string;
48
+ /** Chunk URLs to modulepreload, produced by the client build. */
49
+ preloadManifest?: ClientPreloadManifest;
47
50
  /** Root-level conventions discovered at compile time. */
48
51
  rootConventions?: { errorPath?: string; notFoundPath?: string };
49
52
  rootPath: string;
@@ -51,6 +54,8 @@ export interface CompileContext {
51
54
  routeMetadata?: Record<
52
55
  string,
53
56
  {
57
+ requestKeys?: string[];
58
+ requestKeysByLoader?: string[][];
54
59
  segmentBoundaries: Array<{
55
60
  depth: number;
56
61
  path: string;
@@ -25,11 +25,14 @@ export const FURIN_DEFERRED_GLOBAL = "__FURIN_DEFERRED__";
25
25
  * Synchronous loader data is NOT carried here — it lives exclusively in the
26
26
  * `__FURIN_DATA__` JSON script that the hydrate entry reads.
27
27
  *
28
- * CSP note: this is an inline `<script>` — nonce support is a v2 concern.
29
28
  */
30
- export function buildDeferredScript(deferredKeys: string[]): string {
29
+ export function nonceAttribute(nonce?: string): string {
30
+ return nonce === undefined ? "" : ` nonce="${nonce}"`;
31
+ }
32
+
33
+ export function buildDeferredScript(deferredKeys: string[], nonce?: string): string {
31
34
  const keysJson = safeJson(deferredKeys);
32
- return `<script id="${FURIN_DEFERRED_GLOBAL}">
35
+ return `<script id="${FURIN_DEFERRED_GLOBAL}"${nonceAttribute(nonce)}>
33
36
  window.${FURIN_DEFERRED_GLOBAL} = {
34
37
  _deferredKeys: ${keysJson},
35
38
  _chunks: {},
@@ -63,10 +66,11 @@ window.${FURIN_DEFERRED_GLOBAL} = {
63
66
  export function buildDeferredResolution(
64
67
  key: string,
65
68
  chunk: ReturnType<typeof toCrossJSON>,
66
- action: "resolve" | "reject"
69
+ action: "resolve" | "reject",
70
+ nonce?: string
67
71
  ): string {
68
72
  const chunkJson = safeJson(chunk);
69
- return `<script>window.${FURIN_DEFERRED_GLOBAL}.${action}(${safeJson(key)},${chunkJson})</script>`;
73
+ return `<script${nonceAttribute(nonce)}>window.${FURIN_DEFERRED_GLOBAL}.${action}(${safeJson(key)},${chunkJson})</script>`;
70
74
  }
71
75
 
72
76
  /** Minimal context passed to background / synthetic render helpers — only `request` is needed. */
@@ -108,8 +112,8 @@ export function buildRouteFrameTemplate(payload: string): string {
108
112
  return `<template id="__FURIN_ROUTE_FRAMES__">${escaped}</template>`;
109
113
  }
110
114
 
111
- export function buildRouteFrameStreamScript(): string {
112
- return `<script id="__FURIN_ROUTE_FRAME_STREAM__">
115
+ export function buildRouteFrameStreamScript(nonce?: string): string {
116
+ return `<script id="__FURIN_ROUTE_FRAME_STREAM__"${nonceAttribute(nonce)}>
113
117
  window.__FURIN_ROUTE_FRAME_STREAM__ = {
114
118
  _chunks: [],
115
119
  _closed: false,
@@ -149,12 +153,12 @@ window.__FURIN_ROUTE_FRAME_STREAM__ = {
149
153
  </script>`;
150
154
  }
151
155
 
152
- export function buildRouteFramePushScript(payload: string): string {
153
- return `<script>window.__FURIN_ROUTE_FRAME_STREAM__.push(${safeJson(payload)})</script>`;
156
+ export function buildRouteFramePushScript(payload: string, nonce?: string): string {
157
+ return `<script${nonceAttribute(nonce)}>window.__FURIN_ROUTE_FRAME_STREAM__.push(${safeJson(payload)})</script>`;
154
158
  }
155
159
 
156
- export function buildRouteFrameCloseScript(): string {
157
- return "<script>window.__FURIN_ROUTE_FRAME_STREAM__.close()</script>";
160
+ export function buildRouteFrameCloseScript(nonce?: string): string {
161
+ return `<script${nonceAttribute(nonce)}>window.__FURIN_ROUTE_FRAME_STREAM__.close()</script>`;
158
162
  }
159
163
 
160
164
  export function buildSyncRuntimeScript(): string {
@@ -4,8 +4,11 @@ import {
4
4
  DocumentProvider,
5
5
  type DocumentState,
6
6
  } from "../../client/document.tsx";
7
+ import { QueryStoreContext } from "../../client/query.tsx";
8
+ import { QueryStore } from "../../client/query-store.ts";
7
9
  import type { HeadOptions } from "../../client.ts";
8
10
  import { containsRscSource, serializeRouteFrames } from "../../shared/route-frame.ts";
11
+ import type { QuerySeed } from "../../shared/sync-query.ts";
9
12
  import { currentInstance } from "../instance.ts";
10
13
  import { getSyncPath } from "../sync/config.ts";
11
14
  import { safeJson } from "./shell.ts";
@@ -14,7 +17,8 @@ export function withDocumentState(
14
17
  element: ReactNode,
15
18
  assets: DocumentAssets,
16
19
  head: HeadOptions | undefined,
17
- data: object | undefined
20
+ data: object | undefined,
21
+ nonce?: string
18
22
  ): ReactNode {
19
23
  const syncPath = getSyncPath();
20
24
  const browserEventsClientPath = `${currentInstance().prefix}/_furin/events/client.js`;
@@ -33,8 +37,15 @@ export function withDocumentState(
33
37
  assets: resolvedAssets,
34
38
  dataJson: data === undefined || routeFrames !== undefined ? undefined : safeJson(data),
35
39
  head,
40
+ nonce,
36
41
  routeFrames,
37
42
  syncJson: syncPath === undefined ? undefined : safeJson({ path: syncPath }),
38
43
  };
39
- return createElement(DocumentProvider, { value: state }, element);
44
+ const queries = new QueryStore(undefined);
45
+ queries.hydrate((data as { __furinQueries?: QuerySeed[] } | undefined)?.__furinQueries ?? []);
46
+ return createElement(
47
+ DocumentProvider,
48
+ { value: state },
49
+ createElement(QueryStoreContext.Provider, { value: queries }, element)
50
+ );
40
51
  }
@@ -1,9 +1,11 @@
1
- import type { ReactNode } from "react";
1
+ import { createElement, type ElementType, type ReactNode } from "react";
2
2
  import { wrapSegmentBoundaries } from "../../client/boundaries.tsx";
3
3
  import { DefaultErrorFallback, DefaultNotFoundFallback } from "../../client/default-screens.tsx";
4
4
  import type { RuntimeRoute } from "../../client/internal/runtime-types.ts";
5
+ import { withRouteSnapshot } from "../../client/route-api.tsx";
5
6
  import type { ErrorComponent } from "../../shared/error.ts";
6
7
  import type { FurinNotFoundError, NotFoundComponent } from "../../shared/not-found.ts";
8
+ import { pageKey } from "../../shared/page-key.ts";
7
9
  import type { ResolvedRoute, SegmentBoundary } from "../router/types.ts";
8
10
  import { IS_DEV } from "../runtime-env.ts";
9
11
 
@@ -13,7 +15,10 @@ export function buildElement(
13
15
  rootLayout: RuntimeRoute
14
16
  ): ReactNode {
15
17
  const Component = route.page.component;
16
- let element: ReactNode = <Component {...data} />;
18
+ let element: ReactNode = createElement(Component, {
19
+ ...data,
20
+ key: pageKey(route.pattern, data, route.page._route.remountDeps),
21
+ });
17
22
 
18
23
  // Index segmentBoundaries by depth for O(1) lookup during the wrap loop.
19
24
  // Directory depth `d` maps 1:1 to routeChain[d] in Furin's model (routeChain
@@ -34,7 +39,7 @@ export function buildElement(
34
39
  const routeEntry = route.routeChain[i];
35
40
  if (routeEntry?.layout) {
36
41
  const Layout = routeEntry.layout;
37
- element = <Layout {...data}>{element}</Layout>;
42
+ element = createElement(Layout as ElementType, data, element);
38
43
  }
39
44
  }
40
45
 
@@ -44,10 +49,10 @@ export function buildElement(
44
49
 
45
50
  if (rootLayout.layout) {
46
51
  const RootLayoutComponent = rootLayout.layout;
47
- element = <RootLayoutComponent {...data}>{element}</RootLayoutComponent>;
52
+ element = createElement(RootLayoutComponent as ElementType, data, element);
48
53
  }
49
54
 
50
- return element;
55
+ return withRouteSnapshot(element, route.pattern, data);
51
56
  }
52
57
 
53
58
  export function wrapRootLayout(
@@ -59,7 +64,7 @@ export function wrapRootLayout(
59
64
  return element;
60
65
  }
61
66
  const RootLayoutComponent = rootLayout.layout;
62
- return <RootLayoutComponent {...data}>{element}</RootLayoutComponent>;
67
+ return createElement(RootLayoutComponent as ElementType, data, element);
63
68
  }
64
69
 
65
70
  export function buildNotFoundElement(