houdini-react 1.2.9 → 1.2.11

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 (46) hide show
  1. package/build/plugin/codegen/entries.d.ts +1 -2
  2. package/build/plugin/codegen/index.d.ts +1 -2
  3. package/build/plugin/codegen/manifest.d.ts +4 -41
  4. package/build/plugin/codegen/router.d.ts +1 -2
  5. package/build/plugin/codegen/typeRoot.d.ts +1 -2
  6. package/build/plugin/index.d.ts +3 -1
  7. package/build/plugin/vite.d.ts +38 -1
  8. package/build/plugin-cjs/index.js +75188 -76234
  9. package/build/plugin-esm/index.js +75185 -76233
  10. package/build/runtime/index.d.ts +6 -3
  11. package/build/runtime/routing/components/Router.d.ts +4 -4
  12. package/build/runtime/routing/components/index.d.ts +0 -1
  13. package/build/runtime/routing/lib/cache.d.ts +1 -1
  14. package/build/runtime/routing/lib/types.d.ts +0 -4
  15. package/build/runtime-cjs/index.d.ts +6 -3
  16. package/build/runtime-cjs/index.js +22 -18
  17. package/build/runtime-cjs/routing/components/Router.d.ts +4 -4
  18. package/build/runtime-cjs/routing/components/Router.js +173 -70
  19. package/build/runtime-cjs/routing/components/index.d.ts +0 -1
  20. package/build/runtime-cjs/routing/components/index.js +0 -3
  21. package/build/runtime-cjs/routing/lib/cache.d.ts +1 -1
  22. package/build/runtime-cjs/routing/lib/cache.js +6 -2
  23. package/build/runtime-cjs/routing/lib/types.d.ts +0 -4
  24. package/build/runtime-esm/index.d.ts +6 -3
  25. package/build/runtime-esm/index.js +22 -18
  26. package/build/runtime-esm/routing/components/Router.d.ts +4 -4
  27. package/build/runtime-esm/routing/components/Router.js +173 -69
  28. package/build/runtime-esm/routing/components/index.d.ts +0 -1
  29. package/build/runtime-esm/routing/components/index.js +0 -2
  30. package/build/runtime-esm/routing/lib/cache.d.ts +1 -1
  31. package/build/runtime-esm/routing/lib/cache.js +6 -2
  32. package/build/runtime-esm/routing/lib/types.d.ts +0 -4
  33. package/package.json +3 -12
  34. package/build/plugin/conventions.d.ts +0 -24
  35. package/build/runtime/routing/components/Link.d.ts +0 -5
  36. package/build/runtime-cjs/routing/components/Link.d.ts +0 -5
  37. package/build/runtime-cjs/routing/components/Link.js +0 -51
  38. package/build/runtime-esm/routing/components/Link.d.ts +0 -5
  39. package/build/runtime-esm/routing/components/Link.js +0 -21
  40. package/build/server/compat.d.ts +0 -7
  41. package/build/server/index.d.ts +0 -17
  42. package/build/server/session.d.ts +0 -3
  43. package/build/server-cjs/index.js +0 -166716
  44. package/build/server-cjs/package.json +0 -1
  45. package/build/server-esm/index.js +0 -166707
  46. package/build/server-esm/package.json +0 -1
@@ -7,8 +7,8 @@ import { PendingCache } from './routing/components/Router';
7
7
  import { SuspenseCache } from './routing/lib/cache';
8
8
  export * from './hooks';
9
9
  export * from './routing';
10
- export declare function Router({ cache, intialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, session, }: {
11
- intialURL: string;
10
+ export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, session, assetPrefix, }: {
11
+ initialURL: string;
12
12
  cache: Cache;
13
13
  loaded_queries?: Record<string, {
14
14
  data: GraphQLObject;
@@ -16,6 +16,7 @@ export declare function Router({ cache, intialURL, artifact_cache, component_cac
16
16
  }>;
17
17
  loaded_artifacts?: Record<string, QueryArtifact>;
18
18
  session?: App.Session;
19
+ assetPrefix: string;
19
20
  } & RouterCache): JSX.Element;
20
21
  type RouterCache = {
21
22
  artifact_cache: SuspenseCache<QueryArtifact>;
@@ -24,8 +25,10 @@ type RouterCache = {
24
25
  last_variables: LRUCache<GraphQLVariables>;
25
26
  pending_cache: PendingCache;
26
27
  };
27
- export declare function router_cache({ pending_queries, artifacts, components, }?: {
28
+ export declare function router_cache({ pending_queries, artifacts, components, initialData, initialArtifacts, }?: {
28
29
  pending_queries?: string[];
29
30
  artifacts?: Record<string, QueryArtifact>;
30
31
  components?: Record<string, (props: any) => React.ReactElement>;
32
+ initialData?: Record<string, DocumentStore<GraphQLObject, GraphQLVariables>>;
33
+ initialArtifacts?: Record<string, QueryArtifact>;
31
34
  }): RouterCache;
@@ -5,22 +5,22 @@ import { GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
5
5
  import { QueryArtifact } from '$houdini/runtime/lib/types';
6
6
  import React from 'react';
7
7
  import { SuspenseCache } from '../lib/cache';
8
- import type { NavigationContext, RouterManifest } from '../lib/types';
8
+ import type { RouterManifest } from '../lib/types';
9
9
  /**
10
10
  * Router is the top level entry point for the filesystem-based router.
11
11
  * It is responsible for loading various page sources (including API fetches) and
12
12
  * then rendering when appropriate.
13
13
  */
14
- export declare function Router({ manifest, intialURL, loaded_queries, loaded_artifacts, }: {
14
+ export declare function Router({ manifest, initialURL, loaded_queries, loaded_artifacts, assetPrefix, }: {
15
15
  manifest: RouterManifest;
16
- intialURL?: string;
16
+ initialURL?: string;
17
17
  loaded_queries?: Record<string, {
18
18
  data: GraphQLObject;
19
19
  variables: GraphQLVariables;
20
20
  }>;
21
21
  loaded_artifacts?: Record<string, QueryArtifact>;
22
+ assetPrefix: string;
22
23
  }): JSX.Element;
23
- export declare function useNavigationContext(): NavigationContext;
24
24
  export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, pending_cache, last_variables, session: ssrSession, }: {
25
25
  children: React.ReactElement;
26
26
  client: HoudiniClient;
@@ -1,2 +1 @@
1
- export { Link } from './Link';
2
1
  export { Router, RouterContextProvider, useClient, updateLocalSession } from './Router';
@@ -1,5 +1,5 @@
1
1
  import { LRUCache } from '$houdini/runtime/lib/lru';
2
- export declare function suspense_cache<T>(): SuspenseCache<T>;
2
+ export declare function suspense_cache<T>(initialData?: Record<string, T>): SuspenseCache<T>;
3
3
  export declare class SuspenseCache<_Data> extends LRUCache<_Data> {
4
4
  #private;
5
5
  get(key: string): _Data;
@@ -17,7 +17,3 @@ export type RouterPageManifest = {
17
17
  default: (props: any) => React.ReactElement;
18
18
  }>;
19
19
  };
20
- export type NavigationContext = {
21
- currentRoute: string;
22
- goto: (route: string) => void;
23
- };
@@ -7,8 +7,8 @@ import { PendingCache } from './routing/components/Router';
7
7
  import { SuspenseCache } from './routing/lib/cache';
8
8
  export * from './hooks';
9
9
  export * from './routing';
10
- export declare function Router({ cache, intialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, session, }: {
11
- intialURL: string;
10
+ export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, session, assetPrefix, }: {
11
+ initialURL: string;
12
12
  cache: Cache;
13
13
  loaded_queries?: Record<string, {
14
14
  data: GraphQLObject;
@@ -16,6 +16,7 @@ export declare function Router({ cache, intialURL, artifact_cache, component_cac
16
16
  }>;
17
17
  loaded_artifacts?: Record<string, QueryArtifact>;
18
18
  session?: App.Session;
19
+ assetPrefix: string;
19
20
  } & RouterCache): JSX.Element;
20
21
  type RouterCache = {
21
22
  artifact_cache: SuspenseCache<QueryArtifact>;
@@ -24,8 +25,10 @@ type RouterCache = {
24
25
  last_variables: LRUCache<GraphQLVariables>;
25
26
  pending_cache: PendingCache;
26
27
  };
27
- export declare function router_cache({ pending_queries, artifacts, components, }?: {
28
+ export declare function router_cache({ pending_queries, artifacts, components, initialData, initialArtifacts, }?: {
28
29
  pending_queries?: string[];
29
30
  artifacts?: Record<string, QueryArtifact>;
30
31
  components?: Record<string, (props: any) => React.ReactElement>;
32
+ initialData?: Record<string, DocumentStore<GraphQLObject, GraphQLVariables>>;
33
+ initialArtifacts?: Record<string, QueryArtifact>;
31
34
  }): RouterCache;
@@ -29,7 +29,7 @@ __export(runtime_exports, {
29
29
  router_cache: () => router_cache
30
30
  });
31
31
  module.exports = __toCommonJS(runtime_exports);
32
- var import_react = __toESM(require("react"));
32
+ var import_jsx_runtime = require("react/jsx-runtime");
33
33
  var import_client2 = __toESM(require("./client"));
34
34
  var import_manifest = __toESM(require("./manifest"));
35
35
  var import_routing = require("./routing");
@@ -38,7 +38,7 @@ __reExport(runtime_exports, require("./hooks"), module.exports);
38
38
  __reExport(runtime_exports, require("./routing"), module.exports);
39
39
  function Router({
40
40
  cache,
41
- intialURL,
41
+ initialURL,
42
42
  artifact_cache,
43
43
  component_cache,
44
44
  data_cache,
@@ -46,9 +46,10 @@ function Router({
46
46
  last_variables,
47
47
  loaded_queries,
48
48
  loaded_artifacts,
49
- session
49
+ session,
50
+ assetPrefix
50
51
  }) {
51
- return /* @__PURE__ */ import_react.default.createElement(
52
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
52
53
  import_routing.RouterContextProvider,
53
54
  {
54
55
  client: import_client2.default,
@@ -58,28 +59,31 @@ function Router({
58
59
  data_cache,
59
60
  pending_cache,
60
61
  last_variables,
61
- session
62
- },
63
- /* @__PURE__ */ import_react.default.createElement(
64
- import_routing.Router,
65
- {
66
- intialURL,
67
- manifest: import_manifest.default,
68
- loaded_queries,
69
- loaded_artifacts
70
- }
71
- )
62
+ session,
63
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
64
+ import_routing.Router,
65
+ {
66
+ initialURL,
67
+ manifest: import_manifest.default,
68
+ loaded_queries,
69
+ loaded_artifacts,
70
+ assetPrefix
71
+ }
72
+ )
73
+ }
72
74
  );
73
75
  }
74
76
  function router_cache({
75
77
  pending_queries = [],
76
78
  artifacts = {},
77
- components = {}
79
+ components = {},
80
+ initialData = {},
81
+ initialArtifacts = {}
78
82
  } = {}) {
79
83
  const result = {
80
- artifact_cache: (0, import_cache.suspense_cache)(),
84
+ artifact_cache: (0, import_cache.suspense_cache)(initialArtifacts),
81
85
  component_cache: (0, import_cache.suspense_cache)(),
82
- data_cache: (0, import_cache.suspense_cache)(),
86
+ data_cache: (0, import_cache.suspense_cache)(initialData),
83
87
  pending_cache: (0, import_cache.suspense_cache)(),
84
88
  last_variables: (0, import_cache.suspense_cache)()
85
89
  };
@@ -5,22 +5,22 @@ import { GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
5
5
  import { QueryArtifact } from '$houdini/runtime/lib/types';
6
6
  import React from 'react';
7
7
  import { SuspenseCache } from '../lib/cache';
8
- import type { NavigationContext, RouterManifest } from '../lib/types';
8
+ import type { RouterManifest } from '../lib/types';
9
9
  /**
10
10
  * Router is the top level entry point for the filesystem-based router.
11
11
  * It is responsible for loading various page sources (including API fetches) and
12
12
  * then rendering when appropriate.
13
13
  */
14
- export declare function Router({ manifest, intialURL, loaded_queries, loaded_artifacts, }: {
14
+ export declare function Router({ manifest, initialURL, loaded_queries, loaded_artifacts, assetPrefix, }: {
15
15
  manifest: RouterManifest;
16
- intialURL?: string;
16
+ initialURL?: string;
17
17
  loaded_queries?: Record<string, {
18
18
  data: GraphQLObject;
19
19
  variables: GraphQLVariables;
20
20
  }>;
21
21
  loaded_artifacts?: Record<string, QueryArtifact>;
22
+ assetPrefix: string;
22
23
  }): JSX.Element;
23
- export declare function useNavigationContext(): NavigationContext;
24
24
  export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, pending_cache, last_variables, session: ssrSession, }: {
25
25
  children: React.ReactElement;
26
26
  client: HoudiniClient;
@@ -30,42 +30,51 @@ __export(Router_exports, {
30
30
  useCache: () => useCache,
31
31
  useClient: () => useClient,
32
32
  useCurrentVariables: () => useCurrentVariables,
33
- useNavigationContext: () => useNavigationContext,
34
33
  useQueryResult: () => useQueryResult,
35
34
  useRouterContext: () => useRouterContext,
36
35
  useSession: () => useSession
37
36
  });
38
37
  module.exports = __toCommonJS(Router_exports);
38
+ var import_jsx_runtime = require("react/jsx-runtime");
39
39
  var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
40
40
  var import_react = __toESM(require("react"));
41
41
  var import_react_streaming = require("react-streaming");
42
42
  var import_useDocumentStore = require("../../hooks/useDocumentStore");
43
43
  var import_match = require("../lib/match");
44
- const NavContext = import_react.default.createContext({
45
- currentRoute: "/",
46
- goto: () => {
47
- throw new Error("NOT FOUND");
48
- }
49
- });
44
+ const PreloadWhich = {
45
+ component: "component",
46
+ data: "data",
47
+ page: "page"
48
+ };
50
49
  function Router({
51
50
  manifest,
52
- intialURL,
51
+ initialURL,
53
52
  loaded_queries,
54
- loaded_artifacts
53
+ loaded_artifacts,
54
+ assetPrefix
55
55
  }) {
56
56
  const [current, setCurrent] = import_react.default.useState(() => {
57
- return intialURL || window.location.pathname;
57
+ return initialURL || window.location.pathname;
58
58
  });
59
59
  const [page, variables] = (0, import_match.find_match)(manifest, current);
60
- useLoadPage({ page, variables, loaded_queries, loaded_artifacts });
60
+ const { loadData, loadComponent } = usePageData({
61
+ page,
62
+ variables,
63
+ loaded_queries,
64
+ loaded_artifacts,
65
+ assetPrefix
66
+ });
61
67
  const { component_cache } = useRouterContext();
62
68
  const PageComponent = component_cache.get(page.id);
63
69
  import_react.default.useEffect(() => {
64
- if (window.location.pathname !== current) {
70
+ if (globalThis.window && window.location.pathname !== current) {
65
71
  window.history.pushState({}, "", current);
66
72
  }
67
73
  }, [current]);
68
74
  import_react.default.useEffect(() => {
75
+ if (!globalThis.window) {
76
+ return;
77
+ }
69
78
  const onChange = (evt) => {
70
79
  setCurrent(window.location.pathname);
71
80
  };
@@ -74,22 +83,26 @@ function Router({
74
83
  window.removeEventListener("popstate", onChange);
75
84
  };
76
85
  }, []);
77
- return /* @__PURE__ */ import_react.default.createElement(
78
- NavContext.Provider,
79
- {
80
- value: {
81
- currentRoute: current,
82
- goto: setCurrent
86
+ useLinkBehavior({
87
+ goto: setCurrent,
88
+ preload(url, which) {
89
+ const [page2, variables2] = (0, import_match.find_match)(manifest, url);
90
+ if (["both", "component"].includes(which)) {
91
+ loadComponent(page2);
83
92
  }
84
- },
85
- /* @__PURE__ */ import_react.default.createElement(VariableContext.Provider, { value: variables }, /* @__PURE__ */ import_react.default.createElement(PageComponent, { url: current }))
86
- );
93
+ if (["both", "data"].includes(which)) {
94
+ loadData(page2, variables2);
95
+ }
96
+ }
97
+ });
98
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageComponent, { url: current }) });
87
99
  }
88
- function useLoadPage({
100
+ function usePageData({
89
101
  page,
90
102
  variables,
91
103
  loaded_queries,
92
- loaded_artifacts
104
+ loaded_artifacts,
105
+ assetPrefix
93
106
  }) {
94
107
  const {
95
108
  client,
@@ -131,17 +144,38 @@ function useLoadPage({
131
144
  <script>
132
145
  window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
133
146
 
134
- if (window.__houdini__nav_caches__?.pending_cache.has("${artifact.name}")) {
147
+ const artifactName = "${artifact.name}"
148
+ const value = ${JSON.stringify(observer.state.data)}
149
+
150
+ // if the data is pending, we need to resolve it
151
+ if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
135
152
  // before we resolve the pending signals,
136
153
  // fill the data cache with values we got on the server
137
154
  const new_store = window.__houdini__client__.observe({
138
- artifact: window.__houdini__nav_caches__.artifact_cache.get("${artifact.name}"),
155
+ artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
139
156
  cache: window.__houdini__cache__,
140
- initialValue: ${JSON.stringify(observer.state.data)}
157
+ initialValue: value
141
158
  })
142
159
 
143
- window.__houdini__nav_caches__.data_cache.set("${artifact.name}", new_store)
160
+ window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
161
+ }
162
+
144
163
 
164
+ // if there are no data caches available we need to populate the pending one instead
165
+ if (!window.__houdini__nav_caches__) {
166
+ if (!window.__houdini__pending_data__) {
167
+ window.__houdini__pending_data__ = {}
168
+ }
169
+
170
+ if (!window.__houdini__pending_artifacts__) {
171
+ window.__houdini__pending_artifacts__ = {}
172
+ }
173
+
174
+ window.__houdini__pending_data__[artifactName] = value
175
+ window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
176
+ }
177
+
178
+ if (window.__houdini__nav_caches__?.pending_cache.has(artifactName)) {
145
179
  // we're pushing this store onto the client, it should be initialized
146
180
  new_store.send({
147
181
  setup: true,
@@ -149,8 +183,8 @@ function useLoadPage({
149
183
  })
150
184
 
151
185
  // notify anyone waiting on the pending cache
152
- window.__houdini__nav_caches__.pending_cache.get("${artifact.name}").resolve()
153
- window.__houdini__nav_caches__.pending_cache.delete("${artifact.name}")
186
+ window.__houdini__nav_caches__.pending_cache.get(artifactName).resolve()
187
+ window.__houdini__nav_caches__.pending_cache.delete(artifactName)
154
188
  }
155
189
  <\/script>
156
190
  `);
@@ -162,49 +196,55 @@ function useLoadPage({
162
196
  pending_cache.set(id, { ...promise, resolve, reject });
163
197
  return pending_cache.get(id);
164
198
  }
165
- if (last_variables.has(page.id) && !(0, import_deepEquals.deepEquals)(last_variables.get(page.id), variables)) {
166
- data_cache.clear();
167
- }
168
- const missing_artifacts = [];
169
- const found_artifacts = {};
170
- for (const key of Object.keys(page.documents)) {
171
- if (artifact_cache.has(key)) {
172
- found_artifacts[key] = artifact_cache.get(key);
173
- } else {
174
- missing_artifacts.push(key);
199
+ function loadData(targetPage, variables2) {
200
+ if (last_variables.has(targetPage.id) && !(0, import_deepEquals.deepEquals)(last_variables.get(targetPage.id), variables2)) {
201
+ data_cache.clear();
175
202
  }
176
- }
177
- for (const artifact_id of missing_artifacts) {
178
- page.documents[artifact_id].artifact().then((mod) => {
179
- const artifact = mod.default;
180
- artifact_cache.set(artifact_id, artifact);
181
- if (loaded_artifacts) {
182
- loaded_artifacts[artifact.name] = artifact;
203
+ const missing_artifacts = [];
204
+ const found_artifacts = {};
205
+ for (const key of Object.keys(targetPage.documents)) {
206
+ if (artifact_cache.has(key)) {
207
+ found_artifacts[key] = artifact_cache.get(key);
208
+ } else {
209
+ missing_artifacts.push(key);
183
210
  }
184
- stream?.injectToStream(`
185
- <script type="module" src="@@houdini/artifact/${artifact.name}.js" async=""><\/script>
186
- `);
187
- load_query({ id: artifact.name, artifact });
188
- }).catch((err) => {
189
- console.log(err);
190
- });
211
+ }
212
+ for (const artifact_id of missing_artifacts) {
213
+ targetPage.documents[artifact_id].artifact().then((mod) => {
214
+ const artifact = mod.default;
215
+ artifact_cache.set(artifact_id, artifact);
216
+ if (loaded_artifacts) {
217
+ loaded_artifacts[artifact.name] = artifact;
218
+ }
219
+ stream?.injectToStream(`
220
+ <script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""><\/script>
221
+ `);
222
+ load_query({ id: artifact.name, artifact });
223
+ }).catch((err) => {
224
+ console.log(err);
225
+ });
226
+ }
227
+ for (const artifact of Object.values(found_artifacts)) {
228
+ if (!data_cache.has(artifact.name)) {
229
+ load_query({ id: artifact.name, artifact });
230
+ }
231
+ }
191
232
  }
192
- for (const artifact of Object.values(found_artifacts)) {
193
- if (!data_cache.has(artifact.name)) {
194
- load_query({ id: artifact.name, artifact });
233
+ async function loadComponent(targetPage) {
234
+ if (component_cache.has(targetPage.id)) {
235
+ return;
195
236
  }
237
+ const mod = await targetPage.component();
238
+ component_cache.set(targetPage.id, mod.default);
196
239
  }
240
+ loadData(page, variables);
197
241
  if (!component_cache.has(page.id)) {
198
- throw new Promise((resolve, reject) => {
199
- page.component().then((mod) => {
200
- component_cache.set(page.id, mod.default);
201
- resolve();
202
- }).catch(reject);
203
- });
242
+ throw loadComponent(page);
204
243
  }
205
- }
206
- function useNavigationContext() {
207
- return import_react.default.useContext(NavContext);
244
+ return {
245
+ loadData,
246
+ loadComponent
247
+ };
208
248
  }
209
249
  function RouterContextProvider({
210
250
  children,
@@ -227,7 +267,7 @@ function RouterContextProvider({
227
267
  window.removeEventListener("_houdini_session_", handleNewSession);
228
268
  };
229
269
  }, []);
230
- return /* @__PURE__ */ import_react.default.createElement(
270
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
231
271
  Context.Provider,
232
272
  {
233
273
  value: {
@@ -239,9 +279,9 @@ function RouterContextProvider({
239
279
  pending_cache,
240
280
  last_variables,
241
281
  session
242
- }
243
- },
244
- children
282
+ },
283
+ children
284
+ }
245
285
  );
246
286
  }
247
287
  const Context = import_react.default.createContext(null);
@@ -281,6 +321,70 @@ function useQueryResult(name) {
281
321
  });
282
322
  return [data, observer];
283
323
  }
324
+ function useLinkBehavior({
325
+ goto,
326
+ preload
327
+ }) {
328
+ useLinkNavigation({ goto });
329
+ if (!globalThis.navigator?.connection?.saveData) {
330
+ usePreload({ preload });
331
+ }
332
+ }
333
+ function useLinkNavigation({ goto }) {
334
+ const [pending, startTransition] = import_react.default.useTransition();
335
+ import_react.default.useEffect(() => {
336
+ const onClick = (e) => {
337
+ const link = e.target?.closest("a");
338
+ if (link && link instanceof HTMLAnchorElement && link.href && (!link.target || link.target === "_self") && link.origin === location.origin && !link.hasAttribute("download") && e.button === 0 && !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.defaultPrevented) {
339
+ const target = link.attributes.getNamedItem("href")?.value;
340
+ if (!target || !target.startsWith("/")) {
341
+ return;
342
+ }
343
+ e.preventDefault();
344
+ startTransition(() => {
345
+ goto(target);
346
+ });
347
+ }
348
+ };
349
+ document.addEventListener("click", onClick);
350
+ return () => {
351
+ document.removeEventListener("click", onClick);
352
+ };
353
+ }, []);
354
+ }
355
+ function usePreload({ preload }) {
356
+ const timeoutRef = import_react.default.useRef(null);
357
+ import_react.default.useEffect(() => {
358
+ const mouseMove = (e) => {
359
+ const target = e.target;
360
+ if (!(target instanceof HTMLAnchorElement)) {
361
+ return;
362
+ }
363
+ let preloadWhichRaw = target.attributes.getNamedItem("data-houdini-preload")?.value;
364
+ let preloadWhich = !preloadWhichRaw || preloadWhichRaw === "true" ? "page" : preloadWhichRaw;
365
+ if (!PreloadWhich[preloadWhich]) {
366
+ console.log(
367
+ `invalid preload value "${preloadWhich}" must be "${PreloadWhich.component}", "${PreloadWhich.data}", or "${PreloadWhich.page}"`
368
+ );
369
+ return;
370
+ }
371
+ if (timeoutRef.current) {
372
+ clearTimeout(timeoutRef.current);
373
+ }
374
+ timeoutRef.current = setTimeout(() => {
375
+ const url = target.attributes.getNamedItem("href")?.value;
376
+ if (!url) {
377
+ return;
378
+ }
379
+ preload(url, preloadWhich);
380
+ }, 20);
381
+ };
382
+ document.addEventListener("mousemove", mouseMove);
383
+ return () => {
384
+ document.removeEventListener("mousemove", mouseMove);
385
+ };
386
+ }, []);
387
+ }
284
388
  // Annotate the CommonJS export names for ESM import in node:
285
389
  0 && (module.exports = {
286
390
  Router,
@@ -289,7 +393,6 @@ function useQueryResult(name) {
289
393
  useCache,
290
394
  useClient,
291
395
  useCurrentVariables,
292
- useNavigationContext,
293
396
  useQueryResult,
294
397
  useRouterContext,
295
398
  useSession
@@ -1,2 +1 @@
1
- export { Link } from './Link';
2
1
  export { Router, RouterContextProvider, useClient, updateLocalSession } from './Router';
@@ -18,18 +18,15 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var components_exports = {};
20
20
  __export(components_exports, {
21
- Link: () => import_Link.Link,
22
21
  Router: () => import_Router.Router,
23
22
  RouterContextProvider: () => import_Router.RouterContextProvider,
24
23
  updateLocalSession: () => import_Router.updateLocalSession,
25
24
  useClient: () => import_Router.useClient
26
25
  });
27
26
  module.exports = __toCommonJS(components_exports);
28
- var import_Link = require("./Link");
29
27
  var import_Router = require("./Router");
30
28
  // Annotate the CommonJS export names for ESM import in node:
31
29
  0 && (module.exports = {
32
- Link,
33
30
  Router,
34
31
  RouterContextProvider,
35
32
  updateLocalSession,
@@ -1,5 +1,5 @@
1
1
  import { LRUCache } from '$houdini/runtime/lib/lru';
2
- export declare function suspense_cache<T>(): SuspenseCache<T>;
2
+ export declare function suspense_cache<T>(initialData?: Record<string, T>): SuspenseCache<T>;
3
3
  export declare class SuspenseCache<_Data> extends LRUCache<_Data> {
4
4
  #private;
5
5
  get(key: string): _Data;
@@ -23,8 +23,12 @@ __export(cache_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(cache_exports);
25
25
  var import_lru = require("$houdini/runtime/lib/lru");
26
- function suspense_cache() {
27
- return new SuspenseCache();
26
+ function suspense_cache(initialData) {
27
+ const cache = new SuspenseCache();
28
+ for (const [key, value] of Object.entries(initialData ?? {})) {
29
+ cache.set(key, value);
30
+ }
31
+ return cache;
28
32
  }
29
33
  class SuspenseCache extends import_lru.LRUCache {
30
34
  #callbacks = /* @__PURE__ */ new Map();
@@ -17,7 +17,3 @@ export type RouterPageManifest = {
17
17
  default: (props: any) => React.ReactElement;
18
18
  }>;
19
19
  };
20
- export type NavigationContext = {
21
- currentRoute: string;
22
- goto: (route: string) => void;
23
- };
@@ -7,8 +7,8 @@ import { PendingCache } from './routing/components/Router';
7
7
  import { SuspenseCache } from './routing/lib/cache';
8
8
  export * from './hooks';
9
9
  export * from './routing';
10
- export declare function Router({ cache, intialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, session, }: {
11
- intialURL: string;
10
+ export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, session, assetPrefix, }: {
11
+ initialURL: string;
12
12
  cache: Cache;
13
13
  loaded_queries?: Record<string, {
14
14
  data: GraphQLObject;
@@ -16,6 +16,7 @@ export declare function Router({ cache, intialURL, artifact_cache, component_cac
16
16
  }>;
17
17
  loaded_artifacts?: Record<string, QueryArtifact>;
18
18
  session?: App.Session;
19
+ assetPrefix: string;
19
20
  } & RouterCache): JSX.Element;
20
21
  type RouterCache = {
21
22
  artifact_cache: SuspenseCache<QueryArtifact>;
@@ -24,8 +25,10 @@ type RouterCache = {
24
25
  last_variables: LRUCache<GraphQLVariables>;
25
26
  pending_cache: PendingCache;
26
27
  };
27
- export declare function router_cache({ pending_queries, artifacts, components, }?: {
28
+ export declare function router_cache({ pending_queries, artifacts, components, initialData, initialArtifacts, }?: {
28
29
  pending_queries?: string[];
29
30
  artifacts?: Record<string, QueryArtifact>;
30
31
  components?: Record<string, (props: any) => React.ReactElement>;
32
+ initialData?: Record<string, DocumentStore<GraphQLObject, GraphQLVariables>>;
33
+ initialArtifacts?: Record<string, QueryArtifact>;
31
34
  }): RouterCache;