houdini-react 1.2.44 → 1.2.46
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 +871 -868
- package/build/plugin-esm/index.js +871 -868
- package/build/runtime/hooks/useDocumentHandle.d.ts +2 -0
- package/build/runtime/index.d.ts +1 -1
- package/build/runtime/routing/Router.d.ts +13 -1
- package/build/runtime-cjs/clientPlugin.js +1 -1
- package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +2 -0
- package/build/runtime-cjs/hooks/useDocumentHandle.js +20 -5
- package/build/runtime-cjs/index.d.ts +1 -1
- package/build/runtime-cjs/index.js +2 -0
- package/build/runtime-cjs/routing/Router.d.ts +13 -1
- package/build/runtime-cjs/routing/Router.js +75 -19
- package/build/runtime-esm/clientPlugin.js +1 -1
- package/build/runtime-esm/hooks/useDocumentHandle.d.ts +2 -0
- package/build/runtime-esm/hooks/useDocumentHandle.js +21 -6
- package/build/runtime-esm/index.d.ts +1 -1
- package/build/runtime-esm/index.js +2 -1
- package/build/runtime-esm/routing/Router.d.ts +13 -1
- package/build/runtime-esm/routing/Router.js +73 -19
- package/package.json +4 -4
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import configFile from "$houdini/runtime/imports/config";
|
|
3
3
|
import { deepEquals } from "$houdini/runtime/lib/deepEquals";
|
|
4
|
+
import { marshalSelection, marshalInputs } from "$houdini/runtime/lib/scalars";
|
|
4
5
|
import { find_match } from "$houdini/runtime/router/match";
|
|
5
6
|
import React from "react";
|
|
6
7
|
import { useContext } from "react";
|
|
8
|
+
import { useDocumentHandle } from "../hooks/useDocumentHandle";
|
|
7
9
|
import { useDocumentStore } from "../hooks/useDocumentStore";
|
|
8
10
|
import { suspense_cache } from "./cache";
|
|
9
11
|
const PreloadWhich = {
|
|
@@ -20,7 +22,10 @@ function Router({
|
|
|
20
22
|
const [currentURL, setCurrentURL] = React.useState(() => {
|
|
21
23
|
return initialURL || window.location.pathname;
|
|
22
24
|
});
|
|
23
|
-
const [page, variables] = find_match(manifest, currentURL);
|
|
25
|
+
const [page, variables] = find_match(configFile, manifest, currentURL);
|
|
26
|
+
if (!page) {
|
|
27
|
+
throw new Error("404");
|
|
28
|
+
}
|
|
24
29
|
const { loadData, loadComponent } = usePageData({
|
|
25
30
|
page,
|
|
26
31
|
variables,
|
|
@@ -51,7 +56,7 @@ function Router({
|
|
|
51
56
|
setCurrentURL(val);
|
|
52
57
|
},
|
|
53
58
|
preload(url, which) {
|
|
54
|
-
const [page2, variables2] = find_match(manifest, url);
|
|
59
|
+
const [page2, variables2] = find_match(configFile, manifest, url);
|
|
55
60
|
if (["both", "component"].includes(which)) {
|
|
56
61
|
loadComponent(page2);
|
|
57
62
|
}
|
|
@@ -60,7 +65,7 @@ function Router({
|
|
|
60
65
|
}
|
|
61
66
|
}
|
|
62
67
|
});
|
|
63
|
-
return /* @__PURE__ */ jsx(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ jsx(LocationContext.Provider, { value: { pathname: currentURL }, children: /* @__PURE__ */ jsx(PageComponent, { url: currentURL }, page.id) }) });
|
|
68
|
+
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) }) });
|
|
64
69
|
}
|
|
65
70
|
const useLocation = () => useContext(LocationContext);
|
|
66
71
|
function usePageData({
|
|
@@ -96,9 +101,8 @@ function usePageData({
|
|
|
96
101
|
reject = rej;
|
|
97
102
|
observer.send({
|
|
98
103
|
variables,
|
|
99
|
-
cacheParams: { disableSubscriptions: true },
|
|
100
104
|
session
|
|
101
|
-
}).then(() => {
|
|
105
|
+
}).then(async () => {
|
|
102
106
|
data_cache.set(id, observer);
|
|
103
107
|
if (observer.state.errors && observer.state.errors.length > 0) {
|
|
104
108
|
reject(observer.state.errors.map((e) => e.message).join("\n"));
|
|
@@ -110,7 +114,12 @@ function usePageData({
|
|
|
110
114
|
window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
|
|
111
115
|
|
|
112
116
|
const artifactName = "${artifact.name}"
|
|
113
|
-
const value = ${JSON.stringify(
|
|
117
|
+
const value = ${JSON.stringify(
|
|
118
|
+
await marshalSelection({
|
|
119
|
+
selection: observer.artifact.selection,
|
|
120
|
+
data: observer.state.data
|
|
121
|
+
})
|
|
122
|
+
)}
|
|
114
123
|
|
|
115
124
|
// if the data is pending, we need to resolve it
|
|
116
125
|
if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
|
|
@@ -119,10 +128,22 @@ function usePageData({
|
|
|
119
128
|
const new_store = window.__houdini__client__.observe({
|
|
120
129
|
artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
|
|
121
130
|
cache: window.__houdini__cache__,
|
|
122
|
-
initialValue: value,
|
|
123
131
|
})
|
|
124
132
|
|
|
125
|
-
|
|
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
|
+
)}
|
|
143
|
+
}).then(() => {
|
|
144
|
+
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
|
|
145
|
+
})
|
|
146
|
+
|
|
126
147
|
}
|
|
127
148
|
|
|
128
149
|
|
|
@@ -139,12 +160,12 @@ function usePageData({
|
|
|
139
160
|
if (!window.__houdini__pending_artifacts__) {
|
|
140
161
|
window.__houdini__pending_artifacts__ = {}
|
|
141
162
|
}
|
|
142
|
-
|
|
143
|
-
window.__houdini__pending_variables__[artifactName] = ${JSON.stringify(variables)}
|
|
144
|
-
window.__houdini__pending_data__[artifactName] = value
|
|
145
|
-
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
|
|
146
163
|
}
|
|
147
164
|
|
|
165
|
+
window.__houdini__pending_variables__[artifactName] = ${JSON.stringify(observer.state.variables)}
|
|
166
|
+
window.__houdini__pending_data__[artifactName] = value
|
|
167
|
+
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
|
|
168
|
+
|
|
148
169
|
// if this payload finishes off an ssr request, we need to resolve the signal
|
|
149
170
|
if (window.__houdini__nav_caches__?.ssr_signals.has(artifactName)) {
|
|
150
171
|
|
|
@@ -153,7 +174,13 @@ function usePageData({
|
|
|
153
174
|
// we're pushing this store onto the client, it should be initialized
|
|
154
175
|
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
|
|
155
176
|
setup: true,
|
|
156
|
-
variables: ${JSON.stringify(
|
|
177
|
+
variables: ${JSON.stringify(
|
|
178
|
+
marshalInputs({
|
|
179
|
+
artifact: observer.artifact,
|
|
180
|
+
input: variables,
|
|
181
|
+
config: configFile
|
|
182
|
+
})
|
|
183
|
+
)}
|
|
157
184
|
})
|
|
158
185
|
}
|
|
159
186
|
|
|
@@ -183,7 +210,7 @@ function usePageData({
|
|
|
183
210
|
}
|
|
184
211
|
let last = {};
|
|
185
212
|
let usedVariables = {};
|
|
186
|
-
for (const variable of pageVariables) {
|
|
213
|
+
for (const variable of Object.keys(pageVariables)) {
|
|
187
214
|
last[variable] = last_variables.get(artifact)[variable];
|
|
188
215
|
usedVariables[variable] = (variables2 ?? {})[variable];
|
|
189
216
|
}
|
|
@@ -309,7 +336,8 @@ function useSession() {
|
|
|
309
336
|
method: "POST",
|
|
310
337
|
body: JSON.stringify(newSession),
|
|
311
338
|
headers: {
|
|
312
|
-
"Content-Type": "application/json"
|
|
339
|
+
"Content-Type": "application/json",
|
|
340
|
+
Accept: "application/json"
|
|
313
341
|
}
|
|
314
342
|
});
|
|
315
343
|
};
|
|
@@ -319,17 +347,27 @@ function useCurrentVariables() {
|
|
|
319
347
|
return React.useContext(VariableContext);
|
|
320
348
|
}
|
|
321
349
|
const VariableContext = React.createContext(null);
|
|
322
|
-
const LocationContext = React.createContext({
|
|
350
|
+
const LocationContext = React.createContext({
|
|
351
|
+
pathname: "",
|
|
352
|
+
params: {}
|
|
353
|
+
});
|
|
323
354
|
function useQueryResult(name) {
|
|
324
|
-
const
|
|
325
|
-
const
|
|
355
|
+
const { data_cache, artifact_cache } = useRouterContext();
|
|
356
|
+
const store_ref = data_cache.get(name);
|
|
357
|
+
const [storeValue, observer] = useDocumentStore({
|
|
326
358
|
artifact: store_ref.artifact,
|
|
327
359
|
observer: store_ref
|
|
328
360
|
});
|
|
361
|
+
const { data, errors } = storeValue;
|
|
329
362
|
if (errors && errors.length > 0) {
|
|
330
363
|
throw new Error(JSON.stringify(errors));
|
|
331
364
|
}
|
|
332
|
-
|
|
365
|
+
const handle = useDocumentHandle({
|
|
366
|
+
artifact: artifact_cache.get(name),
|
|
367
|
+
observer,
|
|
368
|
+
storeValue
|
|
369
|
+
});
|
|
370
|
+
return [data, handle];
|
|
333
371
|
}
|
|
334
372
|
function useLinkBehavior({
|
|
335
373
|
goto,
|
|
@@ -429,6 +467,20 @@ function router_cache({
|
|
|
429
467
|
}
|
|
430
468
|
return result;
|
|
431
469
|
}
|
|
470
|
+
const PageContext = React.createContext({ params: {} });
|
|
471
|
+
function PageContextProvider({
|
|
472
|
+
keys,
|
|
473
|
+
children
|
|
474
|
+
}) {
|
|
475
|
+
const location2 = useLocation();
|
|
476
|
+
const params = Object.fromEntries(
|
|
477
|
+
Object.entries(location2.params).filter(([key]) => keys.includes(key))
|
|
478
|
+
);
|
|
479
|
+
return /* @__PURE__ */ jsx(PageContext.Provider, { value: { params }, children });
|
|
480
|
+
}
|
|
481
|
+
function useRoute() {
|
|
482
|
+
return useContext(PageContext);
|
|
483
|
+
}
|
|
432
484
|
function signal_promise() {
|
|
433
485
|
let resolve = () => {
|
|
434
486
|
};
|
|
@@ -445,6 +497,7 @@ function signal_promise() {
|
|
|
445
497
|
};
|
|
446
498
|
}
|
|
447
499
|
export {
|
|
500
|
+
PageContextProvider,
|
|
448
501
|
Router,
|
|
449
502
|
RouterContextProvider,
|
|
450
503
|
router_cache,
|
|
@@ -454,6 +507,7 @@ export {
|
|
|
454
507
|
useCurrentVariables,
|
|
455
508
|
useLocation,
|
|
456
509
|
useQueryResult,
|
|
510
|
+
useRoute,
|
|
457
511
|
useRouterContext,
|
|
458
512
|
useSession
|
|
459
513
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "houdini-react",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.46",
|
|
4
4
|
"description": "The React plugin for houdini",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"express": "^4.18.2",
|
|
38
38
|
"graphql": "^15.8.0",
|
|
39
39
|
"graphql-yoga": "^4.0.4",
|
|
40
|
-
"react": "
|
|
41
|
-
"react-dom": "
|
|
40
|
+
"react": "19.0.0-canary-2b036d3f1-20240327",
|
|
41
|
+
"react-dom": "19.0.0-canary-2b036d3f1-20240327",
|
|
42
42
|
"react-streaming-compat": "^0.3.18",
|
|
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.46"
|
|
47
47
|
},
|
|
48
48
|
"files": [
|
|
49
49
|
"build"
|