mirror of https://github.com/vuejs/core.git
fix(runtime-vapor): dynamic component fallback rendering with insertion state (#13492)
This commit is contained in:
parent
cb925112f5
commit
a6e4966257
|
@ -1,6 +1,13 @@
|
||||||
import { shallowRef } from '@vue/reactivity'
|
import { ref, shallowRef } from '@vue/reactivity'
|
||||||
import { nextTick } from '@vue/runtime-dom'
|
import { nextTick, resolveDynamicComponent } from '@vue/runtime-dom'
|
||||||
import { createDynamicComponent } from '../src'
|
import {
|
||||||
|
createComponentWithFallback,
|
||||||
|
createDynamicComponent,
|
||||||
|
renderEffect,
|
||||||
|
setHtml,
|
||||||
|
setInsertionState,
|
||||||
|
template,
|
||||||
|
} from '../src'
|
||||||
import { makeRender } from './_utils'
|
import { makeRender } from './_utils'
|
||||||
|
|
||||||
const define = makeRender()
|
const define = makeRender()
|
||||||
|
@ -54,4 +61,22 @@ describe('api: createDynamicComponent', () => {
|
||||||
await nextTick()
|
await nextTick()
|
||||||
expect(html()).toBe('<baz></baz><!--dynamic-component-->')
|
expect(html()).toBe('<baz></baz><!--dynamic-component-->')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('render fallback with insertionState', async () => {
|
||||||
|
const { html, mount } = define({
|
||||||
|
setup() {
|
||||||
|
const html = ref('hi')
|
||||||
|
const n1 = template('<div></div>', true)() as any
|
||||||
|
setInsertionState(n1)
|
||||||
|
const n0 = createComponentWithFallback(
|
||||||
|
resolveDynamicComponent('button') as any,
|
||||||
|
) as any
|
||||||
|
renderEffect(() => setHtml(n0, html.value))
|
||||||
|
return n1
|
||||||
|
},
|
||||||
|
}).create()
|
||||||
|
|
||||||
|
mount()
|
||||||
|
expect(html()).toBe('<div><button>hi</button></div>')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -476,6 +476,14 @@ export function createComponentWithFallback(
|
||||||
return createComponent(comp, rawProps, rawSlots, isSingleRoot)
|
return createComponent(comp, rawProps, rawSlots, isSingleRoot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const _insertionParent = insertionParent
|
||||||
|
const _insertionAnchor = insertionAnchor
|
||||||
|
if (isHydrating) {
|
||||||
|
locateHydrationNode()
|
||||||
|
} else {
|
||||||
|
resetInsertionState()
|
||||||
|
}
|
||||||
|
|
||||||
const el = document.createElement(comp)
|
const el = document.createElement(comp)
|
||||||
// mark single root
|
// mark single root
|
||||||
;(el as any).$root = isSingleRoot
|
;(el as any).$root = isSingleRoot
|
||||||
|
@ -494,6 +502,10 @@ export function createComponentWithFallback(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isHydrating && _insertionParent) {
|
||||||
|
insert(el, _insertionParent, _insertionAnchor)
|
||||||
|
}
|
||||||
|
|
||||||
return el
|
return el
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue