| 12345678910111213141516171819202122232425262728293031 |
- Object.defineProperty(document, "getSelection", {
- value: () => ({
- removeAllRanges: () => {},
- addRange: () => {},
- rangeCount: 0,
- }),
- writable: true,
- })
- // ── defineModel / useModel local mode quirk ──
- //
- // In Vue 3.5, useModel (compiled from defineModel) enters "local mode"
- // when no onUpdate:X listener is provided by the parent. The local ref
- // initialises as undefined, NOT from the prop value.
- //
- // VTU's shallowMount(Comp, { props: { content: "Hello" } }) sets the
- // prop but does NOT supply a synthetic onUpdate:content listener, so
- // useModel enters local mode and content.value is undefined on the
- // first tick. Any immediate watcher on content.value fires with
- // undefined instead of "Hello".
- //
- // Two solutions (both applied to this codebase):
- //
- // 1. In tests: provide `"onUpdate:content": vi.fn()` alongside the
- // content prop to keep useModel in "connected" mode.
- //
- // 2. In Editor.vue: watch `content.value ?? props.content` so the
- // immediate fallback reads from the raw prop when useModel is in
- // local mode.
- //
- // Reference: https://github.com/vuejs/core/issues/12005
|