houdini-react 1.2.27 → 1.2.29

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.
Files changed (144) hide show
  1. package/build/plugin/codegen/entries/documentWrappers.d.ts +6 -0
  2. package/build/plugin/codegen/{entries.d.ts → entries/fallbacks.d.ts} +2 -2
  3. package/build/plugin/codegen/entries/index.d.ts +16 -0
  4. package/build/plugin/codegen/entries/pages.d.ts +2 -0
  5. package/build/plugin/codegen/index.d.ts +6 -2
  6. package/build/plugin/codegen/render.d.ts +3 -1
  7. package/build/plugin/vite.d.ts +3 -2
  8. package/build/plugin-cjs/index.js +1629 -970
  9. package/build/plugin-esm/index.js +1629 -970
  10. package/build/runtime/componentFields.d.ts +9 -0
  11. package/build/runtime/index.d.ts +3 -1
  12. package/build/runtime/routing/Router.d.ts +6 -5
  13. package/build/runtime-cjs/componentFields.d.ts +9 -0
  14. package/build/runtime-cjs/componentFields.js +83 -0
  15. package/build/runtime-cjs/index.d.ts +3 -1
  16. package/build/runtime-cjs/index.js +2 -2
  17. package/build/runtime-cjs/routing/Router.d.ts +6 -5
  18. package/build/runtime-cjs/routing/Router.js +113 -68
  19. package/build/runtime-esm/componentFields.d.ts +9 -0
  20. package/build/runtime-esm/componentFields.js +59 -0
  21. package/build/runtime-esm/index.d.ts +3 -1
  22. package/build/runtime-esm/index.js +2 -2
  23. package/build/runtime-esm/routing/Router.d.ts +6 -5
  24. package/build/runtime-esm/routing/Router.js +113 -68
  25. package/build/server/index.d.ts +1 -0
  26. package/build/{runtime-cjs/server → server-cjs}/index.js +2 -2
  27. package/build/server-cjs/package.json +1 -0
  28. package/build/server-esm/index.js +4 -0
  29. package/build/server-esm/package.json +1 -0
  30. package/package.json +17 -7
  31. package/build/runtime/server/index.d.ts +0 -17
  32. package/build/runtime/server/renderToStream/createBuffer.d.ts +0 -17
  33. package/build/runtime/server/renderToStream/createPipeWrapper.d.ts +0 -12
  34. package/build/runtime/server/renderToStream/createReadableWrapper.d.ts +0 -6
  35. package/build/runtime/server/renderToStream/loadNodeStreamModule.d.ts +0 -10
  36. package/build/runtime/server/renderToStream/resolveSeoStrategy.d.ts +0 -9
  37. package/build/runtime/server/renderToStream.d.ts +0 -28
  38. package/build/runtime/server/shared/initData.d.ts +0 -8
  39. package/build/runtime/server/shared/key.d.ts +0 -4
  40. package/build/runtime/server/shared/utils.d.ts +0 -3
  41. package/build/runtime/server/useStream.d.ts +0 -9
  42. package/build/runtime/server/utils/assert.d.ts +0 -15
  43. package/build/runtime/server/utils/createErrorWithCleanStackTrace.d.ts +0 -2
  44. package/build/runtime/server/utils/debug.d.ts +0 -14
  45. package/build/runtime/server/utils/getGlobalVariable.d.ts +0 -4
  46. package/build/runtime/server/utils/isBrowser.d.ts +0 -2
  47. package/build/runtime/server/utils/isCallable.d.ts +0 -2
  48. package/build/runtime/server/utils/isClientSide.d.ts +0 -2
  49. package/build/runtime/server/utils/isPromise.d.ts +0 -1
  50. package/build/runtime/server/utils/isServerSide.d.ts +0 -2
  51. package/build/runtime/server/utils/objectAssign.d.ts +0 -2
  52. package/build/runtime/server/utils/projectInfo.d.ts +0 -10
  53. package/build/runtime/server/utils.d.ts +0 -4
  54. package/build/runtime-cjs/server/index.d.ts +0 -17
  55. package/build/runtime-cjs/server/renderToStream/createBuffer.d.ts +0 -17
  56. package/build/runtime-cjs/server/renderToStream/createBuffer.js +0 -101
  57. package/build/runtime-cjs/server/renderToStream/createPipeWrapper.d.ts +0 -12
  58. package/build/runtime-cjs/server/renderToStream/createPipeWrapper.js +0 -90
  59. package/build/runtime-cjs/server/renderToStream/createReadableWrapper.d.ts +0 -6
  60. package/build/runtime-cjs/server/renderToStream/createReadableWrapper.js +0 -85
  61. package/build/runtime-cjs/server/renderToStream/loadNodeStreamModule.d.ts +0 -10
  62. package/build/runtime-cjs/server/renderToStream/loadNodeStreamModule.js +0 -51
  63. package/build/runtime-cjs/server/renderToStream/resolveSeoStrategy.d.ts +0 -9
  64. package/build/runtime-cjs/server/renderToStream/resolveSeoStrategy.js +0 -44
  65. package/build/runtime-cjs/server/renderToStream.d.ts +0 -28
  66. package/build/runtime-cjs/server/renderToStream.js +0 -183
  67. package/build/runtime-cjs/server/shared/initData.d.ts +0 -8
  68. package/build/runtime-cjs/server/shared/initData.js +0 -28
  69. package/build/runtime-cjs/server/shared/key.d.ts +0 -4
  70. package/build/runtime-cjs/server/shared/key.js +0 -45
  71. package/build/runtime-cjs/server/shared/utils.d.ts +0 -3
  72. package/build/runtime-cjs/server/shared/utils.js +0 -20
  73. package/build/runtime-cjs/server/useStream.d.ts +0 -9
  74. package/build/runtime-cjs/server/useStream.js +0 -44
  75. package/build/runtime-cjs/server/utils/assert.d.ts +0 -15
  76. package/build/runtime-cjs/server/utils/assert.js +0 -119
  77. package/build/runtime-cjs/server/utils/createErrorWithCleanStackTrace.d.ts +0 -2
  78. package/build/runtime-cjs/server/utils/createErrorWithCleanStackTrace.js +0 -62
  79. package/build/runtime-cjs/server/utils/debug.d.ts +0 -14
  80. package/build/runtime-cjs/server/utils/debug.js +0 -112
  81. package/build/runtime-cjs/server/utils/getGlobalVariable.d.ts +0 -4
  82. package/build/runtime-cjs/server/utils/getGlobalVariable.js +0 -32
  83. package/build/runtime-cjs/server/utils/isBrowser.d.ts +0 -2
  84. package/build/runtime-cjs/server/utils/isBrowser.js +0 -30
  85. package/build/runtime-cjs/server/utils/isCallable.d.ts +0 -2
  86. package/build/runtime-cjs/server/utils/isCallable.js +0 -30
  87. package/build/runtime-cjs/server/utils/isClientSide.d.ts +0 -2
  88. package/build/runtime-cjs/server/utils/isClientSide.js +0 -30
  89. package/build/runtime-cjs/server/utils/isPromise.d.ts +0 -1
  90. package/build/runtime-cjs/server/utils/isPromise.js +0 -31
  91. package/build/runtime-cjs/server/utils/isServerSide.d.ts +0 -2
  92. package/build/runtime-cjs/server/utils/isServerSide.js +0 -31
  93. package/build/runtime-cjs/server/utils/objectAssign.d.ts +0 -2
  94. package/build/runtime-cjs/server/utils/objectAssign.js +0 -30
  95. package/build/runtime-cjs/server/utils/projectInfo.d.ts +0 -10
  96. package/build/runtime-cjs/server/utils/projectInfo.js +0 -37
  97. package/build/runtime-cjs/server/utils.d.ts +0 -4
  98. package/build/runtime-cjs/server/utils.js +0 -21
  99. package/build/runtime-esm/server/index.d.ts +0 -17
  100. package/build/runtime-esm/server/index.js +0 -4
  101. package/build/runtime-esm/server/renderToStream/createBuffer.d.ts +0 -17
  102. package/build/runtime-esm/server/renderToStream/createBuffer.js +0 -77
  103. package/build/runtime-esm/server/renderToStream/createPipeWrapper.d.ts +0 -12
  104. package/build/runtime-esm/server/renderToStream/createPipeWrapper.js +0 -66
  105. package/build/runtime-esm/server/renderToStream/createReadableWrapper.d.ts +0 -6
  106. package/build/runtime-esm/server/renderToStream/createReadableWrapper.js +0 -61
  107. package/build/runtime-esm/server/renderToStream/loadNodeStreamModule.d.ts +0 -10
  108. package/build/runtime-esm/server/renderToStream/loadNodeStreamModule.js +0 -20
  109. package/build/runtime-esm/server/renderToStream/resolveSeoStrategy.d.ts +0 -9
  110. package/build/runtime-esm/server/renderToStream/resolveSeoStrategy.js +0 -20
  111. package/build/runtime-esm/server/renderToStream.d.ts +0 -28
  112. package/build/runtime-esm/server/renderToStream.js +0 -152
  113. package/build/runtime-esm/server/shared/initData.d.ts +0 -8
  114. package/build/runtime-esm/server/shared/initData.js +0 -4
  115. package/build/runtime-esm/server/shared/key.d.ts +0 -4
  116. package/build/runtime-esm/server/shared/key.js +0 -20
  117. package/build/runtime-esm/server/shared/utils.d.ts +0 -3
  118. package/build/runtime-esm/server/shared/utils.js +0 -3
  119. package/build/runtime-esm/server/useStream.d.ts +0 -9
  120. package/build/runtime-esm/server/useStream.js +0 -13
  121. package/build/runtime-esm/server/utils/assert.d.ts +0 -15
  122. package/build/runtime-esm/server/utils/assert.js +0 -91
  123. package/build/runtime-esm/server/utils/createErrorWithCleanStackTrace.d.ts +0 -2
  124. package/build/runtime-esm/server/utils/createErrorWithCleanStackTrace.js +0 -38
  125. package/build/runtime-esm/server/utils/debug.d.ts +0 -14
  126. package/build/runtime-esm/server/utils/debug.js +0 -87
  127. package/build/runtime-esm/server/utils/getGlobalVariable.d.ts +0 -4
  128. package/build/runtime-esm/server/utils/getGlobalVariable.js +0 -8
  129. package/build/runtime-esm/server/utils/isBrowser.d.ts +0 -2
  130. package/build/runtime-esm/server/utils/isBrowser.js +0 -6
  131. package/build/runtime-esm/server/utils/isCallable.d.ts +0 -2
  132. package/build/runtime-esm/server/utils/isCallable.js +0 -6
  133. package/build/runtime-esm/server/utils/isClientSide.d.ts +0 -2
  134. package/build/runtime-esm/server/utils/isClientSide.js +0 -6
  135. package/build/runtime-esm/server/utils/isPromise.d.ts +0 -1
  136. package/build/runtime-esm/server/utils/isPromise.js +0 -7
  137. package/build/runtime-esm/server/utils/isServerSide.d.ts +0 -2
  138. package/build/runtime-esm/server/utils/isServerSide.js +0 -7
  139. package/build/runtime-esm/server/utils/objectAssign.d.ts +0 -2
  140. package/build/runtime-esm/server/utils/objectAssign.js +0 -6
  141. package/build/runtime-esm/server/utils/projectInfo.d.ts +0 -10
  142. package/build/runtime-esm/server/utils/projectInfo.js +0 -13
  143. package/build/runtime-esm/server/utils.d.ts +0 -4
  144. package/build/runtime-esm/server/utils.js +0 -4
@@ -18,14 +18,14 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
18
18
  assetPrefix: string;
19
19
  injectToStream?: undefined | ((chunk: string) => void);
20
20
  }): JSX.Element;
21
- export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, pending_cache, last_variables, session: ssrSession, }: {
21
+ export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
22
22
  children: React.ReactElement;
23
23
  client: HoudiniClient;
24
24
  cache: Cache;
25
25
  artifact_cache: SuspenseCache<QueryArtifact>;
26
26
  component_cache: SuspenseCache<(props: any) => React.ReactElement>;
27
27
  data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
28
- pending_cache: PendingCache;
28
+ ssr_signals: PendingCache;
29
29
  last_variables: LRUCache<GraphQLVariables>;
30
30
  session?: App.Session;
31
31
  }): JSX.Element;
@@ -35,7 +35,7 @@ type RouterContext = {
35
35
  artifact_cache: SuspenseCache<QueryArtifact>;
36
36
  component_cache: SuspenseCache<(props: any) => React.ReactElement>;
37
37
  data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
38
- pending_cache: PendingCache;
38
+ ssr_signals: PendingCache;
39
39
  last_variables: LRUCache<GraphQLVariables>;
40
40
  session: App.Session;
41
41
  };
@@ -55,13 +55,14 @@ export type RouterCache = {
55
55
  component_cache: SuspenseCache<(props: any) => React.ReactElement>;
56
56
  data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
57
57
  last_variables: LRUCache<GraphQLVariables>;
58
- pending_cache: PendingCache;
58
+ ssr_signals: PendingCache;
59
59
  };
60
- export declare function router_cache({ pending_queries, artifacts, components, initialData, initialArtifacts, }?: {
60
+ export declare function router_cache({ pending_queries, artifacts, components, initialData, initialVariables, initialArtifacts, }?: {
61
61
  pending_queries?: string[];
62
62
  artifacts?: Record<string, QueryArtifact>;
63
63
  components?: Record<string, (props: any) => React.ReactElement>;
64
64
  initialData?: Record<string, DocumentStore<GraphQLObject, GraphQLVariables>>;
65
+ initialVariables?: Record<string, GraphQLVariables>;
65
66
  initialArtifacts?: Record<string, QueryArtifact>;
66
67
  }): RouterCache;
67
68
  export {};
@@ -15,10 +15,10 @@ function Router({
15
15
  assetPrefix,
16
16
  injectToStream
17
17
  }) {
18
- const [current, setCurrent] = React.useState(() => {
18
+ const [currentURL, setCurrentURL] = React.useState(() => {
19
19
  return initialURL || window.location.pathname;
20
20
  });
21
- const [page, variables] = find_match(manifest, current);
21
+ const [page, variables] = find_match(manifest, currentURL);
22
22
  const { loadData, loadComponent } = usePageData({
23
23
  page,
24
24
  variables,
@@ -28,16 +28,16 @@ function Router({
28
28
  const { component_cache } = useRouterContext();
29
29
  const PageComponent = component_cache.get(page.id);
30
30
  React.useEffect(() => {
31
- if (globalThis.window && window.location.pathname !== current) {
32
- window.history.pushState({}, "", current);
31
+ if (globalThis.window && window.location.pathname !== currentURL) {
32
+ window.history.pushState({}, "", currentURL);
33
33
  }
34
- }, [current]);
34
+ }, [currentURL]);
35
35
  React.useEffect(() => {
36
36
  if (!globalThis.window) {
37
37
  return;
38
38
  }
39
39
  const onChange = (evt) => {
40
- setCurrent(window.location.pathname);
40
+ setCurrentURL(window.location.pathname);
41
41
  };
42
42
  window.addEventListener("popstate", onChange);
43
43
  return () => {
@@ -45,7 +45,9 @@ function Router({
45
45
  };
46
46
  }, []);
47
47
  useLinkBehavior({
48
- goto: setCurrent,
48
+ goto: (val) => {
49
+ setCurrentURL(val);
50
+ },
49
51
  preload(url, which) {
50
52
  const [page2, variables2] = find_match(manifest, url);
51
53
  if (["both", "component"].includes(which)) {
@@ -56,7 +58,7 @@ function Router({
56
58
  }
57
59
  }
58
60
  });
59
- return /* @__PURE__ */ jsx(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ jsx(PageComponent, { url: current }) });
61
+ return /* @__PURE__ */ jsx(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ jsx(PageComponent, { url: currentURL }, page.id) });
60
62
  }
61
63
  function usePageData({
62
64
  page,
@@ -70,14 +72,18 @@ function usePageData({
70
72
  data_cache,
71
73
  component_cache,
72
74
  artifact_cache,
73
- pending_cache,
75
+ ssr_signals,
74
76
  last_variables
75
77
  } = useRouterContext();
76
78
  const session = useSession();
77
79
  function load_query({ id, artifact }) {
78
- last_variables.set(page.id, variables);
79
- if (pending_cache.has(id)) {
80
- return pending_cache.get(id);
80
+ for (const artifact2 of Object.keys(page.documents)) {
81
+ last_variables.set(artifact2, variables);
82
+ }
83
+ console.log("loading query", artifact.name);
84
+ if (ssr_signals.has(id)) {
85
+ console.log("using ssr signal", id);
86
+ return ssr_signals.get(id);
81
87
  }
82
88
  const observer = client.observe({ artifact, cache });
83
89
  let resolve = () => {
@@ -87,71 +93,102 @@ function usePageData({
87
93
  const promise = new Promise((res, rej) => {
88
94
  resolve = res;
89
95
  reject = rej;
96
+ console.log("sending query", id, variables);
90
97
  observer.send({
91
98
  variables,
92
99
  cacheParams: { disableSubscriptions: true },
93
100
  session
94
101
  }).then(() => {
102
+ console.log("resolved query", id, variables);
95
103
  data_cache.set(id, observer);
96
104
  injectToStream?.(`
97
105
  <script>
98
- window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
106
+ {
107
+ window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
99
108
 
100
- const artifactName = "${artifact.name}"
101
- const value = ${JSON.stringify(observer.state.data)}
109
+ const artifactName = "${artifact.name}"
110
+ const value = ${JSON.stringify(observer.state.data)}
102
111
 
103
- // if the data is pending, we need to resolve it
104
- if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
105
- // before we resolve the pending signals,
106
- // fill the data cache with values we got on the server
107
- const new_store = window.__houdini__client__.observe({
108
- artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
109
- cache: window.__houdini__cache__,
110
- initialValue: value
111
- })
112
+ // if the data is pending, we need to resolve it
113
+ if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
114
+ // before we resolve the pending signals,
115
+ // fill the data cache with values we got on the server
116
+ const new_store = window.__houdini__client__.observe({
117
+ artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
118
+ cache: window.__houdini__cache__,
119
+ initialValue: value,
120
+ })
112
121
 
113
- window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
114
- }
122
+ window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
123
+ }
115
124
 
116
125
 
117
- // if there are no data caches available we need to populate the pending one instead
118
- if (!window.__houdini__nav_caches__) {
119
- if (!window.__houdini__pending_data__) {
120
- window.__houdini__pending_data__ = {}
121
- }
126
+ // if there are no data caches available we need to populate the pending one instead
127
+ if (!window.__houdini__nav_caches__) {
128
+ if (!window.__houdini__pending_data__) {
129
+ window.__houdini__pending_data__ = {}
130
+ }
131
+
132
+ if (!window.__houdini__pending_variables__) {
133
+ window.__houdini__pending_variables__ = {}
134
+ }
135
+
136
+ if (!window.__houdini__pending_artifacts__) {
137
+ window.__houdini__pending_artifacts__ = {}
138
+ }
122
139
 
123
- if (!window.__houdini__pending_artifacts__) {
124
- window.__houdini__pending_artifacts__ = {}
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)}
125
143
  }
126
144
 
127
- window.__houdini__pending_data__[artifactName] = value
128
- window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
129
- }
145
+ // if this payload finishes off an ssr request, we need to resolve the signal
146
+ if (window.__houdini__nav_caches__?.ssr_signals.has(artifactName)) {
147
+
148
+ // if the data showed up on the client before
149
+ if (window.__houdini__nav_caches__.data_cache.has(artifactName)) {
150
+ // we're pushing this store onto the client, it should be initialized
151
+ window.__houdini__nav_caches__.data_cache.get(artifactName).send({
152
+ setup: true,
153
+ variables: ${JSON.stringify(variables)}
154
+ })
155
+ }
130
156
 
131
- if (window.__houdini__nav_caches__?.pending_cache.has(artifactName)) {
132
- // we're pushing this store onto the client, it should be initialized
133
- new_store.send({
134
- setup: true,
135
- variables: ${JSON.stringify(variables)}
136
- })
137
157
 
138
- // notify anyone waiting on the pending cache
139
- window.__houdini__nav_caches__.pending_cache.get(artifactName).resolve()
140
- window.__houdini__nav_caches__.pending_cache.delete(artifactName)
158
+ console.log('clearing ssr signal', artifactName)
159
+ // trigger the signal
160
+ window.__houdini__nav_caches__.ssr_signals.get(artifactName).resolve()
161
+ window.__houdini__nav_caches__.ssr_signals.delete(artifactName)
162
+ }
141
163
  }
142
164
  <\/script>
143
165
  `);
144
166
  resolve();
145
- }).catch(reject).finally(() => {
146
- pending_cache.delete(id);
147
- });
167
+ }).catch(reject);
148
168
  });
149
- pending_cache.set(id, { ...promise, resolve, reject });
150
- return pending_cache.get(id);
169
+ const resolvable = { ...promise, resolve, reject };
170
+ if (!globalThis.window) {
171
+ console.log("setting ssr signal");
172
+ ssr_signals.set(id, resolvable);
173
+ }
174
+ return resolvable;
151
175
  }
152
176
  function loadData(targetPage, variables2) {
153
- if (last_variables.has(targetPage.id) && !deepEquals(last_variables.get(targetPage.id), variables2)) {
154
- data_cache.clear();
177
+ for (const [artifact, { variables: pageVariables }] of Object.entries(
178
+ targetPage.documents
179
+ )) {
180
+ if (!last_variables.has(artifact)) {
181
+ continue;
182
+ }
183
+ let last = {};
184
+ let usedVariables = {};
185
+ for (const variable of pageVariables) {
186
+ last[variable] = last_variables.get(artifact)[variable];
187
+ usedVariables[variable] = (variables2 ?? {})[variable];
188
+ }
189
+ if (Object.keys(usedVariables ?? {}).length > 0 && !deepEquals(last, usedVariables)) {
190
+ data_cache.delete(artifact);
191
+ }
155
192
  }
156
193
  const missing_artifacts = [];
157
194
  const found_artifacts = {};
@@ -203,7 +240,7 @@ function RouterContextProvider({
203
240
  artifact_cache,
204
241
  component_cache,
205
242
  data_cache,
206
- pending_cache,
243
+ ssr_signals,
207
244
  last_variables,
208
245
  session: ssrSession = {}
209
246
  }) {
@@ -226,7 +263,7 @@ function RouterContextProvider({
226
263
  artifact_cache,
227
264
  component_cache,
228
265
  data_cache,
229
- pending_cache,
266
+ ssr_signals,
230
267
  last_variables,
231
268
  session
232
269
  },
@@ -238,7 +275,6 @@ const Context = React.createContext(null);
238
275
  const useRouterContext = () => {
239
276
  const ctx = React.useContext(Context);
240
277
  if (!ctx) {
241
- console.log(ctx);
242
278
  throw new Error("Could not find router context");
243
279
  }
244
280
  return ctx;
@@ -285,21 +321,26 @@ function useLinkNavigation({ goto }) {
285
321
  const [pending, startTransition] = React.useTransition();
286
322
  React.useEffect(() => {
287
323
  const onClick = (e) => {
324
+ if (!e.target) {
325
+ return;
326
+ }
288
327
  const link = e.target?.closest("a");
289
- 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) {
290
- const target = link.attributes.getNamedItem("href")?.value;
291
- if (!target || !target.startsWith("/")) {
292
- return;
293
- }
294
- e.preventDefault();
295
- startTransition(() => {
296
- goto(target);
297
- });
328
+ 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)) {
329
+ return;
330
+ }
331
+ const target = link.attributes.getNamedItem("href")?.value;
332
+ if (!target || !target.startsWith("/")) {
333
+ return;
298
334
  }
335
+ e.preventDefault();
336
+ e.stopPropagation();
337
+ startTransition(() => {
338
+ goto(target);
339
+ });
299
340
  };
300
- document.addEventListener("click", onClick);
341
+ window.addEventListener("click", onClick);
301
342
  return () => {
302
- document.removeEventListener("click", onClick);
343
+ window.removeEventListener("click", onClick);
303
344
  };
304
345
  }, []);
305
346
  }
@@ -341,17 +382,18 @@ function router_cache({
341
382
  artifacts = {},
342
383
  components = {},
343
384
  initialData = {},
385
+ initialVariables = {},
344
386
  initialArtifacts = {}
345
387
  } = {}) {
346
388
  const result = {
347
389
  artifact_cache: suspense_cache(initialArtifacts),
348
390
  component_cache: suspense_cache(),
349
391
  data_cache: suspense_cache(initialData),
350
- pending_cache: suspense_cache(),
392
+ ssr_signals: suspense_cache(),
351
393
  last_variables: suspense_cache()
352
394
  };
353
395
  for (const query of pending_queries) {
354
- result.pending_cache.set(query, signal_promise());
396
+ result.ssr_signals.set(query, signal_promise());
355
397
  }
356
398
  for (const [name, artifact] of Object.entries(artifacts)) {
357
399
  result.artifact_cache.set(name, artifact);
@@ -359,6 +401,9 @@ function router_cache({
359
401
  for (const [name, component] of Object.entries(components)) {
360
402
  result.component_cache.set(name, component);
361
403
  }
404
+ for (const [name, variables] of Object.entries(initialVariables)) {
405
+ result.last_variables.set(name, variables);
406
+ }
362
407
  return result;
363
408
  }
364
409
  function signal_promise() {
@@ -0,0 +1 @@
1
+ export { renderToStream } from 'react-streaming-compat/server';
@@ -18,10 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var server_exports = {};
20
20
  __export(server_exports, {
21
- renderToStream: () => import_renderToStream.renderToStream
21
+ renderToStream: () => import_server.renderToStream
22
22
  });
23
23
  module.exports = __toCommonJS(server_exports);
24
- var import_renderToStream = require("./renderToStream");
24
+ var import_server = require("react-streaming-compat/server");
25
25
  // Annotate the CommonJS export names for ESM import in node:
26
26
  0 && (module.exports = {
27
27
  renderToStream
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,4 @@
1
+ import { renderToStream } from "react-streaming-compat/server";
2
+ export {
3
+ renderToStream
4
+ };
@@ -0,0 +1 @@
1
+ {"type":"module"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini-react",
3
- "version": "1.2.27",
3
+ "version": "1.2.29",
4
4
  "description": "The React plugin for houdini",
5
5
  "keywords": [
6
6
  "typescript",
@@ -21,14 +21,14 @@
21
21
  "@types/cookies": "^0.7.7",
22
22
  "@types/estraverse": "^5.1.2",
23
23
  "@types/express": "^4.17.17",
24
- "@types/react-dom": "^18.0.11",
24
+ "@types/react": "^18.0.33",
25
+ "@types/react-dom": "^18.0.10",
25
26
  "next": "^13.0.1",
26
27
  "scripts": "^1.0.0"
27
28
  },
28
29
  "dependencies": {
29
30
  "@babel/parser": "^7.19.3",
30
31
  "@babel/types": "^7.21.4",
31
- "@types/react": "^18.0.28",
32
32
  "@whatwg-node/server": "^0.9.14",
33
33
  "cookie-parser": "^1.4.6",
34
34
  "cookie-session": "^2.0.0",
@@ -37,12 +37,13 @@
37
37
  "express": "^4.18.2",
38
38
  "graphql": "^15.8.0",
39
39
  "graphql-yoga": "^4.0.4",
40
- "react": "^18.2.0",
41
- "react-dom": "^18.2.0",
40
+ "react": "18.3.0-canary-09fbee89d-20231013",
41
+ "react-dom": "18.3.0-canary-09fbee89d-20231013",
42
+ "react-streaming-compat": "^0.3.18",
42
43
  "recast": "^0.23.1",
43
44
  "rollup": "^3.7.4",
44
45
  "use-deep-compare-effect": "^1.8.1",
45
- "houdini": "^1.2.27"
46
+ "houdini": "^1.2.29"
46
47
  },
47
48
  "files": [
48
49
  "build"
@@ -53,10 +54,19 @@
53
54
  "types": "./build/plugin/index.d.ts",
54
55
  "import": "./build/plugin-esm/index.js",
55
56
  "require": "./build/plugin-cjs/index.js"
57
+ },
58
+ "./server": {
59
+ "types": "./build/server/index.d.ts",
60
+ "import": "./build/server-esm/index.js",
61
+ "require": "./build/server-cjs/index.js"
56
62
  }
57
63
  },
58
64
  "typesVersions": {
59
- "*": {}
65
+ "*": {
66
+ "server": [
67
+ "build/server/index.d.ts"
68
+ ]
69
+ }
60
70
  },
61
71
  "main": "./build/plugin-cjs/index.js",
62
72
  "types": "./build/plugin/index.d.ts",
@@ -1,17 +0,0 @@
1
- /**
2
- This directory is largely copied from https://github.com/brillout/react-streaming and adapted to fit the needs of this project. It is subject to the MIT license, found [here](https://github.com/brillout/react-streaming/blob/main/LICENSE.md). Duplicated below for reference:
3
-
4
- MIT License
5
-
6
- Copyright (c) 2022-present Romuald Brillout
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
-
12
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
- */
14
- import { renderToStream } from './renderToStream';
15
- import type { InjectToStream } from './renderToStream/createBuffer';
16
- export { renderToStream };
17
- export type { InjectToStream };
@@ -1,17 +0,0 @@
1
- export { createBuffer };
2
- export type { InjectToStream };
3
- export type { StreamOperations };
4
- type InjectToStream = (chunk: unknown, options?: {
5
- flush?: boolean;
6
- }) => void;
7
- type StreamOperations = {
8
- operations: null | {
9
- writeChunk: (chunk: unknown) => void;
10
- flush: null | (() => void);
11
- };
12
- };
13
- declare function createBuffer(streamOperations: StreamOperations): {
14
- injectToStream: InjectToStream;
15
- onBeforeWrite: (chunk: unknown) => void;
16
- onBeforeEnd: () => void;
17
- };
@@ -1,12 +0,0 @@
1
- /// <reference types="node" />
2
- import type { Writable as StreamNodeWritable } from 'stream';
3
- export { createPipeWrapper };
4
- export type { Pipe };
5
- type Pipe = (writable: StreamNodeWritable) => void;
6
- declare function createPipeWrapper(pipeFromReact: Pipe, { onReactBug }: {
7
- onReactBug: (err: unknown) => void;
8
- }): Promise<{
9
- pipeForUser: Pipe;
10
- streamEnd: Promise<void>;
11
- injectToStream: import("./createBuffer").InjectToStream;
12
- }>;
@@ -1,6 +0,0 @@
1
- export { createReadableWrapper };
2
- declare function createReadableWrapper(readableFromReact: ReadableStream): {
3
- readableForUser: ReadableStream<any>;
4
- streamEnd: Promise<void>;
5
- injectToStream: import("./createBuffer").InjectToStream;
6
- };
@@ -1,10 +0,0 @@
1
- /// <reference types="node" />
2
- import type { Readable as StreamNodeReadable, Writable as StreamNodeWritable } from 'stream';
3
- export { loadNodeStreamModule };
4
- export { nodeStreamModuleIsAvailable };
5
- type StreamModule = {
6
- Readable: typeof StreamNodeReadable;
7
- Writable: typeof StreamNodeWritable;
8
- };
9
- declare function loadNodeStreamModule(): Promise<StreamModule>;
10
- declare function nodeStreamModuleIsAvailable(): Promise<boolean>;
@@ -1,9 +0,0 @@
1
- export { resolveSeoStrategy };
2
- export type { SeoStrategy };
3
- type SeoStrategy = 'conservative' | 'google-speed';
4
- declare function resolveSeoStrategy(options?: {
5
- seoStrategy?: SeoStrategy;
6
- userAgent?: string;
7
- }): {
8
- disableStream: boolean;
9
- };
@@ -1,28 +0,0 @@
1
- import React from 'react';
2
- import type { renderToPipeableStream as RenderToPipeableStream, renderToReadableStream as RenderToReadableStream } from 'react-dom/server';
3
- import { Pipe } from './renderToStream/createPipeWrapper';
4
- import { SeoStrategy } from './renderToStream/resolveSeoStrategy';
5
- export { renderToStream };
6
- export { disable };
7
- type Options = {
8
- webStream?: boolean;
9
- disable?: boolean;
10
- seoStrategy?: SeoStrategy;
11
- userAgent?: string;
12
- onBoundaryError?: (err: unknown) => void;
13
- renderToReadableStream?: typeof RenderToReadableStream;
14
- renderToPipeableStream?: typeof RenderToPipeableStream;
15
- };
16
- type Result = ({
17
- pipe: Pipe;
18
- readable: null;
19
- } | {
20
- pipe: null;
21
- readable: ReadableStream;
22
- }) & {
23
- streamEnd: Promise<boolean>;
24
- disabled: boolean;
25
- injectToStream: (chunk: unknown) => void;
26
- };
27
- declare function disable(): void;
28
- declare function renderToStream(element: React.ReactNode, options?: Options): Promise<Result>;
@@ -1,8 +0,0 @@
1
- export type { InitData };
2
- export { initDataHtmlClass };
3
- type InitData = {
4
- value: unknown;
5
- key: string;
6
- elementId: string;
7
- };
8
- declare const initDataHtmlClass = "react-streaming_initData";
@@ -1,4 +0,0 @@
1
- export { stringifyKey };
2
- export { assertKey };
3
- declare function stringifyKey(key: unknown): string;
4
- declare function assertKey(keyValue: unknown): void;
@@ -1,3 +0,0 @@
1
- export * from '../utils/assert';
2
- export * from '../utils/getGlobalVariable';
3
- export * from '../utils/isPromise';
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- export { useStream };
3
- export { StreamProvider };
4
- export type { StreamUtils };
5
- type StreamUtils = {
6
- injectToStream: (htmlChunk: string) => void;
7
- };
8
- declare const StreamProvider: React.Provider<StreamUtils | null>;
9
- declare function useStream(): StreamUtils | null;
@@ -1,15 +0,0 @@
1
- export { assert };
2
- export { assertUsage };
3
- export { assertWarning };
4
- export { assertInfo };
5
- export { getProjectError };
6
- declare function assert(condition: unknown, debugInfo?: unknown): asserts condition;
7
- declare function assertUsage(condition: unknown, errorMessage: string): asserts condition;
8
- declare function getProjectError(errorMessage: string): Error;
9
- declare function assertWarning(condition: unknown, errorMessage: string, { onlyOnce, showStackTrace }: {
10
- onlyOnce: boolean | string;
11
- showStackTrace?: true;
12
- }): void;
13
- declare function assertInfo(condition: unknown, errorMessage: string, { onlyOnce }: {
14
- onlyOnce: boolean;
15
- }): void;
@@ -1,2 +0,0 @@
1
- export { createErrorWithCleanStackTrace };
2
- declare function createErrorWithCleanStackTrace(errorMessage: string, numberOfStackTraceLinesToRemove: number): Error;
@@ -1,14 +0,0 @@
1
- export { createDebugger };
2
- export { isDebugEnabled };
3
- export type { Debug };
4
- type Debug = ReturnType<typeof createDebugger>;
5
- type Options = {
6
- serialization?: {
7
- emptyArray?: string;
8
- };
9
- };
10
- declare function createDebugger(namespace: string, optionsGlobal?: Options): ((msg: string, info?: unknown) => void) & {
11
- options: (options: Options) => (msg: string, info?: unknown) => void;
12
- isEnabled: boolean;
13
- };
14
- declare function isDebugEnabled(namespace: string): boolean;
@@ -1,4 +0,0 @@
1
- export declare function getGlobalVariable<T>(key: string, defaultValue: T): T;
2
- declare global {
3
- var __react_streaming: Record<string, any>;
4
- }
@@ -1,2 +0,0 @@
1
- export { isBrowser };
2
- declare function isBrowser(): boolean;
@@ -1,2 +0,0 @@
1
- export { isCallable };
2
- declare function isCallable<T extends (...args: unknown[]) => unknown>(thing: T | unknown): thing is T;
@@ -1,2 +0,0 @@
1
- export { isClientSide };
2
- declare function isClientSide(): boolean;
@@ -1 +0,0 @@
1
- export declare function isPromise(val: unknown): val is Promise<unknown>;
@@ -1,2 +0,0 @@
1
- export { isServerSide };
2
- declare function isServerSide(): boolean;
@@ -1,2 +0,0 @@
1
- export { objectAssign };
2
- declare function objectAssign<Obj extends object, ObjAddendum>(obj: Obj, objAddendum: ObjAddendum): asserts obj is Obj & ObjAddendum;