Skip to content

Commit 47749ba

Browse files
committed
fix: Harden debug reading of localStorage
1 parent e29ab79 commit 47749ba

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/nuqs/src/debug.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
// todo: Remove check for `next-usequerystate` in v2
2-
const enabled =
3-
(typeof localStorage === 'object' &&
4-
(localStorage.getItem('debug')?.includes('next-usequerystate') ||
5-
localStorage.getItem('debug')?.includes('nuqs'))) ||
6-
false
2+
let enabled = false
3+
4+
try {
5+
enabled =
6+
(typeof localStorage === 'object' &&
7+
(localStorage.getItem('debug')?.includes('next-usequerystate') ||
8+
localStorage.getItem('debug')?.includes('nuqs'))) ||
9+
false
10+
} catch (error) {
11+
console.error(
12+
'[nuqs]: debug mode is disabled (localStorage unavailable).',
13+
error
14+
)
15+
}
716

817
export function debug(message: string, ...args: any[]) {
918
if (!enabled) {

0 commit comments

Comments
 (0)