Skip to content

Commit

Permalink
fix(playground): run code even if it doesn't change (#12224)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA authored Dec 3, 2024
1 parent cc34e67 commit a52bb26
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion client/src/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default function Playground() {
const [initialContent, setInitialContent] = useState<EditorContent | null>(
null
);
const [flipFlop, setFlipFlop] = useState(0);
let { data: initialCode } = useSWRImmutable<EditorContent>(
!stateParam && !shared && gistId
? `/api/v1/play/${encodeURIComponent(gistId)}`
Expand Down Expand Up @@ -134,10 +135,14 @@ export default function Playground() {
);
setVConsole([]);
url.searchParams.set("state", state);
// ensure iframe reloads even if code doesn't change
url.searchParams.set("f", flipFlop.toString());
url.pathname = `${codeSrc || code.src || ""}/runner.html`;
setIframeSrc(url.href);
// using an updater function causes the second "run" to not reload properly:
setFlipFlop((flipFlop + 1) % 2);
},
[codeSrc, setVConsole, setIframeSrc]
[codeSrc, setVConsole, setIframeSrc, flipFlop, setFlipFlop]
);

useEffect(() => {
Expand Down

0 comments on commit a52bb26

Please sign in to comment.