From 519c9f68c7c216d898dcf4979e363009eec0bbe9 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Mon, 9 Mar 2026 18:48:13 -0400 Subject: [PATCH 1/2] fix(sandbox): getInitialCode should not use URL hash without full prefix I'm hunting down https://github.com/typescript-eslint/typescript-eslint/issues/8780 (see more context in the issue discussion), and I finally got to `getInitialCode`. It turns out that the hash may start with `#code` but then not start with `#code/`, causing malformed initial code to be parsed. --- packages/sandbox/src/getInitialCode.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sandbox/src/getInitialCode.ts b/packages/sandbox/src/getInitialCode.ts index 3e712c091c4e..9190fdea2a61 100644 --- a/packages/sandbox/src/getInitialCode.ts +++ b/packages/sandbox/src/getInitialCode.ts @@ -7,13 +7,13 @@ import lzstring from "./vendor/lzstring.min" */ export const getInitialCode = (fallback: string, location: Location) => { // Old school support - if (location.hash.startsWith("#src")) { + if (location.hash.startsWith("#src=")) { const code = location.hash.replace("#src=", "").trim() return decodeURIComponent(code) } // New school support - if (location.hash.startsWith("#code")) { + if (location.hash.startsWith("#code/")) { const code = location.hash.replace("#code/", "").trim() let userCode = lzstring.decompressFromEncodedURIComponent(code) // Fallback incase there is an extra level of decoding: From f0001990b8a4437a1a93e8c82f13e38faa175f51 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Mon, 9 Mar 2026 18:54:19 -0400 Subject: [PATCH 2/2] Add changeset --- .changeset/small-animals-switch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/small-animals-switch.md diff --git a/.changeset/small-animals-switch.md b/.changeset/small-animals-switch.md new file mode 100644 index 000000000000..9e3c8420a2ad --- /dev/null +++ b/.changeset/small-animals-switch.md @@ -0,0 +1,5 @@ +--- +"@typescript/sandbox": patch +--- + +getInitialCode should not use URL hash without full prefix