From ca5cc21ffc4bad29692c973c3b28146008a6e51a Mon Sep 17 00:00:00 2001 From: jjspace <8007967+jjspace@users.noreply.github.com> Date: Thu, 14 Aug 2025 14:55:38 -0400 Subject: [PATCH 1/3] always switch to editor when it should --- packages/sandcastle/src/App.tsx | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/sandcastle/src/App.tsx b/packages/sandcastle/src/App.tsx index 9c0eb0cfd28f..ee148acdde4a 100644 --- a/packages/sandcastle/src/App.tsx +++ b/packages/sandcastle/src/App.tsx @@ -519,20 +519,10 @@ function App() { "", `${getBaseUrl()}?id=${item.id}`, ); - if ( - !searchParams.has("id") || - (searchParams.has("id") && searchParams.get("id") !== item.id) - ) { - // only push state if it's not the current url to prevent duplicated in history - window.history.pushState( - {}, - "", - `${getBaseUrl()}?id=${item.id}`, - ); - } - if (switchToCode) { - setLeftPanel("editor"); - } + } + + if (switchToCode) { + setLeftPanel("editor"); } }} /> From b81911a4cd921c47f908386c0f00938f59ee0e96 Mon Sep 17 00:00:00 2001 From: jjspace <8007967+jjspace@users.noreply.github.com> Date: Tue, 19 Aug 2025 11:15:35 -0400 Subject: [PATCH 2/3] don't rerun sandcastle when switching to code --- packages/sandcastle/src/App.tsx | 17 ++++++++++------- packages/sandcastle/src/Gallery.tsx | 5 ++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/sandcastle/src/App.tsx b/packages/sandcastle/src/App.tsx index ee148acdde4a..dab25a53185c 100644 --- a/packages/sandcastle/src/App.tsx +++ b/packages/sandcastle/src/App.tsx @@ -505,14 +505,11 @@ function App() { hidden={leftPanel !== "gallery"} galleryItems={galleryItems} loadDemo={(item, switchToCode) => { - // Load the gallery item every time it's clicked - loadGalleryItem(item.id); - const searchParams = new URLSearchParams(window.location.search); - if ( - !searchParams.has("id") || - (searchParams.has("id") && searchParams.get("id") !== item.id) - ) { + const isAlreadyActive = + searchParams.has("id") && searchParams.get("id") === item.id; + + if (!isAlreadyActive) { // only push state if it's not the current url to prevent duplicated in history window.history.pushState( {}, @@ -522,7 +519,13 @@ function App() { } if (switchToCode) { + if (!isAlreadyActive) { + loadGalleryItem(item.id); + } setLeftPanel("editor"); + } else { + // Load the gallery item every time it's clicked ro act as a "rerun" button + loadGalleryItem(item.id); } }} /> diff --git a/packages/sandcastle/src/Gallery.tsx b/packages/sandcastle/src/Gallery.tsx index ef0efd8b9441..647c2ad96e2c 100644 --- a/packages/sandcastle/src/Gallery.tsx +++ b/packages/sandcastle/src/Gallery.tsx @@ -206,8 +206,11 @@ export function GalleryCard({ { + onClick={(e) => { + e.preventDefault(); + e.stopPropagation(); loadDemo(item, true); + return false; }} className="open-code-btn" /> From c0973123a5dd5d74a422c2ae0647bfea0a75a112 Mon Sep 17 00:00:00 2001 From: jjspace <8007967+jjspace@users.noreply.github.com> Date: Wed, 27 Aug 2025 19:30:51 -0400 Subject: [PATCH 3/3] fix typo --- packages/sandcastle/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sandcastle/src/App.tsx b/packages/sandcastle/src/App.tsx index 1fd31d689101..aa64ecfe987f 100644 --- a/packages/sandcastle/src/App.tsx +++ b/packages/sandcastle/src/App.tsx @@ -610,7 +610,7 @@ function App() { } setLeftPanel("editor"); } else { - // Load the gallery item every time it's clicked ro act as a "rerun" button + // Load the gallery item every time it's clicked to act as a "rerun" button loadGalleryItem(item.id); } }}