Skip to content

Commit 1a41d9e

Browse files
committed
fix(catalog): only rewrite the url when a value actually changed
1 parent 60526b3 commit 1a41d9e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

docs/snippets/variables-explorer.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,8 +1575,13 @@ export const VariablesExplorer = ({
15751575
const url = new URL(window.location.href);
15761576
if (Object.keys(changed).length === 0) url.searchParams.delete(urlKey);
15771577
else url.searchParams.set(urlKey, encodeURIComponent(JSON.stringify(changed)));
1578-
window.history.replaceState(null, "", url.toString());
1579-
}, [values]);
1578+
1579+
// `defaults` is rebuilt every render, so this effect runs every render too.
1580+
// Comparing first keeps it to an actual change rather than touching the
1581+
// history API on each one.
1582+
const next = url.toString();
1583+
if (next !== window.location.href) window.history.replaceState(null, "", next);
1584+
}, [values, defaults, urlKey]);
15801585
// What the SVG import last had to say, per variable. Held here because
15811586
// `control` is a function rather than a component and cannot hold it itself.
15821587
const [notes, setNotes] = useState({});

0 commit comments

Comments
 (0)