Skip to content

Commit

Permalink
fix: WHS stabilisation (#457)
Browse files Browse the repository at this point in the history
* fix: WHS has been stabilised

* chore: Add test suite for 14.0.3 with WHS
  • Loading branch information
franky47 authored Jan 15, 2024
1 parent ef75b2c commit 3812dcc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ jobs:
# 14.0.2 is not compatible due to a prefetch issue
- latest
include:
# 14.0.3 requires the WHS flag
- next-version: '14.0.3'
window-history-support: true
# Current latest is 14.0.4
- next-version: latest
window-history-support: true
- next-version: latest
Expand Down
5 changes: 4 additions & 1 deletion packages/e2e/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ function supportsWHS() {
const pkgPath = new URL('./package.json', import.meta.url)
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
const nextVersion: string = pkg.dependencies.next
return semver.gte(nextVersion, '14.0.3-canary.6')
return (
semver.gte(nextVersion, '14.0.3-canary.6') &&
semver.lt(nextVersion, '14.0.5-canary.54')
)
}
16 changes: 7 additions & 9 deletions packages/nuqs/src/useQueryState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,13 @@ export function useQueryState<T = string>(
initialSearchParams?.get(key) ?? null
)

if (process.env.__NEXT_WINDOW_HISTORY_SUPPORT) {
React.useEffect(() => {
const value = initialSearchParams.get(key) ?? null
const state = value === null ? null : safeParse(parse, value, key)
debug('[nuqs `%s`] syncFromUseSearchParams %O', key, state)
stateRef.current = state
setInternalState(state)
}, [initialSearchParams?.get(key), key])
}
React.useEffect(() => {
const value = initialSearchParams.get(key) ?? null
const state = value === null ? null : safeParse(parse, value, key)
debug('[nuqs `%s`] syncFromUseSearchParams %O', key, state)
stateRef.current = state
setInternalState(state)
}, [initialSearchParams?.get(key), key])

// Sync all hooks together & with external URL changes
React.useInsertionEffect(() => {
Expand Down

0 comments on commit 3812dcc

Please sign in to comment.