} from '@vue/runtime-dom'
import {
createComponent,
+ createDynamicComponent,
+ createSlot,
defineVaporComponent,
renderEffect,
setClass,
expect(getCSS()).not.toContain('font-size:bold')
})
- test('parent value should take priority', async () => {
+ it('should fallthrough attrs to dynamic component', async () => {
+ const Comp = defineVaporComponent({
+ setup() {
+ const n1 = createDynamicComponent(
+ () => 'button',
+ null,
+ {
+ default: () => {
+ const n0 = createSlot('default', null)
+ return n0
+ },
+ },
+ true,
+ )
+ return n1
+ },
+ })
+
+ const { html } = define({
+ setup() {
+ return createComponent(
+ Comp,
+ {
+ class: () => 'foo',
+ },
+ null,
+ true,
+ )
+ },
+ }).render()
+
+ expect(html()).toBe(
+ '<button class="foo"><!--slot--></button><!--dynamic-component-->',
+ )
+ })
+
+ it('parent value should take priority', async () => {
const parentVal = ref('parent')
const childVal = ref('child')
unregisterHMR,
warn,
} from '@vue/runtime-dom'
-import { type Block, insert, isBlock, remove } from './block'
+import { type Block, DynamicFragment, insert, isBlock, remove } from './block'
import {
type ShallowRef,
markRaw,
if (
instance.hasFallthrough &&
component.inheritAttrs !== false &&
- instance.block instanceof Element &&
Object.keys(instance.attrs).length
) {
- renderEffect(() => {
- isApplyingFallthroughProps = true
- setDynamicProps(instance.block as Element, [instance.attrs])
- isApplyingFallthroughProps = false
- })
+ const el = getRootElement(instance)
+ if (el) {
+ renderEffect(() => {
+ isApplyingFallthroughProps = true
+ setDynamicProps(el, [instance.attrs])
+ isApplyingFallthroughProps = false
+ })
+ }
}
resetTracking()
)
}
}
+
+function getRootElement({
+ block,
+}: VaporComponentInstance): Element | undefined {
+ if (block instanceof Element) {
+ return block
+ }
+
+ if (block instanceof DynamicFragment) {
+ const { nodes } = block
+ if (nodes instanceof Element && (nodes as any).$root) {
+ return nodes
+ }
+ }
+}
if (dynamicSources) {
let i = dynamicSources.length
while (i--) {
- if (hasOwn(resolveSource(dynamicSources[i]), key)) {
+ const source = resolveSource(dynamicSources[i])
+ if (source && hasOwn(source, key)) {
return true
}
}