houdini-react 1.2.43 → 1.2.45
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.
- package/build/plugin-cjs/index.js +884 -883
- package/build/plugin-esm/index.js +884 -883
- package/build/runtime/hooks/useDocumentStore.d.ts +1 -2
- package/build/runtime/hooks/useDocumentSubscription.d.ts +3 -7
- package/build/runtime/index.d.ts +1 -1
- package/build/runtime/routing/Router.d.ts +16 -1
- package/build/runtime-cjs/hooks/useDocumentHandle.js +1 -1
- package/build/runtime-cjs/hooks/useDocumentStore.d.ts +1 -2
- package/build/runtime-cjs/hooks/useDocumentStore.js +5 -1
- package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +3 -7
- package/build/runtime-cjs/hooks/useDocumentSubscription.js +3 -4
- package/build/runtime-cjs/hooks/useMutation.js +1 -1
- package/build/runtime-cjs/index.d.ts +1 -1
- package/build/runtime-cjs/index.js +8 -2
- package/build/runtime-cjs/routing/Router.d.ts +16 -1
- package/build/runtime-cjs/routing/Router.js +85 -13
- package/build/runtime-esm/hooks/useDocumentHandle.js +1 -1
- package/build/runtime-esm/hooks/useDocumentStore.d.ts +1 -2
- package/build/runtime-esm/hooks/useDocumentStore.js +5 -1
- package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +3 -7
- package/build/runtime-esm/hooks/useDocumentSubscription.js +3 -4
- package/build/runtime-esm/hooks/useMutation.js +1 -1
- package/build/runtime-esm/index.d.ts +1 -1
- package/build/runtime-esm/index.js +5 -2
- package/build/runtime-esm/routing/Router.d.ts +16 -1
- package/build/runtime-esm/routing/Router.js +82 -13
- package/package.json +2 -2
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import configFile from "$houdini/runtime/imports/config";
|
|
2
3
|
import { deepEquals } from "$houdini/runtime/lib/deepEquals";
|
|
4
|
+
import { marshalSelection, marshalInputs } from "$houdini/runtime/lib/scalars";
|
|
3
5
|
import { find_match } from "$houdini/runtime/router/match";
|
|
4
6
|
import React from "react";
|
|
7
|
+
import { useContext } from "react";
|
|
5
8
|
import { useDocumentStore } from "../hooks/useDocumentStore";
|
|
6
9
|
import { suspense_cache } from "./cache";
|
|
7
10
|
const PreloadWhich = {
|
|
@@ -19,6 +22,9 @@ function Router({
|
|
|
19
22
|
return initialURL || window.location.pathname;
|
|
20
23
|
});
|
|
21
24
|
const [page, variables] = find_match(manifest, currentURL);
|
|
25
|
+
if (!page) {
|
|
26
|
+
throw new Error("404");
|
|
27
|
+
}
|
|
22
28
|
const { loadData, loadComponent } = usePageData({
|
|
23
29
|
page,
|
|
24
30
|
variables,
|
|
@@ -58,8 +64,9 @@ function Router({
|
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
});
|
|
61
|
-
return /* @__PURE__ */ jsx(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ jsx(PageComponent, { url: currentURL }, page.id) });
|
|
67
|
+
return /* @__PURE__ */ jsx(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ jsx(LocationContext.Provider, { value: { pathname: currentURL, params: variables ?? {} }, children: /* @__PURE__ */ jsx(PageComponent, { url: currentURL }, page.id) }) });
|
|
62
68
|
}
|
|
69
|
+
const useLocation = () => useContext(LocationContext);
|
|
63
70
|
function usePageData({
|
|
64
71
|
page,
|
|
65
72
|
variables,
|
|
@@ -75,7 +82,7 @@ function usePageData({
|
|
|
75
82
|
ssr_signals,
|
|
76
83
|
last_variables
|
|
77
84
|
} = useRouterContext();
|
|
78
|
-
const session = useSession();
|
|
85
|
+
const [session] = useSession();
|
|
79
86
|
function load_query({ id, artifact }) {
|
|
80
87
|
for (const artifact2 of Object.keys(page.documents)) {
|
|
81
88
|
last_variables.set(artifact2, variables);
|
|
@@ -95,7 +102,7 @@ function usePageData({
|
|
|
95
102
|
variables,
|
|
96
103
|
cacheParams: { disableSubscriptions: true },
|
|
97
104
|
session
|
|
98
|
-
}).then(() => {
|
|
105
|
+
}).then(async () => {
|
|
99
106
|
data_cache.set(id, observer);
|
|
100
107
|
if (observer.state.errors && observer.state.errors.length > 0) {
|
|
101
108
|
reject(observer.state.errors.map((e) => e.message).join("\n"));
|
|
@@ -107,7 +114,12 @@ function usePageData({
|
|
|
107
114
|
window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
|
|
108
115
|
|
|
109
116
|
const artifactName = "${artifact.name}"
|
|
110
|
-
const value = ${JSON.stringify(
|
|
117
|
+
const value = ${JSON.stringify(
|
|
118
|
+
await marshalSelection({
|
|
119
|
+
selection: observer.artifact.selection,
|
|
120
|
+
data: observer.state.data
|
|
121
|
+
})
|
|
122
|
+
)}
|
|
111
123
|
|
|
112
124
|
// if the data is pending, we need to resolve it
|
|
113
125
|
if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
|
|
@@ -116,7 +128,18 @@ function usePageData({
|
|
|
116
128
|
const new_store = window.__houdini__client__.observe({
|
|
117
129
|
artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
|
|
118
130
|
cache: window.__houdini__cache__,
|
|
119
|
-
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
// we're pushing this store onto the client, it should be initialized
|
|
134
|
+
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
|
|
135
|
+
setup: true,
|
|
136
|
+
variables: ${JSON.stringify(
|
|
137
|
+
marshalInputs({
|
|
138
|
+
artifact: observer.artifact,
|
|
139
|
+
input: variables,
|
|
140
|
+
config: configFile
|
|
141
|
+
})
|
|
142
|
+
)}
|
|
120
143
|
})
|
|
121
144
|
|
|
122
145
|
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
|
|
@@ -136,12 +159,12 @@ function usePageData({
|
|
|
136
159
|
if (!window.__houdini__pending_artifacts__) {
|
|
137
160
|
window.__houdini__pending_artifacts__ = {}
|
|
138
161
|
}
|
|
139
|
-
|
|
140
|
-
window.__houdini__pending_variables__[artifactName] = ${JSON.stringify(variables)}
|
|
141
|
-
window.__houdini__pending_data__[artifactName] = value
|
|
142
|
-
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
|
|
143
162
|
}
|
|
144
163
|
|
|
164
|
+
window.__houdini__pending_variables__[artifactName] = ${JSON.stringify(observer.state.variables)}
|
|
165
|
+
window.__houdini__pending_data__[artifactName] = value
|
|
166
|
+
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
|
|
167
|
+
|
|
145
168
|
// if this payload finishes off an ssr request, we need to resolve the signal
|
|
146
169
|
if (window.__houdini__nav_caches__?.ssr_signals.has(artifactName)) {
|
|
147
170
|
|
|
@@ -150,7 +173,13 @@ function usePageData({
|
|
|
150
173
|
// we're pushing this store onto the client, it should be initialized
|
|
151
174
|
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
|
|
152
175
|
setup: true,
|
|
153
|
-
variables: ${JSON.stringify(
|
|
176
|
+
variables: ${JSON.stringify(
|
|
177
|
+
marshalInputs({
|
|
178
|
+
artifact: observer.artifact,
|
|
179
|
+
input: variables,
|
|
180
|
+
config: configFile
|
|
181
|
+
})
|
|
182
|
+
)}
|
|
154
183
|
})
|
|
155
184
|
}
|
|
156
185
|
|
|
@@ -180,7 +209,7 @@ function usePageData({
|
|
|
180
209
|
}
|
|
181
210
|
let last = {};
|
|
182
211
|
let usedVariables = {};
|
|
183
|
-
for (const variable of pageVariables) {
|
|
212
|
+
for (const variable of Object.keys(pageVariables)) {
|
|
184
213
|
last[variable] = last_variables.get(artifact)[variable];
|
|
185
214
|
usedVariables[variable] = (variables2 ?? {})[variable];
|
|
186
215
|
}
|
|
@@ -263,7 +292,8 @@ function RouterContextProvider({
|
|
|
263
292
|
data_cache,
|
|
264
293
|
ssr_signals,
|
|
265
294
|
last_variables,
|
|
266
|
-
session
|
|
295
|
+
session,
|
|
296
|
+
setSession: (newSession) => setSession((old) => ({ ...old, ...newSession }))
|
|
267
297
|
},
|
|
268
298
|
children
|
|
269
299
|
}
|
|
@@ -292,12 +322,34 @@ function updateLocalSession(session) {
|
|
|
292
322
|
);
|
|
293
323
|
}
|
|
294
324
|
function useSession() {
|
|
295
|
-
|
|
325
|
+
const ctx = useRouterContext();
|
|
326
|
+
const updateSession = (newSession) => {
|
|
327
|
+
ctx.data_cache.clear();
|
|
328
|
+
ctx.setSession(newSession);
|
|
329
|
+
const auth = configFile.router?.auth;
|
|
330
|
+
if (!auth) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const url = "redirect" in auth ? auth.redirect : auth.url;
|
|
334
|
+
fetch(url, {
|
|
335
|
+
method: "POST",
|
|
336
|
+
body: JSON.stringify(newSession),
|
|
337
|
+
headers: {
|
|
338
|
+
"Content-Type": "application/json",
|
|
339
|
+
Accept: "application/json"
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
return [ctx.session, updateSession];
|
|
296
344
|
}
|
|
297
345
|
function useCurrentVariables() {
|
|
298
346
|
return React.useContext(VariableContext);
|
|
299
347
|
}
|
|
300
348
|
const VariableContext = React.createContext(null);
|
|
349
|
+
const LocationContext = React.createContext({
|
|
350
|
+
pathname: "",
|
|
351
|
+
params: {}
|
|
352
|
+
});
|
|
301
353
|
function useQueryResult(name) {
|
|
302
354
|
const store_ref = useRouterContext().data_cache.get(name);
|
|
303
355
|
const [{ data, errors }, observer] = useDocumentStore({
|
|
@@ -407,6 +459,20 @@ function router_cache({
|
|
|
407
459
|
}
|
|
408
460
|
return result;
|
|
409
461
|
}
|
|
462
|
+
const PageContext = React.createContext({ params: {} });
|
|
463
|
+
function PageContextProvider({
|
|
464
|
+
keys,
|
|
465
|
+
children
|
|
466
|
+
}) {
|
|
467
|
+
const location2 = useLocation();
|
|
468
|
+
const params = Object.fromEntries(
|
|
469
|
+
Object.entries(location2.params).filter(([key]) => keys.includes(key))
|
|
470
|
+
);
|
|
471
|
+
return /* @__PURE__ */ jsx(PageContext.Provider, { value: { params }, children });
|
|
472
|
+
}
|
|
473
|
+
function useRoute() {
|
|
474
|
+
return useContext(PageContext);
|
|
475
|
+
}
|
|
410
476
|
function signal_promise() {
|
|
411
477
|
let resolve = () => {
|
|
412
478
|
};
|
|
@@ -423,6 +489,7 @@ function signal_promise() {
|
|
|
423
489
|
};
|
|
424
490
|
}
|
|
425
491
|
export {
|
|
492
|
+
PageContextProvider,
|
|
426
493
|
Router,
|
|
427
494
|
RouterContextProvider,
|
|
428
495
|
router_cache,
|
|
@@ -430,7 +497,9 @@ export {
|
|
|
430
497
|
useCache,
|
|
431
498
|
useClient,
|
|
432
499
|
useCurrentVariables,
|
|
500
|
+
useLocation,
|
|
433
501
|
useQueryResult,
|
|
502
|
+
useRoute,
|
|
434
503
|
useRouterContext,
|
|
435
504
|
useSession
|
|
436
505
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "houdini-react",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.45",
|
|
4
4
|
"description": "The React plugin for houdini",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"recast": "^0.23.1",
|
|
44
44
|
"rollup": "^3.7.4",
|
|
45
45
|
"use-deep-compare-effect": "^1.8.1",
|
|
46
|
-
"houdini": "^1.2.
|
|
46
|
+
"houdini": "^1.2.45"
|
|
47
47
|
},
|
|
48
48
|
"files": [
|
|
49
49
|
"build"
|