diff --git a/src/ui/omnibarGuide.js b/src/ui/omnibarGuide.js index 6903357400..0e1a668a80 100644 --- a/src/ui/omnibarGuide.js +++ b/src/ui/omnibarGuide.js @@ -501,14 +501,16 @@ export function startGuide(steps, { title = '' } = {}) { ...handlers, }); renderVue(vnode, host); - return vnode.component.exposed; + return vnode; } // Focus returns where it was when the walk ends, if that is still there. const returnFocus = doc.activeElement; - const elements = paint(); - const root = elements.root.value; - const ring = elements.ring.value; - const callout = elements.callout.value; + // The elements come from the rendered tree, which is in place as soon as the + // render returns; template refs are filled after it, and later still when + // the walk starts inside one of Vue's own post-render updates. + const root = paint().component.subTree.children[0].el; + const ring = root.querySelector(':scope > .gev-guide-ring'); + const callout = root.querySelector(':scope > .gev-guide-callout'); const subRings = []; const live = steps.filter(Boolean); diff --git a/src/ui/omnibarGuide.test.mjs b/src/ui/omnibarGuide.test.mjs index b221f73a69..615f7d2f8f 100644 --- a/src/ui/omnibarGuide.test.mjs +++ b/src/ui/omnibarGuide.test.mjs @@ -2,6 +2,7 @@ import '../testSupport/registerDom.mjs'; import test from 'node:test'; import assert from 'node:assert/strict'; +import { createApp, h, onMounted } from 'vue'; import { startGuide } from './omnibarGuide.js'; const settle = () => new Promise((resolve) => setTimeout(resolve, 0)); @@ -109,3 +110,27 @@ test('starting another walk ends the one in progress', async (t) => { assert.equal(document.querySelectorAll('.gev-guide').length, 1); assert.equal($('.gev-guide-text').textContent, 'Second'); }); + +test('a walk started while Vue mounts something else still starts and ends', async (t) => { + const { target, field } = fixture(t); + let stop = null; + const app = createApp({ + setup() { + onMounted(() => { + stop = startGuide([ + { targets: () => [target], text: () => 'Press it' }, + ]); + }); + return () => h('span'); + }, + }); + app.mount(document.body.appendChild(document.createElement('div'))); + t.after(() => app.unmount()); + await settle(); + assert.equal(typeof stop, 'function'); + assert.equal(document.activeElement, $('.gev-guide-callout')); + assert.ok($('.gev-guide').classList.contains('visible')); + stop(); + assert.equal($('.gev-guide'), null); + assert.equal(document.activeElement, field); +}); diff --git a/src/ui/views/panels/OmnibarGuide.vue b/src/ui/views/panels/OmnibarGuide.vue index 3be5b9b852..71f1c95069 100644 --- a/src/ui/views/panels/OmnibarGuide.vue +++ b/src/ui/views/panels/OmnibarGuide.vue @@ -1,5 +1,4 @@