From 1f34210f71c4815f8a7b2a719f3a6715bc1a416a Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Thu, 19 Nov 2026 01:21:10 -0800 Subject: [PATCH] Vue kit: a late close event no longer shuts a reopened dialog; a scene sharing dialog the browser closes closes through its owner; the opened timing test can fail Co-authored-by: Manjunath Paparaju --- src/ui/kit/UiDialog.test.mjs | 40 ++++++++++++++++++++++++----- src/ui/kit/UiDialog.vue | 4 ++- src/ui/sceneSharingView.test.mjs | 16 ++++++++++++ src/ui/views/panels/SceneDialog.vue | 2 +- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/ui/kit/UiDialog.test.mjs b/src/ui/kit/UiDialog.test.mjs index 9514706c8a..13c0846c92 100644 --- a/src/ui/kit/UiDialog.test.mjs +++ b/src/ui/kit/UiDialog.test.mjs @@ -77,15 +77,32 @@ test('a dialog mounted open opens modal on mount; unmounting closes it', async ( }); test('the open state follows the content: opened comes after it renders', async () => { - const { wrapper } = dialog(); + // The content changes in the same update that opens the dialog, so an + // opened emitted before that update renders would see the old words. + const { h } = await import('vue'); let seen; - await wrapper.setProps({ - open: true, - onOpened: () => { - seen = wrapper.element.querySelector('.content')?.textContent; + const Host = { + props: { open: Boolean, words: String }, + setup(props) { + return () => + h( + UiDialog, + { + open: props.open, + onOpened: () => { + seen = document.querySelector('dialog .content')?.textContent; + }, + }, + () => h('p', { class: 'content' }, props.words), + ); }, + }; + const wrapper = mount(Host, { + attachTo: document.body, + props: { open: false, words: 'Before' }, }); - assert.equal(seen, 'Words'); + await wrapper.setProps({ open: true, words: 'After' }); + assert.equal(seen, 'After'); wrapper.unmount(); }); @@ -116,6 +133,17 @@ test('a close the browser made while open is reported once; the owner’s is not wrapper.unmount(); }); +test('a late close event from an earlier close is not reported once open again', async () => { + const { wrapper, events } = dialog({ open: true }); + await wrapper.setProps({ open: false }); + await wrapper.setProps({ open: true }); + events.length = 0; + // The browser's queued close event from the first close lands now. + wrapper.element.dispatchEvent(new Event('close')); + assert.deepEqual(events, [], 'no browserClose'); + wrapper.unmount(); +}); + test('a backdrop click dismisses only when asked, and only on the dialog', async () => { const plain = dialog({ open: true }); plain.events.length = 0; diff --git a/src/ui/kit/UiDialog.vue b/src/ui/kit/UiDialog.vue index 986a74bc3e..1ffa95e3b2 100644 --- a/src/ui/kit/UiDialog.vue +++ b/src/ui/kit/UiDialog.vue @@ -54,8 +54,10 @@ function onCancel(event) { event.preventDefault(); emit('dismiss'); } +// The browser queues its close event, so one from an earlier close can land +// after the dialog has been opened again; only a dialog still shut reports it. function onClose() { - if (!unmounting && props.open) emit('browserClose'); + if (!unmounting && props.open && !element.value?.open) emit('browserClose'); } function onClick(event) { if (props.backdropDismiss && event.target === event.currentTarget) diff --git a/src/ui/sceneSharingView.test.mjs b/src/ui/sceneSharingView.test.mjs index c9fd8e646a..f0e1e31e2f 100644 --- a/src/ui/sceneSharingView.test.mjs +++ b/src/ui/sceneSharingView.test.mjs @@ -187,6 +187,22 @@ test('Cancel and Escape close through the owner; dispose removes the dialog', as assert.equal(store.controls, null); }); +test('a close the browser makes on its own also closes through the owner', async (t) => { + // A repeated Escape can close a modal without a cancel the page may stop. + const { store } = fixture(t); + let closes = 0; + const dialog = createSceneDialog( + 'Share selected scene', + () => closes++, + store, + ); + await nextTick(); + $('dialog').close(); + assert.equal(closes, 1); + dialog.dispose(); + await nextTick(); +}); + test('a replaced dialog opens fresh and its late dispose leaves the new one', async (t) => { const { store } = fixture(t); opened.length = 0; diff --git a/src/ui/views/panels/SceneDialog.vue b/src/ui/views/panels/SceneDialog.vue index 57ed00f70b..39b0fad100 100644 --- a/src/ui/views/panels/SceneDialog.vue +++ b/src/ui/views/panels/SceneDialog.vue @@ -42,7 +42,7 @@ const chooserStyle = (focused) => ({ padding: '3px 9px', border: '1px solid #397