houdini-react 1.3.7 → 2.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/build/plugin/index.d.ts +1 -3
  2. package/build/plugin/state.d.ts +3 -0
  3. package/build/plugin/vite.d.ts +1 -44
  4. package/build/plugin-cjs/index.js +34065 -28140
  5. package/build/plugin-esm/index.js +32507 -26576
  6. package/build/runtime/hooks/index.d.ts +1 -1
  7. package/build/runtime/hooks/useMutation.d.ts +3 -0
  8. package/build/runtime/routing/Router.d.ts +6 -32
  9. package/build/runtime/routing/hooks.d.ts +40 -0
  10. package/build/runtime/routing/index.d.ts +1 -0
  11. package/build/runtime-cjs/client.js +0 -2
  12. package/build/runtime-cjs/clientPlugin.js +0 -2
  13. package/build/runtime-cjs/hooks/index.d.ts +1 -1
  14. package/build/runtime-cjs/hooks/index.js +2 -2
  15. package/build/runtime-cjs/hooks/useDeepCompareEffect.js +4 -0
  16. package/build/runtime-cjs/hooks/useDocumentHandle.js +8 -4
  17. package/build/runtime-cjs/hooks/useDocumentStore.js +6 -2
  18. package/build/runtime-cjs/hooks/useDocumentSubscription.js +7 -2
  19. package/build/runtime-cjs/hooks/useFragment.js +5 -0
  20. package/build/runtime-cjs/hooks/useMutation.d.ts +3 -0
  21. package/build/runtime-cjs/hooks/useMutation.js +26 -11
  22. package/build/runtime-cjs/hooks/useQueryHandle.js +6 -0
  23. package/build/runtime-cjs/index.js +10 -5
  24. package/build/runtime-cjs/manifest.js +0 -2
  25. package/build/runtime-cjs/routing/Router.d.ts +6 -32
  26. package/build/runtime-cjs/routing/Router.js +22 -65
  27. package/build/runtime-cjs/routing/cache.js +3 -0
  28. package/build/runtime-cjs/routing/hooks.d.ts +40 -0
  29. package/build/runtime-cjs/routing/hooks.js +93 -0
  30. package/build/runtime-cjs/routing/index.d.ts +1 -0
  31. package/build/runtime-cjs/routing/index.js +4 -1
  32. package/build/runtime-esm/hooks/index.d.ts +1 -1
  33. package/build/runtime-esm/hooks/index.js +2 -3
  34. package/build/runtime-esm/hooks/useDocumentHandle.js +1 -1
  35. package/build/runtime-esm/hooks/useDocumentStore.js +1 -1
  36. package/build/runtime-esm/hooks/useDocumentSubscription.js +2 -1
  37. package/build/runtime-esm/hooks/useFragment.js +1 -0
  38. package/build/runtime-esm/hooks/useMutation.d.ts +3 -0
  39. package/build/runtime-esm/hooks/useMutation.js +24 -10
  40. package/build/runtime-esm/hooks/useQueryHandle.js +2 -0
  41. package/build/runtime-esm/routing/Router.d.ts +6 -32
  42. package/build/runtime-esm/routing/Router.js +10 -52
  43. package/build/runtime-esm/routing/cache.js +3 -0
  44. package/build/runtime-esm/routing/hooks.d.ts +40 -0
  45. package/build/runtime-esm/routing/hooks.js +53 -0
  46. package/build/runtime-esm/routing/index.d.ts +1 -0
  47. package/build/runtime-esm/routing/index.js +1 -0
  48. package/build/server-cjs/index.js +3 -3
  49. package/package.json +4 -4
@@ -5,9 +5,10 @@ import { marshalSelection, marshalInputs } from "$houdini/runtime/lib/scalars";
5
5
  import { find_match } from "$houdini/runtime/router/match";
6
6
  import React from "react";
7
7
  import { useContext } from "react";
8
+ import { suspense_cache } from "./cache";
8
9
  import { useDocumentHandle } from "../hooks/useDocumentHandle";
9
10
  import { useDocumentStore } from "../hooks/useDocumentStore";
10
- import { suspense_cache } from "./cache";
11
+ import { Context, useRouterContext, useSession, useLocation, LocationContext } from "./hooks";
11
12
  const PreloadWhich = {
12
13
  component: "component",
13
14
  data: "data",
@@ -82,7 +83,6 @@ function Router({
82
83
  }
83
84
  ) });
84
85
  }
85
- const useLocation = () => useContext(LocationContext);
86
86
  function usePageData({
87
87
  page,
88
88
  variables,
@@ -209,7 +209,7 @@ function usePageData({
209
209
  window.__houdini__nav_caches__.ssr_signals.delete(artifactName)
210
210
  }
211
211
  }
212
- <\/script>
212
+ </script>
213
213
  `);
214
214
  resolve();
215
215
  }).catch(reject);
@@ -254,7 +254,7 @@ function usePageData({
254
254
  const artifact = mod.default;
255
255
  artifact_cache.set(artifact_id, artifact);
256
256
  injectToStream?.(`
257
- <script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""><\/script>
257
+ <script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""></script>
258
258
  `);
259
259
  load_query({ id: artifact.name, artifact, variables: variables2 });
260
260
  }).catch((err) => {
@@ -322,20 +322,6 @@ function RouterContextProvider({
322
322
  }
323
323
  );
324
324
  }
325
- const Context = React.createContext(null);
326
- const useRouterContext = () => {
327
- const ctx = React.useContext(Context);
328
- if (!ctx) {
329
- throw new Error("Could not find router context");
330
- }
331
- return ctx;
332
- };
333
- function useClient() {
334
- return useRouterContext().client;
335
- }
336
- function useCache() {
337
- return useRouterContext().cache;
338
- }
339
325
  function updateLocalSession(session) {
340
326
  window.dispatchEvent(
341
327
  new CustomEvent("_houdini_session_", {
@@ -344,37 +330,10 @@ function updateLocalSession(session) {
344
330
  })
345
331
  );
346
332
  }
347
- function useSession() {
348
- const ctx = useRouterContext();
349
- const updateSession = (newSession) => {
350
- ctx.data_cache.clear();
351
- ctx.setSession(newSession);
352
- const auth = configFile.router?.auth;
353
- if (!auth) {
354
- return;
355
- }
356
- const url = "redirect" in auth ? auth.redirect : auth.url;
357
- fetch(url, {
358
- method: "POST",
359
- body: JSON.stringify(newSession),
360
- headers: {
361
- "Content-Type": "application/json",
362
- Accept: "application/json"
363
- }
364
- });
365
- };
366
- return [ctx.session, updateSession];
367
- }
368
333
  function useCurrentVariables() {
369
334
  return React.useContext(VariableContext);
370
335
  }
371
336
  const VariableContext = React.createContext(null);
372
- const LocationContext = React.createContext({
373
- pathname: "",
374
- params: {},
375
- goto: () => {
376
- }
377
- });
378
337
  function useQueryResult(name) {
379
338
  const { data_cache, artifact_cache } = useRouterContext();
380
339
  const store_ref = data_cache.get(name);
@@ -410,7 +369,11 @@ function useLinkNavigation({ goto }) {
410
369
  return;
411
370
  }
412
371
  const link = e.target?.closest("a");
413
- 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)) {
372
+ if (!(link && link instanceof HTMLAnchorElement && link.href && (!link.target || link.target === "_self") && link.origin === location.origin && !link.hasAttribute("download") && e.button === 0 && // left clicks only
373
+ !e.metaKey && // open in new tab (mac)
374
+ !e.ctrlKey && // open in new tab (windows)
375
+ !e.altKey && // download
376
+ !e.shiftKey && !e.defaultPrevented)) {
414
377
  return;
415
378
  }
416
379
  const target = link.attributes.getNamedItem("href")?.value;
@@ -530,12 +493,7 @@ export {
530
493
  RouterContextProvider,
531
494
  router_cache,
532
495
  updateLocalSession,
533
- useCache,
534
- useClient,
535
496
  useCurrentVariables,
536
- useLocation,
537
497
  useQueryResult,
538
- useRoute,
539
- useRouterContext,
540
- useSession
498
+ useRoute
541
499
  };
@@ -7,6 +7,8 @@ function suspense_cache(initialData) {
7
7
  return cache;
8
8
  }
9
9
  class SuspenseCache extends LRUCache {
10
+ // if get is called before set, we need to invoke a callback.
11
+ // that means we need a place to put our callbacks
10
12
  #callbacks = /* @__PURE__ */ new Map();
11
13
  get(key) {
12
14
  if (super.has(key)) {
@@ -16,6 +18,7 @@ class SuspenseCache extends LRUCache {
16
18
  this.#subscribe(key, resolve, reject);
17
19
  });
18
20
  }
21
+ // TODO: reject?
19
22
  set(key, value) {
20
23
  super.set(key, value);
21
24
  if (this.#callbacks.has(key)) {
@@ -0,0 +1,40 @@
1
+ import type { Cache } from '$houdini/runtime/cache/cache';
2
+ import type { DocumentStore, HoudiniClient } from '$houdini/runtime/client';
3
+ import type { LRUCache } from '$houdini/runtime/lib/lru';
4
+ import type { GraphQLObject, GraphQLVariables, QueryArtifact } from '$houdini/runtime/lib/types';
5
+ import { default as React } from 'react';
6
+ import type { SuspenseCache } from './cache';
7
+ export type PageComponent = React.ComponentType<{
8
+ url: string;
9
+ }>;
10
+ export type PendingCache = SuspenseCache<Promise<void> & {
11
+ resolve: () => void;
12
+ reject: (message: string) => void;
13
+ }>;
14
+ type RouterContext = {
15
+ client: HoudiniClient;
16
+ cache: Cache;
17
+ artifact_cache: SuspenseCache<QueryArtifact>;
18
+ component_cache: SuspenseCache<PageComponent>;
19
+ data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
20
+ ssr_signals: PendingCache;
21
+ last_variables: LRUCache<GraphQLVariables>;
22
+ session: App.Session;
23
+ setSession: (newSession: Partial<App.Session>) => void;
24
+ };
25
+ export declare const Context: React.Context<RouterContext | null>;
26
+ export declare const LocationContext: React.Context<{
27
+ pathname: string;
28
+ params: Record<string, any>;
29
+ goto: (url: string) => void;
30
+ }>;
31
+ export declare const useLocation: () => {
32
+ pathname: string;
33
+ params: Record<string, any>;
34
+ goto: (url: string) => void;
35
+ };
36
+ export declare const useRouterContext: () => RouterContext;
37
+ export declare function useClient(): HoudiniClient;
38
+ export declare function useCache(): Cache;
39
+ export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
40
+ export {};
@@ -0,0 +1,53 @@
1
+ import configFile from "$houdini/runtime/imports/config";
2
+ import { useContext, default as React } from "react";
3
+ const Context = React.createContext(null);
4
+ const LocationContext = React.createContext({
5
+ pathname: "",
6
+ params: {},
7
+ goto: () => {
8
+ }
9
+ });
10
+ const useLocation = () => useContext(LocationContext);
11
+ const useRouterContext = () => {
12
+ const ctx = React.useContext(Context);
13
+ if (!ctx) {
14
+ throw new Error("Could not find router context");
15
+ }
16
+ return ctx;
17
+ };
18
+ function useClient() {
19
+ return useRouterContext().client;
20
+ }
21
+ function useCache() {
22
+ return useRouterContext().cache;
23
+ }
24
+ function useSession() {
25
+ const ctx = useRouterContext();
26
+ const updateSession = (newSession) => {
27
+ ctx.data_cache.clear();
28
+ ctx.setSession(newSession);
29
+ const auth = configFile.router?.auth;
30
+ if (!auth) {
31
+ return;
32
+ }
33
+ const url = "redirect" in auth ? auth.redirect : auth.url;
34
+ fetch(url, {
35
+ method: "POST",
36
+ body: JSON.stringify(newSession),
37
+ headers: {
38
+ "Content-Type": "application/json",
39
+ Accept: "application/json"
40
+ }
41
+ });
42
+ };
43
+ return [ctx.session, updateSession];
44
+ }
45
+ export {
46
+ Context,
47
+ LocationContext,
48
+ useCache,
49
+ useClient,
50
+ useLocation,
51
+ useRouterContext,
52
+ useSession
53
+ };
@@ -1,2 +1,3 @@
1
1
  export * from './Router';
2
+ export * from './hooks';
2
3
  export { type SuspenseCache, suspense_cache } from './cache';
@@ -1,4 +1,5 @@
1
1
  export * from "./Router";
2
+ export * from "./hooks";
2
3
  import { suspense_cache } from "./cache";
3
4
  export {
4
5
  suspense_cache
@@ -16,11 +16,11 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var server_exports = {};
20
- __export(server_exports, {
19
+ var index_exports = {};
20
+ __export(index_exports, {
21
21
  renderToStream: () => import_server.renderToStream
22
22
  });
23
- module.exports = __toCommonJS(server_exports);
23
+ module.exports = __toCommonJS(index_exports);
24
24
  var import_server = require("react-streaming-compat/server");
25
25
  // Annotate the CommonJS export names for ESM import in node:
26
26
  0 && (module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini-react",
3
- "version": "1.3.7",
3
+ "version": "2.0.0-next.0",
4
4
  "description": "The React plugin for houdini",
5
5
  "keywords": [
6
6
  "typescript",
@@ -34,15 +34,15 @@
34
34
  "cookies": "^0.8.0",
35
35
  "estraverse": "^5.3.0",
36
36
  "express": "^4.18.2",
37
- "graphql": "^15.8.0",
37
+ "graphql": "^16.10.0",
38
38
  "graphql-yoga": "^4.0.4",
39
39
  "react": "^19.0.0",
40
40
  "react-dom": "^19.0.0",
41
41
  "react-streaming-compat": "^0.3.18",
42
42
  "recast": "^0.23.1",
43
- "rollup": "^4.28.1",
43
+ "rollup": "^4.39.0",
44
44
  "use-deep-compare-effect": "^1.8.1",
45
- "houdini": "^1.5.3"
45
+ "houdini": "^2.0.0-next.0"
46
46
  },
47
47
  "files": [
48
48
  "build"