Skip to content

Commit c2f083c

Browse files
committed
make Atom.searchParam work when window is undefined
1 parent 2fe58d7 commit c2f083c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

.changeset/five-glasses-mate.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@effect-atom/atom": patch
3+
"@effect-atom/atom-livestore": patch
4+
"@effect-atom/atom-react": patch
5+
"@effect-atom/atom-vue": patch
6+
---
7+
8+
make Atom.searchParam work when window is undefined

packages/atom/src/Atom.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,9 @@ export const searchParam = <A = never, I extends string = never>(name: string, o
18501850
const encode = options?.schema && Schema.encodeEither(options.schema)
18511851
return writable(
18521852
(get) => {
1853+
if (typeof window === "undefined") {
1854+
return decode ? Option.none() : ""
1855+
}
18531856
const handleUpdate = () => {
18541857
if (searchParamState.updating) return
18551858
const searchParams = new URLSearchParams(window.location.search)
@@ -1870,6 +1873,11 @@ export const searchParam = <A = never, I extends string = never>(name: string, o
18701873
return decode ? Either.getRight(decode(value as I)) : value as any
18711874
},
18721875
(ctx, value: any) => {
1876+
if (typeof window === "undefined") {
1877+
ctx.setSelf(value)
1878+
return
1879+
}
1880+
18731881
if (encode) {
18741882
const encoded = Option.flatMap(value, (v) => Either.getRight(encode(v as A)))
18751883
searchParamState.updates.set(name, Option.getOrElse(encoded, () => ""))

0 commit comments

Comments
 (0)