houdini-react 1.2.44 → 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 +847 -866
- package/build/plugin-esm/index.js +847 -866
- package/build/runtime/index.d.ts +1 -1
- package/build/runtime/routing/Router.d.ts +11 -0
- 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 +11 -0
- package/build/runtime-cjs/routing/Router.js +60 -12
- 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 +11 -0
- package/build/runtime-esm/routing/Router.js +58 -12
- package/package.json +2 -2
package/build/runtime/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { GraphQLObject } from '$houdini/lib/types';
|
|
|
2
2
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
3
3
|
import { RouterCache } from './routing';
|
|
4
4
|
export * from './hooks';
|
|
5
|
-
export { router_cache, useSession, useLocation } from './routing';
|
|
5
|
+
export { router_cache, useSession, useLocation, useRoute } from './routing';
|
|
6
6
|
export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session, assetPrefix, injectToStream, }: {
|
|
7
7
|
initialURL: string;
|
|
8
8
|
initialVariables: GraphQLObject;
|
|
@@ -20,6 +20,7 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
20
20
|
}): JSX.Element;
|
|
21
21
|
export declare const useLocation: () => {
|
|
22
22
|
pathname: string;
|
|
23
|
+
params: Record<string, any>;
|
|
23
24
|
};
|
|
24
25
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
25
26
|
children: React.ReactElement;
|
|
@@ -69,4 +70,14 @@ export declare function router_cache({ pending_queries, artifacts, components, i
|
|
|
69
70
|
initialVariables?: Record<string, GraphQLVariables>;
|
|
70
71
|
initialArtifacts?: Record<string, QueryArtifact>;
|
|
71
72
|
}): RouterCache;
|
|
73
|
+
export declare function PageContextProvider({ keys, children, }: {
|
|
74
|
+
keys: string[];
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
}): JSX.Element;
|
|
77
|
+
export declare function useRoute<PageProps extends {
|
|
78
|
+
Params: {};
|
|
79
|
+
}>(): RouteProp<PageProps['Params']>;
|
|
80
|
+
export type RouteProp<Params> = {
|
|
81
|
+
params: Params;
|
|
82
|
+
};
|
|
72
83
|
export {};
|
|
@@ -2,7 +2,7 @@ import type { GraphQLObject } from '$houdini/lib/types';
|
|
|
2
2
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
3
3
|
import { RouterCache } from './routing';
|
|
4
4
|
export * from './hooks';
|
|
5
|
-
export { router_cache, useSession, useLocation } from './routing';
|
|
5
|
+
export { router_cache, useSession, useLocation, useRoute } from './routing';
|
|
6
6
|
export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session, assetPrefix, injectToStream, }: {
|
|
7
7
|
initialURL: string;
|
|
8
8
|
initialVariables: GraphQLObject;
|
|
@@ -28,6 +28,7 @@ __export(runtime_exports, {
|
|
|
28
28
|
Router: () => Router,
|
|
29
29
|
router_cache: () => import_routing2.router_cache,
|
|
30
30
|
useLocation: () => import_routing2.useLocation,
|
|
31
|
+
useRoute: () => import_routing2.useRoute,
|
|
31
32
|
useSession: () => import_routing2.useSession
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(runtime_exports);
|
|
@@ -77,5 +78,6 @@ function Router({
|
|
|
77
78
|
Router,
|
|
78
79
|
router_cache,
|
|
79
80
|
useLocation,
|
|
81
|
+
useRoute,
|
|
80
82
|
useSession
|
|
81
83
|
});
|
|
@@ -20,6 +20,7 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
20
20
|
}): JSX.Element;
|
|
21
21
|
export declare const useLocation: () => {
|
|
22
22
|
pathname: string;
|
|
23
|
+
params: Record<string, any>;
|
|
23
24
|
};
|
|
24
25
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
25
26
|
children: React.ReactElement;
|
|
@@ -69,4 +70,14 @@ export declare function router_cache({ pending_queries, artifacts, components, i
|
|
|
69
70
|
initialVariables?: Record<string, GraphQLVariables>;
|
|
70
71
|
initialArtifacts?: Record<string, QueryArtifact>;
|
|
71
72
|
}): RouterCache;
|
|
73
|
+
export declare function PageContextProvider({ keys, children, }: {
|
|
74
|
+
keys: string[];
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
}): JSX.Element;
|
|
77
|
+
export declare function useRoute<PageProps extends {
|
|
78
|
+
Params: {};
|
|
79
|
+
}>(): RouteProp<PageProps['Params']>;
|
|
80
|
+
export type RouteProp<Params> = {
|
|
81
|
+
params: Params;
|
|
82
|
+
};
|
|
72
83
|
export {};
|
|
@@ -24,6 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var Router_exports = {};
|
|
26
26
|
__export(Router_exports, {
|
|
27
|
+
PageContextProvider: () => PageContextProvider,
|
|
27
28
|
Router: () => Router,
|
|
28
29
|
RouterContextProvider: () => RouterContextProvider,
|
|
29
30
|
router_cache: () => router_cache,
|
|
@@ -33,6 +34,7 @@ __export(Router_exports, {
|
|
|
33
34
|
useCurrentVariables: () => useCurrentVariables,
|
|
34
35
|
useLocation: () => useLocation,
|
|
35
36
|
useQueryResult: () => useQueryResult,
|
|
37
|
+
useRoute: () => useRoute,
|
|
36
38
|
useRouterContext: () => useRouterContext,
|
|
37
39
|
useSession: () => useSession
|
|
38
40
|
});
|
|
@@ -40,6 +42,7 @@ module.exports = __toCommonJS(Router_exports);
|
|
|
40
42
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
43
|
var import_config = __toESM(require("$houdini/runtime/imports/config"));
|
|
42
44
|
var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
|
|
45
|
+
var import_scalars = require("$houdini/runtime/lib/scalars");
|
|
43
46
|
var import_match = require("$houdini/runtime/router/match");
|
|
44
47
|
var import_react = __toESM(require("react"));
|
|
45
48
|
var import_react2 = require("react");
|
|
@@ -60,6 +63,9 @@ function Router({
|
|
|
60
63
|
return initialURL || window.location.pathname;
|
|
61
64
|
});
|
|
62
65
|
const [page, variables] = (0, import_match.find_match)(manifest, currentURL);
|
|
66
|
+
if (!page) {
|
|
67
|
+
throw new Error("404");
|
|
68
|
+
}
|
|
63
69
|
const { loadData, loadComponent } = usePageData({
|
|
64
70
|
page,
|
|
65
71
|
variables,
|
|
@@ -99,7 +105,7 @@ function Router({
|
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
107
|
});
|
|
102
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LocationContext.Provider, { value: { pathname: currentURL }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageComponent, { url: currentURL }, page.id) }) });
|
|
108
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LocationContext.Provider, { value: { pathname: currentURL, params: variables ?? {} }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageComponent, { url: currentURL }, page.id) }) });
|
|
103
109
|
}
|
|
104
110
|
const useLocation = () => (0, import_react2.useContext)(LocationContext);
|
|
105
111
|
function usePageData({
|
|
@@ -137,7 +143,7 @@ function usePageData({
|
|
|
137
143
|
variables,
|
|
138
144
|
cacheParams: { disableSubscriptions: true },
|
|
139
145
|
session
|
|
140
|
-
}).then(() => {
|
|
146
|
+
}).then(async () => {
|
|
141
147
|
data_cache.set(id, observer);
|
|
142
148
|
if (observer.state.errors && observer.state.errors.length > 0) {
|
|
143
149
|
reject(observer.state.errors.map((e) => e.message).join("\n"));
|
|
@@ -149,7 +155,12 @@ function usePageData({
|
|
|
149
155
|
window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
|
|
150
156
|
|
|
151
157
|
const artifactName = "${artifact.name}"
|
|
152
|
-
const value = ${JSON.stringify(
|
|
158
|
+
const value = ${JSON.stringify(
|
|
159
|
+
await (0, import_scalars.marshalSelection)({
|
|
160
|
+
selection: observer.artifact.selection,
|
|
161
|
+
data: observer.state.data
|
|
162
|
+
})
|
|
163
|
+
)}
|
|
153
164
|
|
|
154
165
|
// if the data is pending, we need to resolve it
|
|
155
166
|
if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
|
|
@@ -158,7 +169,18 @@ function usePageData({
|
|
|
158
169
|
const new_store = window.__houdini__client__.observe({
|
|
159
170
|
artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
|
|
160
171
|
cache: window.__houdini__cache__,
|
|
161
|
-
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
// we're pushing this store onto the client, it should be initialized
|
|
175
|
+
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
|
|
176
|
+
setup: true,
|
|
177
|
+
variables: ${JSON.stringify(
|
|
178
|
+
(0, import_scalars.marshalInputs)({
|
|
179
|
+
artifact: observer.artifact,
|
|
180
|
+
input: variables,
|
|
181
|
+
config: import_config.default
|
|
182
|
+
})
|
|
183
|
+
)}
|
|
162
184
|
})
|
|
163
185
|
|
|
164
186
|
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
|
|
@@ -178,12 +200,12 @@ function usePageData({
|
|
|
178
200
|
if (!window.__houdini__pending_artifacts__) {
|
|
179
201
|
window.__houdini__pending_artifacts__ = {}
|
|
180
202
|
}
|
|
181
|
-
|
|
182
|
-
window.__houdini__pending_variables__[artifactName] = ${JSON.stringify(variables)}
|
|
183
|
-
window.__houdini__pending_data__[artifactName] = value
|
|
184
|
-
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
|
|
185
203
|
}
|
|
186
204
|
|
|
205
|
+
window.__houdini__pending_variables__[artifactName] = ${JSON.stringify(observer.state.variables)}
|
|
206
|
+
window.__houdini__pending_data__[artifactName] = value
|
|
207
|
+
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
|
|
208
|
+
|
|
187
209
|
// if this payload finishes off an ssr request, we need to resolve the signal
|
|
188
210
|
if (window.__houdini__nav_caches__?.ssr_signals.has(artifactName)) {
|
|
189
211
|
|
|
@@ -192,7 +214,13 @@ function usePageData({
|
|
|
192
214
|
// we're pushing this store onto the client, it should be initialized
|
|
193
215
|
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
|
|
194
216
|
setup: true,
|
|
195
|
-
variables: ${JSON.stringify(
|
|
217
|
+
variables: ${JSON.stringify(
|
|
218
|
+
(0, import_scalars.marshalInputs)({
|
|
219
|
+
artifact: observer.artifact,
|
|
220
|
+
input: variables,
|
|
221
|
+
config: import_config.default
|
|
222
|
+
})
|
|
223
|
+
)}
|
|
196
224
|
})
|
|
197
225
|
}
|
|
198
226
|
|
|
@@ -222,7 +250,7 @@ function usePageData({
|
|
|
222
250
|
}
|
|
223
251
|
let last = {};
|
|
224
252
|
let usedVariables = {};
|
|
225
|
-
for (const variable of pageVariables) {
|
|
253
|
+
for (const variable of Object.keys(pageVariables)) {
|
|
226
254
|
last[variable] = last_variables.get(artifact)[variable];
|
|
227
255
|
usedVariables[variable] = (variables2 ?? {})[variable];
|
|
228
256
|
}
|
|
@@ -348,7 +376,8 @@ function useSession() {
|
|
|
348
376
|
method: "POST",
|
|
349
377
|
body: JSON.stringify(newSession),
|
|
350
378
|
headers: {
|
|
351
|
-
"Content-Type": "application/json"
|
|
379
|
+
"Content-Type": "application/json",
|
|
380
|
+
Accept: "application/json"
|
|
352
381
|
}
|
|
353
382
|
});
|
|
354
383
|
};
|
|
@@ -358,7 +387,10 @@ function useCurrentVariables() {
|
|
|
358
387
|
return import_react.default.useContext(VariableContext);
|
|
359
388
|
}
|
|
360
389
|
const VariableContext = import_react.default.createContext(null);
|
|
361
|
-
const LocationContext = import_react.default.createContext({
|
|
390
|
+
const LocationContext = import_react.default.createContext({
|
|
391
|
+
pathname: "",
|
|
392
|
+
params: {}
|
|
393
|
+
});
|
|
362
394
|
function useQueryResult(name) {
|
|
363
395
|
const store_ref = useRouterContext().data_cache.get(name);
|
|
364
396
|
const [{ data, errors }, observer] = (0, import_useDocumentStore.useDocumentStore)({
|
|
@@ -468,6 +500,20 @@ function router_cache({
|
|
|
468
500
|
}
|
|
469
501
|
return result;
|
|
470
502
|
}
|
|
503
|
+
const PageContext = import_react.default.createContext({ params: {} });
|
|
504
|
+
function PageContextProvider({
|
|
505
|
+
keys,
|
|
506
|
+
children
|
|
507
|
+
}) {
|
|
508
|
+
const location2 = useLocation();
|
|
509
|
+
const params = Object.fromEntries(
|
|
510
|
+
Object.entries(location2.params).filter(([key]) => keys.includes(key))
|
|
511
|
+
);
|
|
512
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageContext.Provider, { value: { params }, children });
|
|
513
|
+
}
|
|
514
|
+
function useRoute() {
|
|
515
|
+
return (0, import_react2.useContext)(PageContext);
|
|
516
|
+
}
|
|
471
517
|
function signal_promise() {
|
|
472
518
|
let resolve = () => {
|
|
473
519
|
};
|
|
@@ -485,6 +531,7 @@ function signal_promise() {
|
|
|
485
531
|
}
|
|
486
532
|
// Annotate the CommonJS export names for ESM import in node:
|
|
487
533
|
0 && (module.exports = {
|
|
534
|
+
PageContextProvider,
|
|
488
535
|
Router,
|
|
489
536
|
RouterContextProvider,
|
|
490
537
|
router_cache,
|
|
@@ -494,6 +541,7 @@ function signal_promise() {
|
|
|
494
541
|
useCurrentVariables,
|
|
495
542
|
useLocation,
|
|
496
543
|
useQueryResult,
|
|
544
|
+
useRoute,
|
|
497
545
|
useRouterContext,
|
|
498
546
|
useSession
|
|
499
547
|
});
|
|
@@ -2,7 +2,7 @@ import type { GraphQLObject } from '$houdini/lib/types';
|
|
|
2
2
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
3
3
|
import { RouterCache } from './routing';
|
|
4
4
|
export * from './hooks';
|
|
5
|
-
export { router_cache, useSession, useLocation } from './routing';
|
|
5
|
+
export { router_cache, useSession, useLocation, useRoute } from './routing';
|
|
6
6
|
export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session, assetPrefix, injectToStream, }: {
|
|
7
7
|
initialURL: string;
|
|
8
8
|
initialVariables: GraphQLObject;
|
|
@@ -3,7 +3,7 @@ import client from "./client";
|
|
|
3
3
|
import manifest from "./manifest";
|
|
4
4
|
import { Router as RouterImpl, RouterContextProvider } from "./routing";
|
|
5
5
|
export * from "./hooks";
|
|
6
|
-
import { router_cache, useSession, useLocation } from "./routing";
|
|
6
|
+
import { router_cache, useSession, useLocation, useRoute } from "./routing";
|
|
7
7
|
function Router({
|
|
8
8
|
cache,
|
|
9
9
|
initialURL,
|
|
@@ -43,5 +43,6 @@ export {
|
|
|
43
43
|
Router,
|
|
44
44
|
router_cache,
|
|
45
45
|
useLocation,
|
|
46
|
+
useRoute,
|
|
46
47
|
useSession
|
|
47
48
|
};
|
|
@@ -20,6 +20,7 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
20
20
|
}): JSX.Element;
|
|
21
21
|
export declare const useLocation: () => {
|
|
22
22
|
pathname: string;
|
|
23
|
+
params: Record<string, any>;
|
|
23
24
|
};
|
|
24
25
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
25
26
|
children: React.ReactElement;
|
|
@@ -69,4 +70,14 @@ export declare function router_cache({ pending_queries, artifacts, components, i
|
|
|
69
70
|
initialVariables?: Record<string, GraphQLVariables>;
|
|
70
71
|
initialArtifacts?: Record<string, QueryArtifact>;
|
|
71
72
|
}): RouterCache;
|
|
73
|
+
export declare function PageContextProvider({ keys, children, }: {
|
|
74
|
+
keys: string[];
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
}): JSX.Element;
|
|
77
|
+
export declare function useRoute<PageProps extends {
|
|
78
|
+
Params: {};
|
|
79
|
+
}>(): RouteProp<PageProps['Params']>;
|
|
80
|
+
export type RouteProp<Params> = {
|
|
81
|
+
params: Params;
|
|
82
|
+
};
|
|
72
83
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
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";
|
|
@@ -21,6 +22,9 @@ function Router({
|
|
|
21
22
|
return initialURL || window.location.pathname;
|
|
22
23
|
});
|
|
23
24
|
const [page, variables] = find_match(manifest, currentURL);
|
|
25
|
+
if (!page) {
|
|
26
|
+
throw new Error("404");
|
|
27
|
+
}
|
|
24
28
|
const { loadData, loadComponent } = usePageData({
|
|
25
29
|
page,
|
|
26
30
|
variables,
|
|
@@ -60,7 +64,7 @@ function Router({
|
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
});
|
|
63
|
-
return /* @__PURE__ */ jsx(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ jsx(LocationContext.Provider, { value: { pathname: currentURL }, 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) }) });
|
|
64
68
|
}
|
|
65
69
|
const useLocation = () => useContext(LocationContext);
|
|
66
70
|
function usePageData({
|
|
@@ -98,7 +102,7 @@ function usePageData({
|
|
|
98
102
|
variables,
|
|
99
103
|
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,7 +128,18 @@ 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
|
-
|
|
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
|
+
)}
|
|
123
143
|
})
|
|
124
144
|
|
|
125
145
|
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
|
|
@@ -139,12 +159,12 @@ function usePageData({
|
|
|
139
159
|
if (!window.__houdini__pending_artifacts__) {
|
|
140
160
|
window.__houdini__pending_artifacts__ = {}
|
|
141
161
|
}
|
|
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
162
|
}
|
|
147
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
|
+
|
|
148
168
|
// if this payload finishes off an ssr request, we need to resolve the signal
|
|
149
169
|
if (window.__houdini__nav_caches__?.ssr_signals.has(artifactName)) {
|
|
150
170
|
|
|
@@ -153,7 +173,13 @@ function usePageData({
|
|
|
153
173
|
// we're pushing this store onto the client, it should be initialized
|
|
154
174
|
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
|
|
155
175
|
setup: true,
|
|
156
|
-
variables: ${JSON.stringify(
|
|
176
|
+
variables: ${JSON.stringify(
|
|
177
|
+
marshalInputs({
|
|
178
|
+
artifact: observer.artifact,
|
|
179
|
+
input: variables,
|
|
180
|
+
config: configFile
|
|
181
|
+
})
|
|
182
|
+
)}
|
|
157
183
|
})
|
|
158
184
|
}
|
|
159
185
|
|
|
@@ -183,7 +209,7 @@ function usePageData({
|
|
|
183
209
|
}
|
|
184
210
|
let last = {};
|
|
185
211
|
let usedVariables = {};
|
|
186
|
-
for (const variable of pageVariables) {
|
|
212
|
+
for (const variable of Object.keys(pageVariables)) {
|
|
187
213
|
last[variable] = last_variables.get(artifact)[variable];
|
|
188
214
|
usedVariables[variable] = (variables2 ?? {})[variable];
|
|
189
215
|
}
|
|
@@ -309,7 +335,8 @@ function useSession() {
|
|
|
309
335
|
method: "POST",
|
|
310
336
|
body: JSON.stringify(newSession),
|
|
311
337
|
headers: {
|
|
312
|
-
"Content-Type": "application/json"
|
|
338
|
+
"Content-Type": "application/json",
|
|
339
|
+
Accept: "application/json"
|
|
313
340
|
}
|
|
314
341
|
});
|
|
315
342
|
};
|
|
@@ -319,7 +346,10 @@ function useCurrentVariables() {
|
|
|
319
346
|
return React.useContext(VariableContext);
|
|
320
347
|
}
|
|
321
348
|
const VariableContext = React.createContext(null);
|
|
322
|
-
const LocationContext = React.createContext({
|
|
349
|
+
const LocationContext = React.createContext({
|
|
350
|
+
pathname: "",
|
|
351
|
+
params: {}
|
|
352
|
+
});
|
|
323
353
|
function useQueryResult(name) {
|
|
324
354
|
const store_ref = useRouterContext().data_cache.get(name);
|
|
325
355
|
const [{ data, errors }, observer] = useDocumentStore({
|
|
@@ -429,6 +459,20 @@ function router_cache({
|
|
|
429
459
|
}
|
|
430
460
|
return result;
|
|
431
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
|
+
}
|
|
432
476
|
function signal_promise() {
|
|
433
477
|
let resolve = () => {
|
|
434
478
|
};
|
|
@@ -445,6 +489,7 @@ function signal_promise() {
|
|
|
445
489
|
};
|
|
446
490
|
}
|
|
447
491
|
export {
|
|
492
|
+
PageContextProvider,
|
|
448
493
|
Router,
|
|
449
494
|
RouterContextProvider,
|
|
450
495
|
router_cache,
|
|
@@ -454,6 +499,7 @@ export {
|
|
|
454
499
|
useCurrentVariables,
|
|
455
500
|
useLocation,
|
|
456
501
|
useQueryResult,
|
|
502
|
+
useRoute,
|
|
457
503
|
useRouterContext,
|
|
458
504
|
useSession
|
|
459
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"
|