Skip to content

Commit 9d25c35

Browse files
committed
fix: warn extraneous attributes for non-single-root components and prevent Teleport attribute fallthrough.
1 parent a8c435d commit 9d25c35

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

packages/runtime-vapor/__tests__/componentAttrs.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ describe('attribute fallthrough', () => {
306306
expect(html()).toMatch(`<div class="child parent">1</div>`)
307307
})
308308

309-
it.todo('should warn when fallthrough fails on non-single-root', () => {
309+
it('should warn when fallthrough fails on non-single-root', () => {
310310
const Parent = {
311311
setup() {
312312
return createComponent(Child, {
@@ -330,7 +330,7 @@ describe('attribute fallthrough', () => {
330330
expect(`Extraneous non-emits event listeners`).toHaveBeenWarned()
331331
})
332332

333-
it.todo('should warn when fallthrough fails on teleport root node', () => {
333+
it('should warn when fallthrough fails on teleport root node', () => {
334334
const Parent = {
335335
render() {
336336
return createComponent(Child, { class: () => 'parent' })
@@ -890,6 +890,7 @@ describe('attribute fallthrough', () => {
890890
},
891891
}).render()
892892
expect(host.innerHTML).toBe('<span></span><div>1</div>')
893+
expect(`Extraneous non-props attributes (id)`).toHaveBeenWarned()
893894
})
894895

895896
it('should not allow attrs to fallthrough on component with single comment root', async () => {
@@ -908,6 +909,7 @@ describe('attribute fallthrough', () => {
908909
},
909910
}).render()
910911
expect(host.innerHTML).toBe('<!--comment-->')
912+
expect(`Extraneous non-props attributes (id)`).toHaveBeenWarned()
911913
})
912914

913915
it('should not fallthrough if explicitly pass inheritAttrs: false', async () => {

packages/runtime-vapor/src/component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
startMeasure,
2929
unregisterHMR,
3030
warn,
31+
warnExtraneousAttributes,
3132
} from '@vue/runtime-dom'
3233
import {
3334
type Block,
@@ -410,7 +411,7 @@ export function setupComponent(
410411
if (root) {
411412
renderEffect(() => applyFallthroughProps(root, instance.attrs))
412413
} else if (__DEV__ && isArray(instance.block)) {
413-
// TODO warn extraneous attributes
414+
warnExtraneousAttributes(instance.attrs)
414415
}
415416
}
416417

packages/runtime-vapor/src/components/Teleport.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import {
99
queuePostFlushCb,
1010
resolveTeleportTarget,
1111
warn,
12+
warnExtraneousAttributes,
1213
} from '@vue/runtime-dom'
1314
import { type Block, type BlockFn, insert, remove } from '../block'
1415
import { createComment, createTextNode, querySelector } from '../dom/node'
1516
import {
1617
type LooseRawProps,
1718
type LooseRawSlots,
1819
type VaporComponentInstance,
19-
applyFallthroughProps,
2020
isVaporComponent,
2121
} from '../component'
2222
import { rawPropsProxyHandlers } from '../componentProps'
@@ -148,14 +148,11 @@ export class TeleportFragment extends VaporFragment<Block[]> {
148148
this.$transition = applyTransitionHooks(this.nodes, this.$transition)
149149
}
150150

151-
// fallthrough attrs
151+
// preventing attrs fallthrough
152+
// consistent with VDOM Teleport behavior
152153
const instance = this.parentComponent as VaporComponentInstance
153-
if (
154-
instance.hasFallthrough &&
155-
Object.keys(instance.attrs).length &&
156-
this.nodes instanceof Element
157-
) {
158-
applyFallthroughProps(this.nodes, instance.attrs)
154+
if (instance.hasFallthrough && Object.keys(instance.attrs).length) {
155+
warnExtraneousAttributes(instance.attrs)
159156
}
160157

161158
insert(

0 commit comments

Comments
 (0)