@teyik0/furin 0.6.0-alpha.1 → 0.7.0-alpha.2

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 (197) hide show
  1. package/dist/adapter/runtime-build.d.ts +1 -1
  2. package/dist/build/client.d.ts +4 -1
  3. package/dist/build/elysia-aot-worker.d.ts +22 -0
  4. package/dist/build/elysia-aot.d.ts +1 -1
  5. package/dist/build/entry-template.d.ts +3 -0
  6. package/dist/build/entry-template.ts +7 -0
  7. package/dist/build/hydrate.d.ts +1 -1
  8. package/dist/build/index.js +1880 -401
  9. package/dist/build/preload-manifest.d.ts +17 -0
  10. package/dist/build/types.d.ts +6 -0
  11. package/dist/cli/index.js +1878 -408
  12. package/dist/client/client-module.d.ts +26 -0
  13. package/dist/client/define-route.d.ts +9 -0
  14. package/dist/client/document.d.ts +2 -0
  15. package/dist/client/internal/runtime-types.d.ts +2 -0
  16. package/dist/client/link.js +942 -122
  17. package/dist/client/mutation.d.ts +38 -0
  18. package/dist/client/query-store.d.ts +85 -0
  19. package/dist/client/query.d.ts +14 -0
  20. package/dist/client/route-api.d.ts +11 -0
  21. package/dist/client/router/context.d.ts +3 -2
  22. package/dist/client/router/index.d.ts +1 -1
  23. package/dist/client/router/link-utils.d.ts +8 -1
  24. package/dist/client/router/navigation.d.ts +2 -9
  25. package/dist/client/router/optimistic.d.ts +41 -0
  26. package/dist/client/router/search/index.d.ts +3 -3
  27. package/dist/client/router/search-store.d.ts +1 -0
  28. package/dist/client/router/sync-catch-up.d.ts +3 -0
  29. package/dist/client/router/types.d.ts +51 -7
  30. package/dist/client/sync.d.ts +39 -22
  31. package/dist/client.d.ts +11 -33
  32. package/dist/client.js +1219 -59
  33. package/dist/config.d.ts +7 -0
  34. package/dist/config.js +1 -0
  35. package/dist/define-route.d.ts +78 -32
  36. package/dist/env.d.ts +2 -2
  37. package/dist/furin.d.ts +1 -2
  38. package/dist/furin.js +2484 -708
  39. package/dist/plugin/hmr-dependencies.d.ts +2 -0
  40. package/dist/plugin/index.js +349 -18
  41. package/dist/plugin/transform-client-module.d.ts +16 -0
  42. package/dist/plugin/transform-client.d.ts +2 -0
  43. package/dist/plugin/transform-isomorphic.d.ts +1 -1
  44. package/dist/routes.d.ts +6 -0
  45. package/dist/rsc-client.js +87 -16
  46. package/dist/rsc.js +87 -16
  47. package/dist/server/auto-invalidate/registry.d.ts +1 -0
  48. package/dist/server/auto-invalidate/types.d.ts +2 -0
  49. package/dist/server/cache/isr.d.ts +2 -4
  50. package/dist/server/cache/route-cache.d.ts +5 -0
  51. package/dist/server/dev/graph.d.ts +1 -0
  52. package/dist/server/dev-page-plugin.d.ts +5 -19
  53. package/dist/server/internal.d.ts +3 -0
  54. package/dist/server/internal.js +55 -35
  55. package/dist/server/production-server.js +54 -34
  56. package/dist/server/render/loaders.d.ts +4 -2
  57. package/dist/server/render/react-stream.d.ts +3 -0
  58. package/dist/server/render/ssr.d.ts +2 -1
  59. package/dist/server/render/template.d.ts +4 -0
  60. package/dist/server/router/defined-route.d.ts +2 -0
  61. package/dist/server/router/hmr.d.ts +1 -1
  62. package/dist/server/router/patterns.d.ts +2 -0
  63. package/dist/server/router/types.d.ts +1 -1
  64. package/dist/server/sync/adapter.d.ts +25 -4
  65. package/dist/server/sync/atomic.d.ts +25 -0
  66. package/dist/server/sync/drizzle/index.d.ts +45 -0
  67. package/dist/server/sync/drizzle/index.js +540 -0
  68. package/dist/server/sync/execution-error.d.ts +2 -0
  69. package/dist/server/sync/index.d.ts +2 -1
  70. package/dist/server/sync/index.js +533 -105
  71. package/dist/server/sync/mutation-handler.d.ts +4 -0
  72. package/dist/server/sync/plugin.d.ts +34 -11
  73. package/dist/server/sync/postgres/execute.d.ts +3 -0
  74. package/dist/server/sync/postgres/index.d.ts +12 -1
  75. package/dist/server/sync/postgres/index.js +34 -13
  76. package/dist/server/sync/postgres/sql.d.ts +8 -0
  77. package/dist/server/sync/prisma/index.d.ts +24 -0
  78. package/dist/server/sync/prisma/index.js +340 -0
  79. package/dist/server/sync/queries.d.ts +21 -0
  80. package/dist/server/sync/query-context.d.ts +5 -0
  81. package/dist/server/sync/redis/index.js +3 -3
  82. package/dist/server/sync/redis/scripts.d.ts +1 -1
  83. package/dist/server/sync/response.d.ts +1 -0
  84. package/dist/server/sync/sqlite/index.d.ts +3 -0
  85. package/dist/server/sync/sqlite/index.js +10 -4
  86. package/dist/server/sync/stream.d.ts +2 -5
  87. package/dist/server/sync/validation.d.ts +4 -0
  88. package/dist/shared/defer.d.ts +31 -0
  89. package/dist/shared/error.d.ts +2 -2
  90. package/dist/shared/page-key.d.ts +7 -0
  91. package/dist/shared/query-bindings.d.ts +12 -0
  92. package/dist/shared/route-frame.d.ts +1 -0
  93. package/dist/shared/sync-query.d.ts +40 -0
  94. package/package.json +29 -6
  95. package/src/adapter/package.ts +12 -2
  96. package/src/adapter/runtime-build.ts +63 -12
  97. package/src/adapter/static.ts +7 -2
  98. package/src/adapter/vercel.ts +15 -13
  99. package/src/build/client.ts +23 -5
  100. package/src/build/elysia-aot-worker.ts +51 -0
  101. package/src/build/elysia-aot.ts +83 -19
  102. package/src/build/entry-template.ts +7 -0
  103. package/src/build/hydrate.ts +21 -3
  104. package/src/build/preload-manifest.ts +100 -0
  105. package/src/build/production-instrumentation.ts +6 -3
  106. package/src/build/types.ts +4 -0
  107. package/src/cli/index.ts +1 -0
  108. package/src/client/browser-events-runtime.ts +4 -0
  109. package/src/client/client-module.ts +57 -0
  110. package/src/client/define-route.ts +11 -1
  111. package/src/client/document.tsx +28 -18
  112. package/src/client/hmr.ts +2 -1
  113. package/src/client/internal/runtime-types.ts +2 -0
  114. package/src/client/link.tsx +8 -8
  115. package/src/client/mutation.ts +136 -0
  116. package/src/client/query-store.ts +418 -0
  117. package/src/client/query.tsx +67 -0
  118. package/src/client/route-api.tsx +75 -0
  119. package/src/client/router/boundary-tree.tsx +19 -12
  120. package/src/client/router/context.ts +57 -4
  121. package/src/client/router/index.ts +3 -0
  122. package/src/client/router/link-utils.ts +29 -1
  123. package/src/client/router/navigation.ts +3 -50
  124. package/src/client/router/optimistic.ts +233 -0
  125. package/src/client/router/provider.tsx +306 -46
  126. package/src/client/router/search/index.ts +37 -17
  127. package/src/client/router/search-store.ts +4 -0
  128. package/src/client/router/sync-catch-up.ts +7 -0
  129. package/src/client/router/types.ts +73 -9
  130. package/src/client/sync.ts +438 -65
  131. package/src/client.ts +20 -60
  132. package/src/config.ts +5 -0
  133. package/src/define-route.ts +113 -55
  134. package/src/env.d.ts +2 -2
  135. package/src/furin.ts +75 -13
  136. package/src/plugin/hmr-dependencies.ts +58 -0
  137. package/src/plugin/index.ts +38 -2
  138. package/src/plugin/routes.ts +28 -16
  139. package/src/plugin/transform-client-module.ts +123 -0
  140. package/src/plugin/transform-client.ts +293 -13
  141. package/src/plugin/transform-isomorphic.ts +11 -5
  142. package/src/routes.ts +8 -0
  143. package/src/rsc/shared.tsx +104 -18
  144. package/src/server/auto-invalidate/registry.ts +4 -0
  145. package/src/server/auto-invalidate/runtime.ts +17 -0
  146. package/src/server/auto-invalidate/types.ts +6 -0
  147. package/src/server/cache/isr.ts +6 -34
  148. package/src/server/cache/route-cache.ts +40 -4
  149. package/src/server/dev/graph.ts +16 -2
  150. package/src/server/dev-page-plugin.ts +93 -59
  151. package/src/server/internal.ts +3 -0
  152. package/src/server/render/document.tsx +10 -1
  153. package/src/server/render/element.tsx +21 -11
  154. package/src/server/render/isr.ts +61 -29
  155. package/src/server/render/loaders.ts +118 -47
  156. package/src/server/render/mixed-cache.ts +33 -4
  157. package/src/server/render/not-found.ts +4 -7
  158. package/src/server/render/ppr-document.ts +2 -1
  159. package/src/server/render/ppr-route.ts +30 -10
  160. package/src/server/render/react-stream.ts +17 -0
  161. package/src/server/render/route-frame-transport.ts +3 -0
  162. package/src/server/render/ssg.ts +51 -18
  163. package/src/server/render/ssr.ts +53 -8
  164. package/src/server/render/template.ts +23 -0
  165. package/src/server/router/defined-route.ts +3 -0
  166. package/src/server/router/discovery.ts +25 -9
  167. package/src/server/router/hmr.ts +3 -2
  168. package/src/server/router/patterns.ts +16 -0
  169. package/src/server/router/plugin.ts +27 -12
  170. package/src/server/router/types.ts +1 -1
  171. package/src/server/sync/adapter.ts +41 -4
  172. package/src/server/sync/atomic.ts +303 -0
  173. package/src/server/sync/drizzle/index.ts +145 -0
  174. package/src/server/sync/execution-error.ts +1 -0
  175. package/src/server/sync/fingerprint.ts +2 -6
  176. package/src/server/sync/index.ts +6 -0
  177. package/src/server/sync/mutation-handler.ts +69 -0
  178. package/src/server/sync/plugin.ts +177 -60
  179. package/src/server/sync/postgres/execute.ts +20 -0
  180. package/src/server/sync/postgres/index.ts +52 -16
  181. package/src/server/sync/postgres/sql.ts +20 -0
  182. package/src/server/sync/prisma/index.ts +70 -0
  183. package/src/server/sync/queries.ts +75 -0
  184. package/src/server/sync/query-context.ts +85 -0
  185. package/src/server/sync/redis/index.ts +7 -3
  186. package/src/server/sync/redis/scripts.ts +1 -1
  187. package/src/server/sync/response.ts +21 -0
  188. package/src/server/sync/sqlite/index.ts +19 -8
  189. package/src/server/sync/stream.ts +14 -22
  190. package/src/server/sync/validation.ts +34 -0
  191. package/src/shared/defer.ts +48 -0
  192. package/src/shared/error.ts +2 -2
  193. package/src/shared/page-key.ts +36 -0
  194. package/src/shared/query-bindings.ts +138 -0
  195. package/src/shared/route-frame.ts +13 -1
  196. package/src/shared/route-map.ts +12 -2
  197. package/src/shared/sync-query.ts +138 -0
@@ -1,4 +1,5 @@
1
1
  import type { CacheTag } from "../../furin.ts";
2
+ import type { SyncQueryIdentity } from "../../shared/sync-query.ts";
2
3
  import type { RevalidateType } from "../cache/route-cache.ts";
3
4
 
4
5
  export type InvalidationRule =
@@ -14,3 +15,8 @@ export type InvalidationRule =
14
15
  };
15
16
 
16
17
  export type InvalidationInput = InvalidationRule | readonly InvalidationRule[];
18
+
19
+ export type SyncInvalidationInput =
20
+ | InvalidationRule
21
+ | SyncQueryIdentity
22
+ | readonly (InvalidationRule | SyncQueryIdentity)[];
@@ -1,38 +1,23 @@
1
1
  import { allStateBuckets, type FurinInstance, instanceSlot } from "../instance.ts";
2
2
  import { createHtmlRouteCache, type ISRCacheEntry } from "./isr-ssg";
3
3
  import { registerCacheInvalidator } from "./registry";
4
- import type { Cache } from "./route-cache";
4
+ import type { Cache, CacheGeneration } from "./route-cache";
5
5
  import { createStoreView, type StoreView } from "./store-view";
6
6
 
7
7
  interface ISRCacheState {
8
8
  cache: Cache<ISRCacheEntry>;
9
- generations: Map<string, Set<ISRCacheGeneration>>;
10
9
  pendingRevalidations: Map<string, Promise<void>>;
11
10
  }
12
11
 
13
- export interface ISRCacheGeneration {
14
- valid: boolean;
15
- }
12
+ export type ISRCacheGeneration = CacheGeneration;
16
13
 
17
14
  // Per-instance ISR HTML cache — registered against the owning instance's
18
15
  // invalidator map on first access.
19
16
  const instanceIsrCache = instanceSlot<ISRCacheState>((instance) => {
20
- const generations = new Map<string, Set<ISRCacheGeneration>>();
21
17
  const pendingRevalidations = new Map<string, Promise<void>>();
22
- const cache = createHtmlRouteCache<ISRCacheEntry>("isr", {
23
- onDelete: (key) => {
24
- const pending = generations.get(key);
25
- if (pending === undefined) {
26
- return;
27
- }
28
- for (const generation of pending) {
29
- generation.valid = false;
30
- }
31
- generations.delete(key);
32
- },
33
- });
18
+ const cache = createHtmlRouteCache<ISRCacheEntry>("isr");
34
19
  registerCacheInvalidator(cache, instance);
35
- return { cache, generations, pendingRevalidations };
20
+ return { cache, pendingRevalidations };
36
21
  });
37
22
 
38
23
  export function isrRouteCache(instance?: FurinInstance): Cache<ISRCacheEntry> {
@@ -57,24 +42,11 @@ export function setISRCache(key: string, entry: ISRCacheEntry): void {
57
42
  }
58
43
 
59
44
  export function captureISRCacheGeneration(key: string): ISRCacheGeneration {
60
- const state = instanceIsrCache();
61
- const generation = { valid: true };
62
- const pending = state.generations.get(key);
63
- if (pending === undefined) {
64
- state.generations.set(key, new Set([generation]));
65
- } else {
66
- pending.add(generation);
67
- }
68
- return generation;
45
+ return instanceIsrCache().cache.captureGeneration(key);
69
46
  }
70
47
 
71
48
  export function releaseISRCacheGeneration(key: string, generation: ISRCacheGeneration): void {
72
- const { generations } = instanceIsrCache();
73
- const pending = generations.get(key);
74
- pending?.delete(generation);
75
- if (pending?.size === 0) {
76
- generations.delete(key);
77
- }
49
+ instanceIsrCache().cache.releaseGeneration(key, generation);
78
50
  }
79
51
 
80
52
  export function setISRCacheIfGenerationUnchanged(
@@ -5,7 +5,12 @@ export interface CacheInvalidationResult {
5
5
  purgedPaths: string[];
6
6
  }
7
7
 
8
+ export interface CacheGeneration {
9
+ valid: boolean;
10
+ }
11
+
8
12
  export interface Cache<Entry> {
13
+ captureGeneration: (key: string) => CacheGeneration;
9
14
  clear: () => void;
10
15
  delete: (key: string) => boolean;
11
16
  entries: () => IterableIterator<[string, Entry]>;
@@ -14,6 +19,7 @@ export interface Cache<Entry> {
14
19
  invalidatePath: (path: string, type: RevalidateType) => CacheInvalidationResult;
15
20
  keys: () => IterableIterator<string>;
16
21
  readonly name: string;
22
+ releaseGeneration: (key: string, generation: CacheGeneration) => void;
17
23
  set: (key: string, entry: Entry) => void;
18
24
  get size(): number;
19
25
  readonly store: Map<string, Entry>;
@@ -54,8 +60,16 @@ function matchesPath(urlPath: string, path: string, type: RevalidateType): boole
54
60
 
55
61
  export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cache<Entry> {
56
62
  const store = new Map<string, Entry>();
63
+ const generations = new Map<string, Set<CacheGeneration>>();
57
64
  const pathFromKey = options.pathFromKey ?? defaultPathFromKey;
58
65
 
66
+ const invalidateGenerations = (key: string): void => {
67
+ for (const generation of generations.get(key) ?? []) {
68
+ generation.valid = false;
69
+ }
70
+ generations.delete(key);
71
+ };
72
+
59
73
  const evictOldest = (): void => {
60
74
  if (options.maxSize === undefined || store.size <= options.maxSize) {
61
75
  return;
@@ -67,6 +81,7 @@ export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cach
67
81
  };
68
82
 
69
83
  const deleteEntry = (key: string): boolean => {
84
+ invalidateGenerations(key);
70
85
  const entry = store.get(key);
71
86
  if (entry === undefined) {
72
87
  return false;
@@ -77,7 +92,20 @@ export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cach
77
92
  };
78
93
 
79
94
  return {
95
+ captureGeneration(key) {
96
+ const generation = { valid: true };
97
+ let pending = generations.get(key);
98
+ if (pending === undefined) {
99
+ pending = new Set();
100
+ generations.set(key, pending);
101
+ }
102
+ pending.add(generation);
103
+ return generation;
104
+ },
80
105
  clear() {
106
+ for (const key of generations.keys()) {
107
+ invalidateGenerations(key);
108
+ }
81
109
  for (const key of [...store.keys()]) {
82
110
  deleteEntry(key);
83
111
  }
@@ -104,14 +132,15 @@ export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cach
104
132
  let deleted = false;
105
133
  const purgedPaths: string[] = [];
106
134
 
107
- for (const key of [...store.keys()]) {
135
+ for (const key of new Set([...store.keys(), ...generations.keys()])) {
108
136
  const urlPath = pathFromKey(key);
109
137
  if (urlPath === null || !matchesPath(urlPath, path, type)) {
110
138
  continue;
111
139
  }
112
- deleteEntry(key);
113
- deleted = true;
114
- purgedPaths.push(urlPath);
140
+ if (deleteEntry(key)) {
141
+ deleted = true;
142
+ purgedPaths.push(urlPath);
143
+ }
115
144
  }
116
145
 
117
146
  return { deleted, purgedPaths: [...new Set(purgedPaths)] };
@@ -120,6 +149,13 @@ export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cach
120
149
  return store.keys();
121
150
  },
122
151
  name: options.name,
152
+ releaseGeneration(key, generation) {
153
+ const pending = generations.get(key);
154
+ pending?.delete(generation);
155
+ if (pending?.size === 0) {
156
+ generations.delete(key);
157
+ }
158
+ },
123
159
  set(key, entry) {
124
160
  const previous = store.get(key);
125
161
  if (previous !== undefined) {
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { readFileSync, statSync } from "node:fs";
3
- import { dirname, extname, resolve } from "node:path";
3
+ import { dirname, extname, isAbsolute, resolve } from "node:path";
4
4
  import type { FurinRouteDispatcher } from "../../define-route.ts";
5
5
  import { currentInstance, type FurinInstance } from "../instance.ts";
6
6
  import type { ResolvedRoute, RootLayout } from "../router/types.ts";
@@ -84,7 +84,7 @@ export function resolveDevSourceImports(
84
84
  ? resolve(dirname(path), imported.path)
85
85
  : Bun.resolveSync(imported.path, dirname(path));
86
86
  const resolved = normalizeModulePath(absolute);
87
- if (!resolved.includes("/node_modules/")) {
87
+ if (isAbsolute(resolved) && !resolved.includes("/node_modules/")) {
88
88
  imports.push(resolved);
89
89
  }
90
90
  } catch {
@@ -268,6 +268,20 @@ export class DevGraph<Snapshot> {
268
268
  return this.importChain(from, normalizedTo).includes(normalizedTo);
269
269
  }
270
270
 
271
+ sourceDependencies(from: string): string[] {
272
+ const pending = [normalizeModulePath(from)];
273
+ const visited = new Set<string>();
274
+ while (pending.length > 0) {
275
+ const path = pending.pop();
276
+ if (path === undefined || visited.has(path)) {
277
+ continue;
278
+ }
279
+ visited.add(path);
280
+ pending.push(...(this.#dependencies.get(path) ?? []));
281
+ }
282
+ return [...visited];
283
+ }
284
+
271
285
  clearSourceErrors(path: string): void {
272
286
  const modulePath = normalizeModulePath(path);
273
287
  for (const [message, positions] of this.#sourceErrors) {
@@ -47,17 +47,19 @@
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
54
  import { statSync } from "node:fs";
57
55
  import { dirname, isAbsolute, resolve } from "node:path";
58
56
  import { fileURLToPath } from "node:url";
57
+ import MagicString from "magic-string";
59
58
  import { splitDevPage } from "../plugin/transform-dev-page.ts";
60
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";
61
63
  import { invalidateDevLoaderCacheBySource } from "./cache/dev-loader.ts";
62
64
  import { publishDevError } from "./dev/error.ts";
63
65
  import { developmentGraphs, resolveDevSourceImports } from "./dev/graph.ts";
@@ -74,6 +76,7 @@ export const WORKSPACE_SOURCE_FILTER =
74
76
  const T_PARAM_RE = /&t=(\d+)/;
75
77
  const STRIP_FURIN_SERVER_RE = /\?furin-server.*$/;
76
78
  const STRIP_T_PARAM_RE = /\?t=\d+$/;
79
+ const IMPORT_ATTRIBUTES_RE = /\b(?:with|assert)\s*\{/;
77
80
  const DELETED_DEV_PAGE_CONTENTS = "export const route = undefined;";
78
81
 
79
82
  let _pluginRegistered = false;
@@ -240,69 +243,45 @@ function rewriteRelativeImportsWithVersion(
240
243
  }
241
244
 
242
245
  /**
243
- * Rewrites all remaining bare specifiers in the transpiled JS to absolute
244
- * on-disk paths resolved from `dir` (the page file's directory).
245
- *
246
- * Uses `Bun.Transpiler.scan()` on the original source to get the authoritative
247
- * list of *actual* import specifiers (parsing correctly handles template
248
- * literals, comments, etc.). For each bare specifier that is not already
249
- * handled by `rewriteSingletonImports`, it calls `Bun.resolveSync` and
250
- * replaces **every** import/re-export occurrence of the quoted specifier using
251
- * a context-aware regex with the `g` flag — mirroring the approach used by
252
- * `rewriteSingletonImports`. This correctly handles modules that both import
253
- * and re-export from the same package without leaving any bare specifier
254
- * behind. String literals that happen to contain the same text (inside
255
- * template literals, JSX props, etc.) are not touched because the regex
256
- * 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.
257
248
  *
258
249
  * @internal exported for testing
259
250
  */
260
- export function rewriteBareImports(source: string, transpiled: string, dir: string): string {
261
- const scanner = new Bun.Transpiler({ loader: "tsx" });
262
- let { imports } = scanner.scan(source);
263
- // Deduplicate: scan() may return the same specifier multiple times if it
264
- // appears in both `import` and `export ... from` positions.
265
- const seen = new Set<string>();
266
- imports = imports.filter((imp) => {
267
- if (seen.has(imp.path)) {
268
- return false;
269
- }
270
- seen.add(imp.path);
271
- return true;
272
- });
273
-
274
- let result = transpiled;
275
- for (const imp of imports) {
276
- const spec = imp.path;
277
- // Skip relative paths (already rewritten by rewriteRelativeImports before transpilation)
278
- // and already-absolute paths.
279
- if (spec.startsWith(".") || spec.startsWith("/") || spec.startsWith("file:")) {
280
- 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;
281
261
  }
282
- // Skip React singletons — already handled by rewriteSingletonImports.
283
- if (SINGLETON_PATHS.has(spec)) {
284
- 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;
285
273
  }
286
274
 
287
275
  let resolved: string;
288
276
  try {
289
- resolved = toImportSpecifier(Bun.resolveSync(spec, dir));
277
+ resolved = toImportSpecifier(Bun.resolveSync(specifier, dir));
290
278
  } catch {
291
- // Not resolvable from the file's directory — leave as a bare specifier
292
- // so Bun falls back to CWD-relative resolution (adequate for most cases).
293
- continue;
279
+ // Leave unresolved imports to Bun's native resolution and diagnostics.
280
+ return;
294
281
  }
295
-
296
- // Replace ALL import/re-export occurrences of the bare specifier using a
297
- // context-aware regex with the `g` flag. This correctly handles modules
298
- // that both import and re-export from the same package. The regex only
299
- // matches when the specifier is preceded by `from` or `import` so string
300
- // literals in non-import positions are left untouched.
301
- // react-doctor-disable-next-line react-doctor/js-hoist-regexp
302
- const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(spec)}["']`, "g");
303
- result = result.replace(re, (_, g1: string) => `${g1}${JSON.stringify(resolved)}`);
304
- }
305
- return result;
282
+ output.update(literal.start, literal.end, JSON.stringify(resolved));
283
+ });
284
+ return output.toString();
306
285
  }
307
286
 
308
287
  function getSourceLoader(filePath: string): SourceLoader | null {
@@ -321,6 +300,57 @@ function getSourceLoader(filePath: string): SourceLoader | null {
321
300
  return null;
322
301
  }
323
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
+
324
354
  function shouldSkipWorkspaceTransform(filePath: string): boolean {
325
355
  const normalized = filePath.replace(/\\/g, "/");
326
356
  return normalized.includes("/.furin/");
@@ -422,11 +452,15 @@ export function transformDevSource(
422
452
  ? rewriteRelativeImportsWithVersion(serverSource, filePath, true)
423
453
  : serverSource;
424
454
  const transpiler = new Bun.Transpiler({ loader });
425
- const transpiled = transpiler.transformSync(sourceForTranspile, loader);
455
+ const transpiled = restoreImportAttributes(
456
+ sourceForTranspile,
457
+ transpiler.transformSync(sourceForTranspile, loader),
458
+ loader
459
+ );
426
460
 
427
461
  let result = transpiled;
428
462
  if (options.rewriteBareImports) {
429
- result = rewriteBareImports(serverSource, result, dirname(filePath));
463
+ result = rewriteBareImports(result, dirname(filePath));
430
464
  }
431
465
 
432
466
  result = rewriteSingletonImports(result);
@@ -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;
@@ -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";
@@ -38,5 +41,11 @@ export function withDocumentState(
38
41
  routeFrames,
39
42
  syncJson: syncPath === undefined ? undefined : safeJson({ path: syncPath }),
40
43
  };
41
- 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
+ );
42
51
  }
@@ -2,8 +2,10 @@ 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,24 +15,30 @@ export function buildElement(
13
15
  rootLayout: RuntimeRoute
14
16
  ): ReactNode {
15
17
  const Component = route.page.component;
16
- let element: ReactNode = createElement(Component, data);
18
+ let element: ReactNode = createElement(Component, {
19
+ ...data,
20
+ key: pageKey(route.pattern, data, route.page._route.remountDeps),
21
+ });
17
22
 
18
- // Index segmentBoundaries by depth for O(1) lookup during the wrap loop.
19
- // Directory depth `d` maps 1:1 to routeChain[d] in Furin's model (routeChain
20
- // is ordered shallow→deep, with index 0 being the root).
21
- const byDepth = new Map<number, SegmentBoundary>();
23
+ // Directories without layouts share their enclosing layout's chain index.
24
+ // Keep their boundaries in inside-out order instead of overwriting them.
25
+ const byDepth = new Map<number, SegmentBoundary[]>();
22
26
  const legacyRoute = route as ResolvedRoute & {
23
27
  segmentBoundaries?: SegmentBoundary[];
24
28
  };
25
29
  for (const segment of legacyRoute.segmentBoundaries ?? []) {
26
- byDepth.set(segment.depth, segment);
30
+ const boundaries = byDepth.get(segment.depth) ?? [];
31
+ boundaries.unshift(segment);
32
+ byDepth.set(segment.depth, boundaries);
27
33
  }
28
34
 
29
35
  // Build inside-out. At each level we first wrap the accumulated subtree
30
36
  // with the boundary declared at this depth (so the boundary sits INSIDE
31
37
  // the layout at the same depth), THEN wrap with the layout itself.
32
38
  for (let i = route.routeChain.length - 1; i >= 1; i -= 1) {
33
- element = wrapSegmentBoundaries(element, byDepth.get(i), undefined);
39
+ for (const segment of byDepth.get(i) ?? []) {
40
+ element = wrapSegmentBoundaries(element, segment, undefined);
41
+ }
34
42
  const routeEntry = route.routeChain[i];
35
43
  if (routeEntry?.layout) {
36
44
  const Layout = routeEntry.layout;
@@ -38,16 +46,18 @@ export function buildElement(
38
46
  }
39
47
  }
40
48
 
41
- // Depth 0 = pagesDir itself = the root layout directory. Boundary wraps
42
- // everything below the root layout; root layout wraps the boundary.
43
- element = wrapSegmentBoundaries(element, byDepth.get(0), undefined);
49
+ // Index-0 boundaries wrap everything below the root layout, including
50
+ // pathless directories without their own layouts.
51
+ for (const segment of byDepth.get(0) ?? []) {
52
+ element = wrapSegmentBoundaries(element, segment, undefined);
53
+ }
44
54
 
45
55
  if (rootLayout.layout) {
46
56
  const RootLayoutComponent = rootLayout.layout;
47
57
  element = createElement(RootLayoutComponent as ElementType, data, element);
48
58
  }
49
59
 
50
- return element;
60
+ return withRouteSnapshot(element, route.pattern, data);
51
61
  }
52
62
 
53
63
  export function wrapRootLayout(