houdini-react 1.3.14 → 2.0.0-go.1
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/package.json +89 -73
- package/shim.cjs +64 -0
- package/LICENSE +0 -21
- package/README.md +0 -36
- package/build/plugin/codegen/entries/documentWrappers.d.ts +0 -6
- package/build/plugin/codegen/entries/fallbacks.d.ts +0 -5
- package/build/plugin/codegen/entries/index.d.ts +0 -16
- package/build/plugin/codegen/entries/pages.d.ts +0 -2
- package/build/plugin/codegen/index.d.ts +0 -17
- package/build/plugin/codegen/manifest.d.ts +0 -5
- package/build/plugin/codegen/render.d.ts +0 -7
- package/build/plugin/codegen/router.d.ts +0 -7
- package/build/plugin/codegen/typeRoot.d.ts +0 -5
- package/build/plugin/config.d.ts +0 -4
- package/build/plugin/dedent.d.ts +0 -1
- package/build/plugin/extract.d.ts +0 -6
- package/build/plugin/index.d.ts +0 -5
- package/build/plugin/state.d.ts +0 -3
- package/build/plugin/transform.d.ts +0 -6
- package/build/plugin/vite.d.ts +0 -70
- package/build/plugin-cjs/index.js +0 -84192
- package/build/plugin-cjs/package.json +0 -1
- package/build/plugin-esm/index.js +0 -84184
- package/build/plugin-esm/package.json +0 -1
- package/build/runtime/client.d.ts +0 -3
- package/build/runtime/clientPlugin.d.ts +0 -3
- package/build/runtime/componentFields.d.ts +0 -9
- package/build/runtime/hooks/index.d.ts +0 -8
- package/build/runtime/hooks/useDeepCompareEffect.d.ts +0 -35
- package/build/runtime/hooks/useDocumentHandle.d.ts +0 -36
- package/build/runtime/hooks/useDocumentStore.d.ts +0 -11
- package/build/runtime/hooks/useDocumentSubscription.d.ts +0 -11
- package/build/runtime/hooks/useFragment.d.ts +0 -16
- package/build/runtime/hooks/useFragmentHandle.d.ts +0 -8
- package/build/runtime/hooks/useIsMounted.d.ts +0 -3
- package/build/runtime/hooks/useMutation.d.ts +0 -11
- package/build/runtime/hooks/useQuery.d.ts +0 -5
- package/build/runtime/hooks/useQueryHandle.d.ts +0 -10
- package/build/runtime/hooks/useSubscription.d.ts +0 -4
- package/build/runtime/hooks/useSubscriptionHandle.d.ts +0 -25
- package/build/runtime/index.d.ts +0 -14
- package/build/runtime/manifest.d.ts +0 -3
- package/build/runtime/routing/Router.d.ts +0 -62
- package/build/runtime/routing/cache.d.ts +0 -7
- package/build/runtime/routing/hooks.d.ts +0 -40
- package/build/runtime/routing/index.d.ts +0 -3
- package/build/runtime-cjs/client.d.ts +0 -3
- package/build/runtime-cjs/client.js +0 -27
- package/build/runtime-cjs/clientPlugin.d.ts +0 -3
- package/build/runtime-cjs/clientPlugin.js +0 -39
- package/build/runtime-cjs/componentFields.d.ts +0 -9
- package/build/runtime-cjs/componentFields.js +0 -83
- package/build/runtime-cjs/hooks/index.d.ts +0 -8
- package/build/runtime-cjs/hooks/index.js +0 -45
- package/build/runtime-cjs/hooks/useDeepCompareEffect.d.ts +0 -35
- package/build/runtime-cjs/hooks/useDeepCompareEffect.js +0 -72
- package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +0 -36
- package/build/runtime-cjs/hooks/useDocumentHandle.js +0 -173
- package/build/runtime-cjs/hooks/useDocumentStore.d.ts +0 -11
- package/build/runtime-cjs/hooks/useDocumentStore.js +0 -72
- package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +0 -11
- package/build/runtime-cjs/hooks/useDocumentSubscription.js +0 -71
- package/build/runtime-cjs/hooks/useFragment.d.ts +0 -16
- package/build/runtime-cjs/hooks/useFragment.js +0 -97
- package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +0 -8
- package/build/runtime-cjs/hooks/useFragmentHandle.js +0 -47
- package/build/runtime-cjs/hooks/useIsMounted.d.ts +0 -3
- package/build/runtime-cjs/hooks/useIsMounted.js +0 -38
- package/build/runtime-cjs/hooks/useMutation.d.ts +0 -11
- package/build/runtime-cjs/hooks/useMutation.js +0 -52
- package/build/runtime-cjs/hooks/useQuery.d.ts +0 -5
- package/build/runtime-cjs/hooks/useQuery.js +0 -32
- package/build/runtime-cjs/hooks/useQueryHandle.d.ts +0 -10
- package/build/runtime-cjs/hooks/useQueryHandle.js +0 -125
- package/build/runtime-cjs/hooks/useSubscription.d.ts +0 -4
- package/build/runtime-cjs/hooks/useSubscription.js +0 -32
- package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +0 -25
- package/build/runtime-cjs/hooks/useSubscriptionHandle.js +0 -42
- package/build/runtime-cjs/index.d.ts +0 -14
- package/build/runtime-cjs/index.js +0 -83
- package/build/runtime-cjs/manifest.d.ts +0 -3
- package/build/runtime-cjs/manifest.js +0 -27
- package/build/runtime-cjs/package.json +0 -1
- package/build/runtime-cjs/routing/Router.d.ts +0 -62
- package/build/runtime-cjs/routing/Router.js +0 -532
- package/build/runtime-cjs/routing/cache.d.ts +0 -7
- package/build/runtime-cjs/routing/cache.js +0 -58
- package/build/runtime-cjs/routing/hooks.d.ts +0 -40
- package/build/runtime-cjs/routing/hooks.js +0 -89
- package/build/runtime-cjs/routing/index.d.ts +0 -3
- package/build/runtime-cjs/routing/index.js +0 -31
- package/build/runtime-esm/client.d.ts +0 -3
- package/build/runtime-esm/client.js +0 -5
- package/build/runtime-esm/clientPlugin.d.ts +0 -3
- package/build/runtime-esm/clientPlugin.js +0 -17
- package/build/runtime-esm/componentFields.d.ts +0 -9
- package/build/runtime-esm/componentFields.js +0 -59
- package/build/runtime-esm/hooks/index.d.ts +0 -8
- package/build/runtime-esm/hooks/index.js +0 -16
- package/build/runtime-esm/hooks/useDeepCompareEffect.d.ts +0 -35
- package/build/runtime-esm/hooks/useDeepCompareEffect.js +0 -41
- package/build/runtime-esm/hooks/useDocumentHandle.d.ts +0 -36
- package/build/runtime-esm/hooks/useDocumentHandle.js +0 -143
- package/build/runtime-esm/hooks/useDocumentStore.d.ts +0 -11
- package/build/runtime-esm/hooks/useDocumentStore.js +0 -42
- package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +0 -11
- package/build/runtime-esm/hooks/useDocumentSubscription.js +0 -41
- package/build/runtime-esm/hooks/useFragment.d.ts +0 -16
- package/build/runtime-esm/hooks/useFragment.js +0 -66
- package/build/runtime-esm/hooks/useFragmentHandle.d.ts +0 -8
- package/build/runtime-esm/hooks/useFragmentHandle.js +0 -23
- package/build/runtime-esm/hooks/useIsMounted.d.ts +0 -3
- package/build/runtime-esm/hooks/useIsMounted.js +0 -14
- package/build/runtime-esm/hooks/useMutation.d.ts +0 -11
- package/build/runtime-esm/hooks/useMutation.js +0 -28
- package/build/runtime-esm/hooks/useQuery.d.ts +0 -5
- package/build/runtime-esm/hooks/useQuery.js +0 -8
- package/build/runtime-esm/hooks/useQueryHandle.d.ts +0 -10
- package/build/runtime-esm/hooks/useQueryHandle.js +0 -95
- package/build/runtime-esm/hooks/useSubscription.d.ts +0 -4
- package/build/runtime-esm/hooks/useSubscription.js +0 -8
- package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +0 -25
- package/build/runtime-esm/hooks/useSubscriptionHandle.js +0 -18
- package/build/runtime-esm/index.d.ts +0 -14
- package/build/runtime-esm/index.js +0 -48
- package/build/runtime-esm/manifest.d.ts +0 -3
- package/build/runtime-esm/manifest.js +0 -5
- package/build/runtime-esm/package.json +0 -1
- package/build/runtime-esm/routing/Router.d.ts +0 -62
- package/build/runtime-esm/routing/Router.js +0 -495
- package/build/runtime-esm/routing/cache.d.ts +0 -7
- package/build/runtime-esm/routing/cache.js +0 -33
- package/build/runtime-esm/routing/hooks.d.ts +0 -40
- package/build/runtime-esm/routing/hooks.js +0 -53
- package/build/runtime-esm/routing/index.d.ts +0 -3
- package/build/runtime-esm/routing/index.js +0 -6
- package/build/server/index.d.ts +0 -1
- package/build/server-cjs/index.js +0 -28
- package/build/server-cjs/package.json +0 -1
- package/build/server-esm/index.js +0 -4
- package/build/server-esm/package.json +0 -1
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import configFile from "$houdini/runtime/imports/config";
|
|
3
|
-
import { deepEquals } from "$houdini/runtime/lib/deepEquals";
|
|
4
|
-
import { marshalSelection, marshalInputs } from "$houdini/runtime/lib/scalars";
|
|
5
|
-
import { find_match } from "$houdini/runtime/router/match";
|
|
6
|
-
import React from "react";
|
|
7
|
-
import { useContext } from "react";
|
|
8
|
-
import { suspense_cache } from "./cache";
|
|
9
|
-
import { useDocumentHandle } from "../hooks/useDocumentHandle";
|
|
10
|
-
import { useDocumentStore } from "../hooks/useDocumentStore";
|
|
11
|
-
import { Context, useRouterContext, useSession, useLocation, LocationContext } from "./hooks";
|
|
12
|
-
const PreloadWhich = {
|
|
13
|
-
component: "component",
|
|
14
|
-
data: "data",
|
|
15
|
-
page: "page"
|
|
16
|
-
};
|
|
17
|
-
function Router({
|
|
18
|
-
manifest,
|
|
19
|
-
initialURL,
|
|
20
|
-
assetPrefix,
|
|
21
|
-
injectToStream
|
|
22
|
-
}) {
|
|
23
|
-
const [currentURL, setCurrentURL] = React.useState(() => {
|
|
24
|
-
return initialURL || window.location.pathname;
|
|
25
|
-
});
|
|
26
|
-
const [page, variables] = find_match(configFile, manifest, currentURL);
|
|
27
|
-
if (!page) {
|
|
28
|
-
throw new Error("404");
|
|
29
|
-
}
|
|
30
|
-
const { loadData, loadComponent } = usePageData({
|
|
31
|
-
page,
|
|
32
|
-
variables,
|
|
33
|
-
assetPrefix,
|
|
34
|
-
injectToStream
|
|
35
|
-
});
|
|
36
|
-
const { component_cache, data_cache } = useRouterContext();
|
|
37
|
-
const PageComponent = component_cache.get(page.id);
|
|
38
|
-
React.useEffect(() => {
|
|
39
|
-
if (globalThis.window && window.location.pathname !== currentURL) {
|
|
40
|
-
window.history.pushState({}, "", currentURL);
|
|
41
|
-
}
|
|
42
|
-
}, [currentURL]);
|
|
43
|
-
React.useEffect(() => {
|
|
44
|
-
if (!globalThis.window) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const onChange = (evt) => {
|
|
48
|
-
setCurrentURL(window.location.pathname);
|
|
49
|
-
};
|
|
50
|
-
window.addEventListener("popstate", onChange);
|
|
51
|
-
return () => {
|
|
52
|
-
window.removeEventListener("popstate", onChange);
|
|
53
|
-
};
|
|
54
|
-
}, []);
|
|
55
|
-
const goto = (url) => {
|
|
56
|
-
data_cache.clear();
|
|
57
|
-
setCurrentURL(url);
|
|
58
|
-
};
|
|
59
|
-
useLinkBehavior({
|
|
60
|
-
goto,
|
|
61
|
-
preload(url, which) {
|
|
62
|
-
const [page2, variables2] = find_match(configFile, manifest, url);
|
|
63
|
-
if (!page2) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (["page", "component"].includes(which)) {
|
|
67
|
-
loadComponent(page2);
|
|
68
|
-
}
|
|
69
|
-
if (["page", "data"].includes(which)) {
|
|
70
|
-
loadData(page2, variables2);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return /* @__PURE__ */ jsx(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ jsx(
|
|
75
|
-
LocationContext.Provider,
|
|
76
|
-
{
|
|
77
|
-
value: {
|
|
78
|
-
pathname: currentURL,
|
|
79
|
-
goto,
|
|
80
|
-
params: variables ?? {}
|
|
81
|
-
},
|
|
82
|
-
children: /* @__PURE__ */ jsx(PageComponent, { url: currentURL }, page.id)
|
|
83
|
-
}
|
|
84
|
-
) });
|
|
85
|
-
}
|
|
86
|
-
function usePageData({
|
|
87
|
-
page,
|
|
88
|
-
variables,
|
|
89
|
-
assetPrefix,
|
|
90
|
-
injectToStream
|
|
91
|
-
}) {
|
|
92
|
-
const {
|
|
93
|
-
client,
|
|
94
|
-
cache,
|
|
95
|
-
data_cache,
|
|
96
|
-
component_cache,
|
|
97
|
-
artifact_cache,
|
|
98
|
-
ssr_signals,
|
|
99
|
-
last_variables
|
|
100
|
-
} = useRouterContext();
|
|
101
|
-
const [session] = useSession();
|
|
102
|
-
function load_query({
|
|
103
|
-
id,
|
|
104
|
-
artifact,
|
|
105
|
-
variables: variables2
|
|
106
|
-
}) {
|
|
107
|
-
for (const artifact2 of Object.keys(page.documents)) {
|
|
108
|
-
last_variables.set(artifact2, variables2);
|
|
109
|
-
}
|
|
110
|
-
if (ssr_signals.has(id)) {
|
|
111
|
-
return ssr_signals.get(id);
|
|
112
|
-
}
|
|
113
|
-
const observer = data_cache.has(artifact.name) ? data_cache.get(artifact.name) : client.observe({ artifact, cache });
|
|
114
|
-
let resolve = () => {
|
|
115
|
-
};
|
|
116
|
-
let reject = () => {
|
|
117
|
-
};
|
|
118
|
-
const promise = new Promise((res, rej) => {
|
|
119
|
-
resolve = res;
|
|
120
|
-
reject = rej;
|
|
121
|
-
observer.send({
|
|
122
|
-
variables: variables2,
|
|
123
|
-
session
|
|
124
|
-
}).then(async () => {
|
|
125
|
-
data_cache.set(id, observer);
|
|
126
|
-
if (observer.state.errors && observer.state.errors.length > 0) {
|
|
127
|
-
reject(observer.state.errors.map((e) => e.message).join("\n"));
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
injectToStream?.(`
|
|
131
|
-
<script>
|
|
132
|
-
{
|
|
133
|
-
window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
|
|
134
|
-
|
|
135
|
-
const artifactName = "${artifact.name}"
|
|
136
|
-
const value = ${JSON.stringify(
|
|
137
|
-
marshalSelection({
|
|
138
|
-
selection: observer.artifact.selection,
|
|
139
|
-
data: observer.state.data
|
|
140
|
-
})
|
|
141
|
-
)}
|
|
142
|
-
|
|
143
|
-
// if the data is pending, we need to resolve it
|
|
144
|
-
if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
|
|
145
|
-
// before we resolve the pending signals,
|
|
146
|
-
// fill the data cache with values we got on the server
|
|
147
|
-
const new_store = window.__houdini__client__.observe({
|
|
148
|
-
artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
|
|
149
|
-
cache: window.__houdini__cache__,
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
// we're pushing this store onto the client, it should be initialized
|
|
153
|
-
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
|
|
154
|
-
setup: true,
|
|
155
|
-
variables: ${JSON.stringify(
|
|
156
|
-
marshalInputs({
|
|
157
|
-
artifact: observer.artifact,
|
|
158
|
-
input: variables2,
|
|
159
|
-
config: configFile
|
|
160
|
-
})
|
|
161
|
-
)}
|
|
162
|
-
}).then(() => {
|
|
163
|
-
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
// if there are no data caches available we need to populate the pending one instead
|
|
170
|
-
if (!window.__houdini__nav_caches__) {
|
|
171
|
-
if (!window.__houdini__pending_data__) {
|
|
172
|
-
window.__houdini__pending_data__ = {}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (!window.__houdini__pending_variables__) {
|
|
176
|
-
window.__houdini__pending_variables__ = {}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (!window.__houdini__pending_artifacts__) {
|
|
180
|
-
window.__houdini__pending_artifacts__ = {}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
window.__houdini__pending_variables__[artifactName] = ${JSON.stringify(observer.state.variables)}
|
|
185
|
-
window.__houdini__pending_data__[artifactName] = value
|
|
186
|
-
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
|
|
187
|
-
|
|
188
|
-
// if this payload finishes off an ssr request, we need to resolve the signal
|
|
189
|
-
if (window.__houdini__nav_caches__?.ssr_signals.has(artifactName)) {
|
|
190
|
-
|
|
191
|
-
// if the data showed up on the client before
|
|
192
|
-
if (window.__houdini__nav_caches__.data_cache.has(artifactName)) {
|
|
193
|
-
// we're pushing this store onto the client, it should be initialized
|
|
194
|
-
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
|
|
195
|
-
setup: true,
|
|
196
|
-
variables: ${JSON.stringify(
|
|
197
|
-
marshalInputs({
|
|
198
|
-
artifact: observer.artifact,
|
|
199
|
-
input: variables2,
|
|
200
|
-
config: configFile
|
|
201
|
-
})
|
|
202
|
-
)}
|
|
203
|
-
})
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
// trigger the signal
|
|
208
|
-
window.__houdini__nav_caches__.ssr_signals.get(artifactName).resolve()
|
|
209
|
-
window.__houdini__nav_caches__.ssr_signals.delete(artifactName)
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
<\/script>
|
|
213
|
-
`);
|
|
214
|
-
resolve();
|
|
215
|
-
}).catch(reject);
|
|
216
|
-
});
|
|
217
|
-
const resolvable = { ...promise, resolve, reject };
|
|
218
|
-
if (!globalThis.window) {
|
|
219
|
-
ssr_signals.set(id, resolvable);
|
|
220
|
-
}
|
|
221
|
-
return resolvable;
|
|
222
|
-
}
|
|
223
|
-
function loadData(targetPage, variables2) {
|
|
224
|
-
if (!targetPage) {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
for (const [artifact, { variables: pageVariables }] of Object.entries(
|
|
228
|
-
targetPage.documents
|
|
229
|
-
)) {
|
|
230
|
-
if (!last_variables.has(artifact)) {
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
let last = {};
|
|
234
|
-
let usedVariables = {};
|
|
235
|
-
for (const variable of Object.keys(pageVariables)) {
|
|
236
|
-
last[variable] = last_variables.get(artifact)[variable];
|
|
237
|
-
usedVariables[variable] = (variables2 ?? {})[variable];
|
|
238
|
-
}
|
|
239
|
-
if (Object.keys(usedVariables ?? {}).length > 0 && !deepEquals(last, usedVariables)) {
|
|
240
|
-
data_cache.delete(artifact);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
const missing_artifacts = [];
|
|
244
|
-
const found_artifacts = {};
|
|
245
|
-
for (const key of Object.keys(targetPage.documents)) {
|
|
246
|
-
if (artifact_cache.has(key)) {
|
|
247
|
-
found_artifacts[key] = artifact_cache.get(key);
|
|
248
|
-
} else {
|
|
249
|
-
missing_artifacts.push(key);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
for (const artifact_id of missing_artifacts) {
|
|
253
|
-
targetPage.documents[artifact_id].artifact().then((mod) => {
|
|
254
|
-
const artifact = mod.default;
|
|
255
|
-
artifact_cache.set(artifact_id, artifact);
|
|
256
|
-
injectToStream?.(`
|
|
257
|
-
<script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""><\/script>
|
|
258
|
-
`);
|
|
259
|
-
load_query({ id: artifact.name, artifact, variables: variables2 });
|
|
260
|
-
}).catch((err) => {
|
|
261
|
-
console.log(err);
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
for (const artifact of Object.values(found_artifacts)) {
|
|
265
|
-
if (!data_cache.has(artifact.name)) {
|
|
266
|
-
load_query({ id: artifact.name, artifact, variables: variables2 });
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
async function loadComponent(targetPage) {
|
|
271
|
-
if (component_cache.has(targetPage.id)) {
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
const mod = await targetPage.component();
|
|
275
|
-
component_cache.set(targetPage.id, mod.default);
|
|
276
|
-
}
|
|
277
|
-
loadData(page, variables);
|
|
278
|
-
if (!component_cache.has(page.id)) {
|
|
279
|
-
throw loadComponent(page);
|
|
280
|
-
}
|
|
281
|
-
return {
|
|
282
|
-
loadData,
|
|
283
|
-
loadComponent
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
function RouterContextProvider({
|
|
287
|
-
children,
|
|
288
|
-
client,
|
|
289
|
-
cache,
|
|
290
|
-
artifact_cache,
|
|
291
|
-
component_cache,
|
|
292
|
-
data_cache,
|
|
293
|
-
ssr_signals,
|
|
294
|
-
last_variables,
|
|
295
|
-
session: ssrSession = {}
|
|
296
|
-
}) {
|
|
297
|
-
const [session, setSession] = React.useState(ssrSession);
|
|
298
|
-
const handleNewSession = React.useCallback((event) => {
|
|
299
|
-
setSession(event.detail);
|
|
300
|
-
}, []);
|
|
301
|
-
React.useEffect(() => {
|
|
302
|
-
window.addEventListener("_houdini_session_", handleNewSession);
|
|
303
|
-
return () => {
|
|
304
|
-
window.removeEventListener("_houdini_session_", handleNewSession);
|
|
305
|
-
};
|
|
306
|
-
}, []);
|
|
307
|
-
return /* @__PURE__ */ jsx(
|
|
308
|
-
Context.Provider,
|
|
309
|
-
{
|
|
310
|
-
value: {
|
|
311
|
-
client,
|
|
312
|
-
cache,
|
|
313
|
-
artifact_cache,
|
|
314
|
-
component_cache,
|
|
315
|
-
data_cache,
|
|
316
|
-
ssr_signals,
|
|
317
|
-
last_variables,
|
|
318
|
-
session,
|
|
319
|
-
setSession: (newSession) => setSession((old) => ({ ...old, ...newSession }))
|
|
320
|
-
},
|
|
321
|
-
children
|
|
322
|
-
}
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
function updateLocalSession(session) {
|
|
326
|
-
window.dispatchEvent(
|
|
327
|
-
new CustomEvent("_houdini_session_", {
|
|
328
|
-
bubbles: true,
|
|
329
|
-
detail: session
|
|
330
|
-
})
|
|
331
|
-
);
|
|
332
|
-
}
|
|
333
|
-
function useCurrentVariables() {
|
|
334
|
-
return React.useContext(VariableContext);
|
|
335
|
-
}
|
|
336
|
-
const VariableContext = React.createContext(null);
|
|
337
|
-
function useQueryResult(name) {
|
|
338
|
-
const { data_cache, artifact_cache } = useRouterContext();
|
|
339
|
-
const store_ref = data_cache.get(name);
|
|
340
|
-
const [storeValue, observer] = useDocumentStore({
|
|
341
|
-
artifact: store_ref.artifact,
|
|
342
|
-
observer: store_ref
|
|
343
|
-
});
|
|
344
|
-
const { data, errors } = storeValue;
|
|
345
|
-
if (errors && errors.length > 0) {
|
|
346
|
-
throw new Error(JSON.stringify(errors));
|
|
347
|
-
}
|
|
348
|
-
const handle = useDocumentHandle({
|
|
349
|
-
artifact: artifact_cache.get(name),
|
|
350
|
-
observer,
|
|
351
|
-
storeValue
|
|
352
|
-
});
|
|
353
|
-
return [data, handle];
|
|
354
|
-
}
|
|
355
|
-
function useLinkBehavior({
|
|
356
|
-
goto,
|
|
357
|
-
preload
|
|
358
|
-
}) {
|
|
359
|
-
useLinkNavigation({ goto });
|
|
360
|
-
if (!globalThis.navigator?.connection?.saveData) {
|
|
361
|
-
usePreload({ preload });
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
function useLinkNavigation({ goto }) {
|
|
365
|
-
const [pending, startTransition] = React.useTransition();
|
|
366
|
-
React.useEffect(() => {
|
|
367
|
-
const onClick = (e) => {
|
|
368
|
-
if (!e.target) {
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
const link = e.target?.closest("a");
|
|
372
|
-
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)) {
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
const target = link.attributes.getNamedItem("href")?.value;
|
|
376
|
-
if (!target || !target.startsWith("/")) {
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
e.preventDefault();
|
|
380
|
-
e.stopPropagation();
|
|
381
|
-
startTransition(() => {
|
|
382
|
-
goto(target);
|
|
383
|
-
});
|
|
384
|
-
};
|
|
385
|
-
window.addEventListener("click", onClick);
|
|
386
|
-
return () => {
|
|
387
|
-
window.removeEventListener("click", onClick);
|
|
388
|
-
};
|
|
389
|
-
}, []);
|
|
390
|
-
}
|
|
391
|
-
function usePreload({ preload }) {
|
|
392
|
-
const timeoutRef = React.useRef(null);
|
|
393
|
-
React.useEffect(() => {
|
|
394
|
-
const mouseMove = (e) => {
|
|
395
|
-
const target = e.target;
|
|
396
|
-
if (!(target instanceof HTMLElement)) {
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
const anchor = target.closest("a");
|
|
400
|
-
if (!anchor) {
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
let preloadWhichRaw = anchor.attributes.getNamedItem("data-houdini-preload")?.value;
|
|
404
|
-
let preloadWhich = !preloadWhichRaw || preloadWhichRaw === "true" ? "page" : preloadWhichRaw;
|
|
405
|
-
if (!PreloadWhich[preloadWhich]) {
|
|
406
|
-
console.log(
|
|
407
|
-
`invalid preload value "${preloadWhich}" must be "${PreloadWhich.component}", "${PreloadWhich.data}", or "${PreloadWhich.page}"`
|
|
408
|
-
);
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
if (timeoutRef.current) {
|
|
412
|
-
clearTimeout(timeoutRef.current);
|
|
413
|
-
}
|
|
414
|
-
timeoutRef.current = setTimeout(() => {
|
|
415
|
-
const url = anchor.attributes.getNamedItem("href")?.value;
|
|
416
|
-
if (!url) {
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
preload(url, preloadWhich);
|
|
420
|
-
}, 20);
|
|
421
|
-
};
|
|
422
|
-
document.addEventListener("mousemove", mouseMove);
|
|
423
|
-
return () => {
|
|
424
|
-
document.removeEventListener("mousemove", mouseMove);
|
|
425
|
-
};
|
|
426
|
-
}, []);
|
|
427
|
-
}
|
|
428
|
-
function router_cache({
|
|
429
|
-
pending_queries = [],
|
|
430
|
-
artifacts = {},
|
|
431
|
-
components = {},
|
|
432
|
-
initialData = {},
|
|
433
|
-
initialVariables = {},
|
|
434
|
-
initialArtifacts = {}
|
|
435
|
-
} = {}) {
|
|
436
|
-
const result = {
|
|
437
|
-
artifact_cache: suspense_cache(initialArtifacts),
|
|
438
|
-
component_cache: suspense_cache(),
|
|
439
|
-
data_cache: suspense_cache(initialData),
|
|
440
|
-
ssr_signals: suspense_cache(),
|
|
441
|
-
last_variables: suspense_cache()
|
|
442
|
-
};
|
|
443
|
-
for (const query of pending_queries) {
|
|
444
|
-
result.ssr_signals.set(query, signal_promise());
|
|
445
|
-
}
|
|
446
|
-
for (const [name, artifact] of Object.entries(artifacts)) {
|
|
447
|
-
result.artifact_cache.set(name, artifact);
|
|
448
|
-
}
|
|
449
|
-
for (const [name, component] of Object.entries(components)) {
|
|
450
|
-
result.component_cache.set(name, component);
|
|
451
|
-
}
|
|
452
|
-
for (const [name, variables] of Object.entries(initialVariables)) {
|
|
453
|
-
result.last_variables.set(name, variables);
|
|
454
|
-
}
|
|
455
|
-
return result;
|
|
456
|
-
}
|
|
457
|
-
const PageContext = React.createContext({ params: {} });
|
|
458
|
-
function PageContextProvider({
|
|
459
|
-
keys,
|
|
460
|
-
children
|
|
461
|
-
}) {
|
|
462
|
-
const location2 = useLocation();
|
|
463
|
-
const params = Object.fromEntries(
|
|
464
|
-
Object.entries(location2.params).filter(([key]) => keys.includes(key))
|
|
465
|
-
);
|
|
466
|
-
return /* @__PURE__ */ jsx(PageContext.Provider, { value: { params }, children });
|
|
467
|
-
}
|
|
468
|
-
function useRoute() {
|
|
469
|
-
return useContext(PageContext);
|
|
470
|
-
}
|
|
471
|
-
function signal_promise() {
|
|
472
|
-
let resolve = () => {
|
|
473
|
-
};
|
|
474
|
-
let reject = () => {
|
|
475
|
-
};
|
|
476
|
-
const promise = new Promise((res, rej) => {
|
|
477
|
-
resolve = res;
|
|
478
|
-
reject = rej;
|
|
479
|
-
});
|
|
480
|
-
return {
|
|
481
|
-
...promise,
|
|
482
|
-
resolve,
|
|
483
|
-
reject
|
|
484
|
-
};
|
|
485
|
-
}
|
|
486
|
-
export {
|
|
487
|
-
PageContextProvider,
|
|
488
|
-
Router,
|
|
489
|
-
RouterContextProvider,
|
|
490
|
-
router_cache,
|
|
491
|
-
updateLocalSession,
|
|
492
|
-
useCurrentVariables,
|
|
493
|
-
useQueryResult,
|
|
494
|
-
useRoute
|
|
495
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { LRUCache } from '$houdini/runtime/lib/lru';
|
|
2
|
-
export declare function suspense_cache<T>(initialData?: Record<string, T>): SuspenseCache<T>;
|
|
3
|
-
export declare class SuspenseCache<_Data> extends LRUCache<_Data> {
|
|
4
|
-
#private;
|
|
5
|
-
get(key: string): _Data;
|
|
6
|
-
set(key: string, value: _Data): void;
|
|
7
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { LRUCache } from "$houdini/runtime/lib/lru";
|
|
2
|
-
function suspense_cache(initialData) {
|
|
3
|
-
const cache = new SuspenseCache();
|
|
4
|
-
for (const [key, value] of Object.entries(initialData ?? {})) {
|
|
5
|
-
cache.set(key, value);
|
|
6
|
-
}
|
|
7
|
-
return cache;
|
|
8
|
-
}
|
|
9
|
-
class SuspenseCache extends LRUCache {
|
|
10
|
-
#callbacks = /* @__PURE__ */ new Map();
|
|
11
|
-
get(key) {
|
|
12
|
-
if (super.has(key)) {
|
|
13
|
-
return super.get(key);
|
|
14
|
-
}
|
|
15
|
-
throw new Promise((resolve, reject) => {
|
|
16
|
-
this.#subscribe(key, resolve, reject);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
set(key, value) {
|
|
20
|
-
super.set(key, value);
|
|
21
|
-
if (this.#callbacks.has(key)) {
|
|
22
|
-
this.#callbacks.get(key)?.forEach(({ resolve }) => resolve());
|
|
23
|
-
this.#callbacks.delete(key);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
#subscribe(key, resolve, reject) {
|
|
27
|
-
this.#callbacks.set(key, [...this.#callbacks.get(key) || [], { resolve, reject }]);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export {
|
|
31
|
-
SuspenseCache,
|
|
32
|
-
suspense_cache
|
|
33
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
-
};
|
package/build/server/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { renderToStream } from 'react-streaming-compat/server';
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var server_exports = {};
|
|
20
|
-
__export(server_exports, {
|
|
21
|
-
renderToStream: () => import_server.renderToStream
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(server_exports);
|
|
24
|
-
var import_server = require("react-streaming-compat/server");
|
|
25
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
-
0 && (module.exports = {
|
|
27
|
-
renderToStream
|
|
28
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|