generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: New API for seach param cache
- Loading branch information
Showing
6 changed files
with
152 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Search params cache already populated | ||
|
||
This error occurs when a [search params cache](https://github.com/47ng/next-usequerystate#accessing-searchparams-in-server-components) | ||
is being fed searchParams more than once. | ||
|
||
Internally, the cache object will be frozen for the duration of the page render | ||
after having been populated. This is to prevent search params from being modified | ||
while the page is being rendered. | ||
|
||
## Solutions | ||
|
||
Look into the stack trace where the error occurred and remove the second call to | ||
`parse` that threw the error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
import { expectError, expectNotAssignable, expectType } from 'tsd' | ||
import { | ||
createSearchParamCache, | ||
createSearchParamsCache, | ||
parseAsBoolean, | ||
parseAsInteger, | ||
parseAsString | ||
} from '../../dist/parsers' | ||
|
||
{ | ||
const { getSearchParam } = createSearchParamCache({ | ||
const cache = createSearchParamsCache({ | ||
foo: parseAsString, | ||
bar: parseAsInteger, | ||
egg: parseAsBoolean.withDefault(false) | ||
}) | ||
// Values are type-safe | ||
expectType<string | null>(getSearchParam('foo')) | ||
expectType<number | null>(getSearchParam('bar')) | ||
expectType<string | null>(cache.get('foo')) | ||
expectType<number | null>(cache.get('bar')) | ||
// Default values are taken into account | ||
expectType<boolean>(getSearchParam('egg')) | ||
expectNotAssignable<null>(getSearchParam('egg')) | ||
expectType<boolean>(cache.get('egg')) | ||
expectNotAssignable<null>(cache.get('egg')) | ||
// Keys are type safe | ||
expectError(() => { | ||
getSearchParam('spam') | ||
cache.get('spam') | ||
}) | ||
expectType< | ||
Readonly<{ foo: string | null; bar: number | null; egg: boolean }> | ||
>(cache.all()) | ||
} |