Skip to content

Commit 757aa74

Browse files
Doctor-wusxzz
authored andcommitted
feat(runtime-vapor): impl fallthrough attrs
1 parent 2f8b9af commit 757aa74

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/runtime-vapor/src/apiRender.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { flushPostFlushCbs, queuePostRenderEffect } from './scheduler'
55
import { proxyRefs } from '@vue/reactivity'
66
import { invokeLifecycle } from './componentLifecycle'
77
import { VaporLifecycleHooks } from './apiLifecycle'
8+
import { fallThroughAttrs } from './componentAttrs'
89

910
export const fragmentKey = Symbol(__DEV__ ? `fragmentKey` : ``)
1011

@@ -47,7 +48,11 @@ export function setupComponent(instance: ComponentInternalInstance): void {
4748
// TODO: warn no template
4849
block = []
4950
}
50-
return (instance.block = block)
51+
instance.block = block
52+
if (instance.inheritAttrs !== false) {
53+
fallThroughAttrs(instance)
54+
}
55+
return block
5156
})
5257
reset()
5358
}

packages/runtime-vapor/src/componentAttrs.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { camelize, isFunction } from '@vue/shared'
1+
import { camelize, isArray, isFunction } from '@vue/shared'
22
import type { ComponentInternalInstance } from './component'
33
import { isEmitListener } from './componentEmits'
4+
import type { Block } from './apiRender'
45

56
export function patchAttrs(instance: ComponentInternalInstance) {
67
const attrs = instance.attrs
@@ -42,3 +43,20 @@ export function patchAttrs(instance: ComponentInternalInstance) {
4243
}
4344
}
4445
}
46+
47+
export function fallThroughAttrs(instance: ComponentInternalInstance) {
48+
const attrs = instance.attrs
49+
const block = getFallThroughNode(instance.block!)
50+
if (!block) return
51+
for (const key in attrs) {
52+
if (block instanceof Element) {
53+
block.setAttribute(key, String(attrs[key]))
54+
}
55+
}
56+
}
57+
58+
function getFallThroughNode(block: Block) {
59+
if (block instanceof Node) return block
60+
if (isArray(block) && block.length === 1) return getFallThroughNode(block[0])
61+
return null
62+
}

0 commit comments

Comments
 (0)