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 <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-19 01:21:10 -08:00
1 parent ec4a5b6afe
commit 1f34210f71
4 files changed
+54 -8

No files matched your search

+34 -6
View File
@@ -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;
+3 -1
View File
@@ -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)