Skip to content

Commit

Permalink
clear pending cache
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed Oct 16, 2023
1 parent 3b676a0 commit 07a4efd
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions packages/houdini-react/src/runtime/routing/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ function usePageData({
const artifactName = "${artifact.name}"
const value = ${JSON.stringify(observer.state.data)}
// if the data is pending, we need to resolve it
if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
// before we resolve the pending signals,
// fill the data cache with values we got on the server
const new_store = window.__houdini__client__.observe({
artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
cache: window.__houdini__cache__,
initialValue: value,
})
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
}
// if there are no data caches available we need to populate the pending one instead
if (!window.__houdini__nav_caches__) {
if (!window.__houdini__pending_data__) {
Expand All @@ -218,29 +232,18 @@ function usePageData({
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
}
// if the data is pending, we need to resolve it
if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
// before we resolve the pending signals,
// fill the data cache with values we got on the server
const new_store = window.__houdini__client__.observe({
artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
cache: window.__houdini__cache__,
initialValue: value,
})
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
if (window.__houdini__nav_caches__?.pending_cache.has(artifactName)) {
if (window.__houdini__nav_caches__?.pending_cache.has(artifactName)) {
if (window.__houdini__nav_caches__.data_cache.has(articleName)) {
// we're pushing this store onto the client, it should be initialized
new_store.send({
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
setup: true,
variables: ${JSON.stringify(variables)}
})
// notify anyone waiting on the pending cache
window.__houdini__nav_caches__.pending_cache.get(artifactName).resolve()
window.__houdini__nav_caches__.pending_cache.delete(artifactName)
}
// notify anyone waiting on the pending cache
window.__houdini__nav_caches__.pending_cache.get(artifactName).resolve()
window.__houdini__nav_caches__.pending_cache.delete(artifactName)
}
}
</script>
Expand Down

0 comments on commit 07a4efd

Please sign in to comment.