houdini-react 0.0.0-20240329062150 → 0.0.0-20240402040259

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.
@@ -98,10 +98,10 @@ function Router({
98
98
  },
99
99
  preload(url, which) {
100
100
  const [page2, variables2] = (0, import_match.find_match)(import_config.default, manifest, url);
101
- if (["both", "component"].includes(which)) {
101
+ if (["page", "component"].includes(which)) {
102
102
  loadComponent(page2);
103
103
  }
104
- if (["both", "data"].includes(which)) {
104
+ if (["page", "data"].includes(which)) {
105
105
  loadData(page2, variables2);
106
106
  }
107
107
  }
@@ -125,9 +125,13 @@ function usePageData({
125
125
  last_variables
126
126
  } = useRouterContext();
127
127
  const [session] = useSession();
128
- function load_query({ id, artifact }) {
128
+ function load_query({
129
+ id,
130
+ artifact,
131
+ variables: variables2
132
+ }) {
129
133
  for (const artifact2 of Object.keys(page.documents)) {
130
- last_variables.set(artifact2, variables);
134
+ last_variables.set(artifact2, variables2);
131
135
  }
132
136
  if (ssr_signals.has(id)) {
133
137
  return ssr_signals.get(id);
@@ -140,10 +144,12 @@ function usePageData({
140
144
  const promise = new Promise((res, rej) => {
141
145
  resolve = res;
142
146
  reject = rej;
147
+ console.log("sending query", observer.artifact.name, variables2);
143
148
  observer.send({
144
- variables,
149
+ variables: variables2,
145
150
  session
146
151
  }).then(async () => {
152
+ console.log("query resolved", observer.artifact.name, observer.state);
147
153
  data_cache.set(id, observer);
148
154
  if (observer.state.errors && observer.state.errors.length > 0) {
149
155
  reject(observer.state.errors.map((e) => e.message).join("\n"));
@@ -177,7 +183,7 @@ function usePageData({
177
183
  variables: ${JSON.stringify(
178
184
  (0, import_scalars.marshalInputs)({
179
185
  artifact: observer.artifact,
180
- input: variables,
186
+ input: variables2,
181
187
  config: import_config.default
182
188
  })
183
189
  )}
@@ -218,7 +224,7 @@ function usePageData({
218
224
  variables: ${JSON.stringify(
219
225
  (0, import_scalars.marshalInputs)({
220
226
  artifact: observer.artifact,
221
- input: variables,
227
+ input: variables2,
222
228
  config: import_config.default
223
229
  })
224
230
  )}
@@ -275,14 +281,14 @@ function usePageData({
275
281
  injectToStream?.(`
276
282
  <script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""><\/script>
277
283
  `);
278
- load_query({ id: artifact.name, artifact });
284
+ load_query({ id: artifact.name, artifact, variables: variables2 });
279
285
  }).catch((err) => {
280
286
  console.log(err);
281
287
  });
282
288
  }
283
289
  for (const artifact of Object.values(found_artifacts)) {
284
290
  if (!data_cache.has(artifact.name)) {
285
- load_query({ id: artifact.name, artifact });
291
+ load_query({ id: artifact.name, artifact, variables: variables2 });
286
292
  }
287
293
  }
288
294
  }
@@ -451,10 +457,14 @@ function usePreload({ preload }) {
451
457
  import_react.default.useEffect(() => {
452
458
  const mouseMove = (e) => {
453
459
  const target = e.target;
454
- if (!(target instanceof HTMLAnchorElement)) {
460
+ if (!(target instanceof HTMLElement)) {
455
461
  return;
456
462
  }
457
- let preloadWhichRaw = target.attributes.getNamedItem("data-houdini-preload")?.value;
463
+ const anchor = target.closest("a");
464
+ if (!anchor) {
465
+ return;
466
+ }
467
+ let preloadWhichRaw = anchor.attributes.getNamedItem("data-houdini-preload")?.value;
458
468
  let preloadWhich = !preloadWhichRaw || preloadWhichRaw === "true" ? "page" : preloadWhichRaw;
459
469
  if (!PreloadWhich[preloadWhich]) {
460
470
  console.log(
@@ -466,7 +476,7 @@ function usePreload({ preload }) {
466
476
  clearTimeout(timeoutRef.current);
467
477
  }
468
478
  timeoutRef.current = setTimeout(() => {
469
- const url = target.attributes.getNamedItem("href")?.value;
479
+ const url = anchor.attributes.getNamedItem("href")?.value;
470
480
  if (!url) {
471
481
  return;
472
482
  }
@@ -57,10 +57,10 @@ function Router({
57
57
  },
58
58
  preload(url, which) {
59
59
  const [page2, variables2] = find_match(configFile, manifest, url);
60
- if (["both", "component"].includes(which)) {
60
+ if (["page", "component"].includes(which)) {
61
61
  loadComponent(page2);
62
62
  }
63
- if (["both", "data"].includes(which)) {
63
+ if (["page", "data"].includes(which)) {
64
64
  loadData(page2, variables2);
65
65
  }
66
66
  }
@@ -84,9 +84,13 @@ function usePageData({
84
84
  last_variables
85
85
  } = useRouterContext();
86
86
  const [session] = useSession();
87
- function load_query({ id, artifact }) {
87
+ function load_query({
88
+ id,
89
+ artifact,
90
+ variables: variables2
91
+ }) {
88
92
  for (const artifact2 of Object.keys(page.documents)) {
89
- last_variables.set(artifact2, variables);
93
+ last_variables.set(artifact2, variables2);
90
94
  }
91
95
  if (ssr_signals.has(id)) {
92
96
  return ssr_signals.get(id);
@@ -99,10 +103,12 @@ function usePageData({
99
103
  const promise = new Promise((res, rej) => {
100
104
  resolve = res;
101
105
  reject = rej;
106
+ console.log("sending query", observer.artifact.name, variables2);
102
107
  observer.send({
103
- variables,
108
+ variables: variables2,
104
109
  session
105
110
  }).then(async () => {
111
+ console.log("query resolved", observer.artifact.name, observer.state);
106
112
  data_cache.set(id, observer);
107
113
  if (observer.state.errors && observer.state.errors.length > 0) {
108
114
  reject(observer.state.errors.map((e) => e.message).join("\n"));
@@ -136,7 +142,7 @@ function usePageData({
136
142
  variables: ${JSON.stringify(
137
143
  marshalInputs({
138
144
  artifact: observer.artifact,
139
- input: variables,
145
+ input: variables2,
140
146
  config: configFile
141
147
  })
142
148
  )}
@@ -177,7 +183,7 @@ function usePageData({
177
183
  variables: ${JSON.stringify(
178
184
  marshalInputs({
179
185
  artifact: observer.artifact,
180
- input: variables,
186
+ input: variables2,
181
187
  config: configFile
182
188
  })
183
189
  )}
@@ -234,14 +240,14 @@ function usePageData({
234
240
  injectToStream?.(`
235
241
  <script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""><\/script>
236
242
  `);
237
- load_query({ id: artifact.name, artifact });
243
+ load_query({ id: artifact.name, artifact, variables: variables2 });
238
244
  }).catch((err) => {
239
245
  console.log(err);
240
246
  });
241
247
  }
242
248
  for (const artifact of Object.values(found_artifacts)) {
243
249
  if (!data_cache.has(artifact.name)) {
244
- load_query({ id: artifact.name, artifact });
250
+ load_query({ id: artifact.name, artifact, variables: variables2 });
245
251
  }
246
252
  }
247
253
  }
@@ -410,10 +416,14 @@ function usePreload({ preload }) {
410
416
  React.useEffect(() => {
411
417
  const mouseMove = (e) => {
412
418
  const target = e.target;
413
- if (!(target instanceof HTMLAnchorElement)) {
419
+ if (!(target instanceof HTMLElement)) {
414
420
  return;
415
421
  }
416
- let preloadWhichRaw = target.attributes.getNamedItem("data-houdini-preload")?.value;
422
+ const anchor = target.closest("a");
423
+ if (!anchor) {
424
+ return;
425
+ }
426
+ let preloadWhichRaw = anchor.attributes.getNamedItem("data-houdini-preload")?.value;
417
427
  let preloadWhich = !preloadWhichRaw || preloadWhichRaw === "true" ? "page" : preloadWhichRaw;
418
428
  if (!PreloadWhich[preloadWhich]) {
419
429
  console.log(
@@ -425,7 +435,7 @@ function usePreload({ preload }) {
425
435
  clearTimeout(timeoutRef.current);
426
436
  }
427
437
  timeoutRef.current = setTimeout(() => {
428
- const url = target.attributes.getNamedItem("href")?.value;
438
+ const url = anchor.attributes.getNamedItem("href")?.value;
429
439
  if (!url) {
430
440
  return;
431
441
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini-react",
3
- "version": "0.0.0-20240329062150",
3
+ "version": "0.0.0-20240402040259",
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": "^0.0.0-20240329062150"
46
+ "houdini": "^0.0.0-20240402040259"
47
47
  },
48
48
  "files": [
49
49
  "build"