Skip to content

Commit 198a393

Browse files
committed
Handle malformed URL params
1 parent 5101601 commit 198a393

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/App.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,24 @@ function App() {
2323
}, [themeOptions]);
2424

2525
useEffect(() => {
26-
const searchParams = new URLSearchParams(window.location.search);
27-
const sharedTheme = searchParams.get("theme");
28-
if (sharedTheme) {
29-
// Toast doesn't work without timeout
30-
setTimeout(() => toast.success("Loaded theme from URL"), 1000);
31-
setThemeOptions(JSON.parse(decodeURIComponent(sharedTheme)));
32-
history.replaceState(null, "", location.pathname);
26+
try {
27+
const searchParams = new URLSearchParams(window.location.search);
28+
const sharedTheme = searchParams.get("theme");
29+
if (sharedTheme) {
30+
const themeObjectFromUrl = JSON.parse(decodeURIComponent(sharedTheme));
31+
if (typeof themeObjectFromUrl !== "object") {
32+
setTimeout(() => toast.error("Malformed theme in URL"), 1000);
33+
return;
34+
}
35+
// Toast doesn't work without timeout
36+
console.log(typeof themeObjectFromUrl);
37+
setTimeout(() => toast.success("Loaded theme from URL"), 1000);
38+
setThemeOptions(JSON.parse(decodeURIComponent(sharedTheme)));
39+
history.replaceState(null, "", location.pathname);
40+
}
41+
} catch (e) {
42+
console.error(e);
43+
setTimeout(() => toast.error("Malformed theme in URL"), 1000);
3344
}
3445
}, []);
3546

src/components/NumberSpecifier/NumberSpecifier.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const NumberSpecifier = ({ title, onReset, isDefault, onChange, unit, ...
3939
background: "transparent",
4040
color: "text.primary",
4141
"::-webkit-inner-spin-button": {
42-
"-webkit-appearance": "none",
42+
appearance: "none",
4343
margin: 0,
4444
},
4545
}}

0 commit comments

Comments
 (0)