diff --git a/src/stories/controller.js b/src/stories/controller.js index 8147792eb..1ae41e709 100644 --- a/src/stories/controller.js +++ b/src/stories/controller.js @@ -268,13 +268,18 @@ export function createStoriesController({ ? controller.open({ fromHistory: true }) : controller.backToExplore({ fromHistory: true, returningToExplore }); else if (store.mode !== 'closed') controller.close({ fromHistory: true }); - else if (pendingView) { - // Another browser navigation landed while the scene was stopping. - // The destination owns the globe now, so discard the earlier restore. - pendingView = null; - closeGeneration += 1; - document.body.classList.remove('stories-mode'); - shareLink()?.holdWrites?.(false); + else { + // An entry for a story that is gone (deleted since) opens nothing; + // its ?story= must not stay in the address for the next share link. + if (id) clearStoriesUrl(); + if (pendingView) { + // Another browser navigation landed while the scene was stopping. + // The destination owns the globe now, so discard the earlier restore. + pendingView = null; + closeGeneration += 1; + document.body.classList.remove('stories-mode'); + shareLink()?.holdWrites?.(false); + } } } addEventListener('popstate', onPopState); diff --git a/src/stories/controller.test.mjs b/src/stories/controller.test.mjs index a62811497..d89d11f2b 100644 --- a/src/stories/controller.test.mjs +++ b/src/stories/controller.test.mjs @@ -948,6 +948,24 @@ test('Close after Back to Explore still puts AUTHORING’s selection back', asyn controller.destroy(); }); +test('Back into the entry of a deleted story, with Stories closed, clears ?story=', () => { + const { controller, store } = setup(); + assert.equal(store.mode, 'closed'); + history.replaceState( + { gevStories: { story: 'gev:gone', depth: 2, explore: 1 } }, + '', + '/?story=gev%3Agone&storyTime=12#lat=1', + ); + dispatchEvent(new PopStateEvent('popstate')); + assert.equal(store.mode, 'closed', 'nothing opens'); + const url = new URL(location.href); + assert.equal(url.searchParams.has('story'), false); + assert.equal(url.searchParams.has('storyTime'), false); + assert.equal(url.hash, '#lat=1', 'the globe state stays'); + assert.equal(history.state?.gevStories, undefined); + controller.destroy(); +}); + test('unsaved scenes appear as local drafts and disappear when deleted', () => { setActivePinia(createPinia()); history.replaceState(null, '', '/');