houdini-react 2.0.0-next.45 → 2.0.0-next.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini-react",
3
- "version": "2.0.0-next.45",
3
+ "version": "2.0.0-next.46",
4
4
  "description": "The React plugin for houdini",
5
5
  "keywords": [
6
6
  "typescript",
@@ -81,13 +81,13 @@
81
81
  }
82
82
  },
83
83
  "optionalDependencies": {
84
- "houdini-react-darwin-x64": "2.0.0-next.45",
85
- "houdini-react-darwin-arm64": "2.0.0-next.45",
86
- "houdini-react-linux-x64": "2.0.0-next.45",
87
- "houdini-react-linux-arm64": "2.0.0-next.45",
88
- "houdini-react-win32-x64": "2.0.0-next.45",
89
- "houdini-react-win32-arm64": "2.0.0-next.45",
90
- "houdini-react-wasm": "2.0.0-next.45"
84
+ "houdini-react-darwin-x64": "2.0.0-next.46",
85
+ "houdini-react-darwin-arm64": "2.0.0-next.46",
86
+ "houdini-react-linux-x64": "2.0.0-next.46",
87
+ "houdini-react-linux-arm64": "2.0.0-next.46",
88
+ "houdini-react-win32-x64": "2.0.0-next.46",
89
+ "houdini-react-win32-arm64": "2.0.0-next.46",
90
+ "houdini-react-wasm": "2.0.0-next.46"
91
91
  },
92
92
  "scripts": {
93
93
  "compile": "scripts build-go",
package/postInstall.js CHANGED
@@ -5,7 +5,7 @@ const https = require('https')
5
5
  const child_process = require('child_process')
6
6
 
7
7
  // Adjust the version you want to install. You can also make this dynamic.
8
- const BINARY_DISTRIBUTION_VERSION = '2.0.0-next.45'
8
+ const BINARY_DISTRIBUTION_VERSION = '2.0.0-next.46'
9
9
 
10
10
  // Windows binaries end with .exe so we need to special case them.
11
11
  const binaryName = process.platform === 'win32' ? 'houdini-react.exe' : 'houdini-react'
@@ -31,7 +31,10 @@ export function useFragmentHandle<
31
31
  document: { artifact: FragmentArtifact; refetchArtifact?: QueryArtifact }
32
32
  ): any {
33
33
  const fragmentData = useFragment<_Data, _ReferenceType, _Input>(reference, document)
34
- const { variables } = fragmentReference<_Data, _Input, _ReferenceType>(reference, document)
34
+ const { variables, loading } = fragmentReference<_Data, _Input, _ReferenceType>(
35
+ reference,
36
+ document
37
+ )
35
38
 
36
39
  const client = useClient()
37
40
  const [session] = useSession()
@@ -172,6 +175,8 @@ export function useFragmentHandle<
172
175
  getState: () => displayData as _Data | null,
173
176
  getVariables: () =>
174
177
  (paginationObserver.state.variables ?? variables) as NonNullable<_Input>,
178
+ // no-op pagination while the parent is still in its @loading state (issue #1408)
179
+ getLoading: () => loading,
175
180
  fetch: fetchFn,
176
181
  fetchUpdate,
177
182
  getSession: async () => session,
@@ -196,6 +201,8 @@ export function useFragmentHandle<
196
201
  getState: () => displayData as _Data | null,
197
202
  getVariables: () =>
198
203
  (paginationObserver.state.variables ?? variables) as NonNullable<_Input>,
204
+ // no-op pagination while the parent is still in its @loading state (issue #1408)
205
+ getLoading: () => loading,
199
206
  storeName: refetchArtifact.name,
200
207
  fetch: fetchFn,
201
208
  fetchUpdate: async (args: any, updates = ['append']) =>
@@ -210,7 +217,15 @@ export function useFragmentHandle<
210
217
  }
211
218
 
212
219
  return null
213
- }, [refetchArtifact, paginationObserver, displayData, session, forwardPending, backwardPending])
220
+ }, [
221
+ refetchArtifact,
222
+ paginationObserver,
223
+ displayData,
224
+ session,
225
+ forwardPending,
226
+ backwardPending,
227
+ loading,
228
+ ])
214
229
 
215
230
  // the fragment's current argument values: the initial args overlaid with everything that
216
231
  // has been passed to refetch() so far. we track these explicitly rather than reading them
@@ -20,6 +20,7 @@ declare global {
20
20
  __houdini__pending_artifacts__?: Record<string, QueryArtifact>
21
21
  __houdini__pending_data__?: Record<string, any>
22
22
  __houdini__pending_variables__?: Record<string, GraphQLVariables>
23
+ __houdini__pending_cache__?: any[]
23
24
  __houdini__nav_caches__?: RouterCache
24
25
  }
25
26
  }
@@ -57,6 +58,22 @@ export function hydrate_page(
57
58
  window.__houdini__hydration__layer__
58
59
  )
59
60
 
61
+ // apply any cache snapshots that streamed in before this module ran. an @loading query
62
+ // resolves while the document is still open, so its resolution script runs before this
63
+ // (deferred) module and couldn't hydrate the cache directly — it queued its snapshot here
64
+ // instead. drain the queue now that the cache exists so the observers below read the
65
+ // resolved data rather than the loading-state placeholder. each snapshot goes into its own
66
+ // layer (hydrate() replaces a layer's contents wholesale, so reusing one would keep only
67
+ // the last snapshot) and is then merged down so we end up with a single hydration layer.
68
+ const storage = window.__houdini__cache__?._internal_unstable.storage
69
+ for (const snapshot of window.__houdini__pending_cache__ ?? []) {
70
+ const layer = window.__houdini__cache__?.hydrate(snapshot)
71
+ if (layer && storage) {
72
+ storage.resolveLayer(layer.id)
73
+ }
74
+ }
75
+ window.__houdini__pending_cache__ = []
76
+
60
77
  // prime the data/artifact caches from anything the server streamed
61
78
  const initialData: Record<string, any> = {}
62
79
  const initialArtifacts: Record<string, QueryArtifact> = {}
@@ -314,7 +314,23 @@ function usePageData({
314
314
  injectToStream?.(`
315
315
  <script>
316
316
  {
317
- window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer__)
317
+ // the resolved cache snapshot for this streamed query. when the bootstrap
318
+ // module has already run (data arrived after hydration) we hydrate the live
319
+ // cache directly; otherwise the module is still deferred (an @loading query
320
+ // streams its data while the document is open) so we queue the snapshot for
321
+ // hydrate_page to apply once it creates the cache. without this the snapshot
322
+ // would be dropped and the query would hydrate with null data.
323
+ const __houdini__snapshot__ = ${cache.serialize()}
324
+ if (window.__houdini__cache__) {
325
+ // hydrate into a fresh layer and merge it down, rather than clobbering the
326
+ // shared hydration layer (which would drop everything hydrated before it)
327
+ const __houdini__layer__ = window.__houdini__cache__.hydrate(__houdini__snapshot__)
328
+ if (__houdini__layer__) {
329
+ window.__houdini__cache__._internal_unstable.storage.resolveLayer(__houdini__layer__.id)
330
+ }
331
+ } else {
332
+ (window.__houdini__pending_cache__ = window.__houdini__pending_cache__ || []).push(__houdini__snapshot__)
333
+ }
318
334
 
319
335
  const artifactName = "${artifact.name}"
320
336
  const value = ${JSON.stringify(