Skip to content

Commit

Permalink
updating the session refreshes queries
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed Mar 7, 2024
1 parent 28b3c29 commit 3d5e9b0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
12 changes: 9 additions & 3 deletions packages/houdini-react/src/runtime/hooks/useDocumentStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export function useDocumentStore<
...observeParams
}: UseDocumentStoreParams<_Artifact, _Data, _Input>): [
QueryResult<_Data, _Input>,
DocumentStore<_Data, _Input>,
(store: DocumentStore<_Data, _Input>) => void
DocumentStore<_Data, _Input>
] {
const client = useClient()
const isMountedRef = useIsMountedRef()
Expand All @@ -43,6 +42,13 @@ export function useDocumentStore<

const box = React.useRef(observer.state)

// if the observer changes, we need to track the new one
if (obs && obs !== observer) {
box.current = obs.state
setObserver(obs)
}

// the function that registers a new subscription for the observer
const subscribe: any = React.useCallback(
(fn: () => void) => {
return observer.subscribe((val) => {
Expand All @@ -62,5 +68,5 @@ export function useDocumentStore<
() => box.current
)

return [storeValue!, observer, setObserver]
return [storeValue!, observer]
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ export function useDocumentSubscription<
variables: _Input
disabled?: boolean
send?: Partial<SendParams>
}): [
QueryResult<_Data, _Input> & { parent?: string | null },
DocumentStore<_Data, _Input>,
(store: DocumentStore<_Data, _Input>) => void
] {
const [storeValue, observer, setObserver] = useDocumentStore<_Data, _Input>({
}): [QueryResult<_Data, _Input> & { parent?: string | null }, DocumentStore<_Data, _Input>] {
const [storeValue, observer] = useDocumentStore<_Data, _Input>({
artifact,
...observeParams,
})
Expand Down Expand Up @@ -58,6 +54,5 @@ export function useDocumentSubscription<
...storeValue,
},
observer,
setObserver,
]
}
2 changes: 1 addition & 1 deletion packages/houdini-react/src/runtime/routing/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export function RouterContextProvider({
ssr_signals,
last_variables,
session,
setSession: (newSession) => setSession((old) => ({ ...old, newSession })),
setSession: (newSession) => setSession((old) => ({ ...old, ...newSession })),
}}
>
{children}
Expand Down

0 comments on commit 3d5e9b0

Please sign in to comment.