Skip to content

Commit

Permalink
chore: Remove deprecated APIs
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the following deprecated APIs have been removed:
- `queryTypes` bag of parsers -> use individual `parseAsXYZ` parsers
  for better tree-shakeability.
- `subscribeToQueryUpdates` helper -> since Next.js 14.0.5,
  `useSearchParams` is reactive to shallow search params updates
  in the app router. See #425.
- Internal types and aliases
  • Loading branch information
franky47 committed Jan 17, 2024
1 parent 455415f commit 30f3e0a
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 495 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
'use client'

import { useSearchParams } from 'next/navigation'
import { subscribeToQueryUpdates } from 'nuqs'
import React from 'react'

export const QuerySpy: React.FC = () => {
const initialSearchParams = useSearchParams()
const [search, setSearch] = React.useState<URLSearchParams>(() => {
if (typeof location !== 'object') {
// SSR
const out = new URLSearchParams()
if (!initialSearchParams) {
return out
}
for (const [key, value] of initialSearchParams) {
out.set(key, value)
}
return out
} else {
return new URLSearchParams(location.search)
}
})

React.useLayoutEffect(
() => subscribeToQueryUpdates(({ search }) => setSearch(search)),
[]
)
const qs = search.toString()
const qs = initialSearchParams?.toString()

return (
<pre
Expand Down

This file was deleted.

16 changes: 11 additions & 5 deletions packages/e2e/src/pages/pages/useQueryState/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { GetServerSideProps } from 'next'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { parseAsString, queryTypes, useQueryState } from 'nuqs'
import {
parseAsBoolean,
parseAsFloat,
parseAsInteger,
parseAsString,
useQueryState
} from 'nuqs'
import { HydrationMarker } from '../../../components/hydration-marker'

export const getServerSideProps = (async ctx => {
Expand All @@ -18,12 +24,12 @@ export const getServerSideProps = (async ctx => {

const IntegrationPage = () => {
const [string, setString] = useQueryState('string')
const [int, setInt] = useQueryState('int', queryTypes.integer)
const [float, setFloat] = useQueryState('float', queryTypes.float)
const [bool, setBool] = useQueryState('bool', queryTypes.boolean)
const [int, setInt] = useQueryState('int', parseAsInteger)
const [float, setFloat] = useQueryState('float', parseAsFloat)
const [bool, setBool] = useQueryState('bool', parseAsBoolean)
const [text, setText] = useQueryState(
'text',
queryTypes.string.withDefault('Hello, world!')
parseAsString.withDefault('Hello, world!')
)
const pathname = usePathname()
return (
Expand Down
16 changes: 11 additions & 5 deletions packages/e2e/src/pages/pages/useQueryStates/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import Link from 'next/link'
import { queryTypes, useQueryStates } from 'nuqs'
import {
parseAsBoolean,
parseAsFloat,
parseAsInteger,
parseAsString,
useQueryStates
} from 'nuqs'
import { HydrationMarker } from '../../../components/hydration-marker'

const IntegrationPage = () => {
const [state, setState] = useQueryStates({
string: queryTypes.string,
int: queryTypes.integer,
float: queryTypes.float,
bool: queryTypes.boolean
string: parseAsString,
int: parseAsInteger,
float: parseAsFloat,
bool: parseAsBoolean
})
return (
<>
Expand Down
70 changes: 0 additions & 70 deletions packages/nuqs/src/deprecated.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/nuqs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use client'

export type { HistoryOptions, Options } from './defs'
export * from './deprecated'
export * from './parsers'
export { subscribeToQueryUpdates } from './sync'
export type { QueryUpdateNotificationArgs, QueryUpdateSource } from './sync'
export * from './useQueryState'
export * from './useQueryStates'
15 changes: 0 additions & 15 deletions packages/nuqs/src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ declare global {
}
}

/**
* @deprecated Since Next.js introduced shallow routing in 14.0.3, this
* method is no longer needed as you can use `useSearchParams`, which will
* react to changes in the URL when the `windowHistorySupport` experimental flag
* is set.
* This method will be removed in `[email protected]`, when Next.js
* decides to land the `windowHistorySupport` flag in GA.
*/
export function subscribeToQueryUpdates(
callback: (args: QueryUpdateNotificationArgs) => void
) {
emitter.on(NOTIFY_EVENT_KEY, callback)
return () => emitter.off(NOTIFY_EVENT_KEY, callback)
}

if (typeof history === 'object') {
patchHistory()
}
Expand Down
Loading

0 comments on commit 30f3e0a

Please sign in to comment.