houdini-react 1.3.6 → 1.3.8

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.
@@ -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,
@@ -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);
@@ -530,12 +489,7 @@ export {
530
489
  RouterContextProvider,
531
490
  router_cache,
532
491
  updateLocalSession,
533
- useCache,
534
- useClient,
535
492
  useCurrentVariables,
536
- useLocation,
537
493
  useQueryResult,
538
- useRoute,
539
- useRouterContext,
540
- useSession
494
+ useRoute
541
495
  };
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini-react",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "The React plugin for houdini",
5
5
  "keywords": [
6
6
  "typescript",
@@ -42,7 +42,7 @@
42
42
  "recast": "^0.23.1",
43
43
  "rollup": "^4.28.1",
44
44
  "use-deep-compare-effect": "^1.8.1",
45
- "houdini": "^1.5.2"
45
+ "houdini": "^1.5.4"
46
46
  },
47
47
  "files": [
48
48
  "build"