Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion apps/website/src/app/playground/ClientPlayground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { useAvailableHeight } from "../../utils/useAvailableHeight";
import { ShareButton } from "./ShareButton";

function updateUrl(params: Partial<PlaygroundParams>) {
function applyUrlUpdate(params: Partial<PlaygroundParams>) {
const url = new URL(window.location.href);
const newUrl = getPlaygroundUrl({ ...parsePlaygroundUrl(url), ...params });

Expand All @@ -31,6 +31,25 @@ function updateUrl(params: Partial<PlaygroundParams>) {
window.history.replaceState(undefined, "", newUrl.toString());
}

// Firefox and Safari rate-limit History API calls and crash the page on fast
// typing (https://github.com/quantified-uncertainty/squiggle/issues/3510), so
// we debounce URL updates while accumulating the pending params.
let pendingParams: Partial<PlaygroundParams> = {};
let updateTimeout: ReturnType<typeof setTimeout> | undefined;

function updateUrl(params: Partial<PlaygroundParams>) {
pendingParams = { ...pendingParams, ...params };
if (updateTimeout !== undefined) {
clearTimeout(updateTimeout);
}
updateTimeout = setTimeout(() => {
updateTimeout = undefined;
const paramsToApply = pendingParams;
pendingParams = {};
applyUrlUpdate(paramsToApply);
}, 300);
}

export const ClientPlayground: FC = () => {
const params = useSearchParams();

Expand Down
Loading