Skip to content

fix(runtime-core): fix resolving inheritAttrs from mixins #3742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,34 @@ describe('attribute fallthrough', () => {
expect(root.innerHTML).toMatch(`<div>1</div>`)
})

// #3741
it('should not fallthrough with inheritAttrs: false from mixins', () => {
const Parent = {
render() {
return h(Child, { foo: 1, class: 'parent' })
}
}

const mixin = {
inheritAttrs: false
}

const Child = defineComponent({
mixins: [mixin],
props: ['foo'],
render() {
return h('div', this.foo)
}
})

const root = document.createElement('div')
document.body.appendChild(root)
render(h(Parent), root)

// should not contain class
expect(root.innerHTML).toMatch(`<div>1</div>`)
})

it('explicit spreading with inheritAttrs: false', () => {
const Parent = {
render() {
Expand Down
5 changes: 4 additions & 1 deletion packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ export function applyOptions(
renderTriggered,
errorCaptured,
// public API
expose
expose,
inheritAttrs
} = options

const publicThis = instance.proxy!
Expand Down Expand Up @@ -753,6 +754,8 @@ export function applyOptions(
if (__COMPAT__ && isCompatEnabled(DeprecationTypes.FILTERS, instance)) {
resolveInstanceAssets(instance, options, FILTERS)
}

if (inheritAttrs !== undefined) instance.type.inheritAttrs = inheritAttrs
}

// lifecycle options
Expand Down