Skip to content
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

fix(compat): don't warn deprecation if compat config is disabled #12447

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/runtime-core/src/compat/compatConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export function warnDeprecation(

// check user config
const config = getCompatConfigForKey(key, instance)
if (config === 'suppress-warning') {
if (config === false || config === 'suppress-warning') {
return
}

Expand Down
5 changes: 2 additions & 3 deletions packages/runtime-dom/src/modules/attrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@ export function compatCoerceAttr(
} else if (
value === false &&
!isSpecialBooleanAttr(key) &&
compatUtils.isCompatEnabled(DeprecationTypes.ATTR_FALSE_VALUE, instance)
) {
compatUtils.warnDeprecation(
compatUtils.softAssertCompatEnabled(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems not to be proper.
see 04729ba
see #11126 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in compatConfig.ts

if (config === false || config === 'suppress-warning') {
   return
}

fix the this PR related issue and #11126 also, so this change is just revert the some slightly cumbersome logic of 04729ba.
Moreover, it is possible to see that both the original test and the new test have passed.

DeprecationTypes.ATTR_FALSE_VALUE,
instance,
key,
)
) {
el.removeAttribute(key)
return true
}
Expand Down
1 change: 0 additions & 1 deletion packages/vue-compat/__tests__/compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ afterEach(() => {
Vue.configureCompat({ MODE: 3 })
})

// COMPILER_V_FOR_REF is tested in ./refInfor.spec.ts
// COMPILER_FILTERS is tested in ./filters.spec.ts

test('COMPILER_IS_ON_ELEMENT', () => {
Expand Down
101 changes: 39 additions & 62 deletions packages/vue-compat/__tests__/misc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,35 +158,17 @@ test('CUSTOM_DIR', async () => {

expect(getCalls()).toMatchObject([1, 1, 0, 0, 0])

expect(
(deprecationData[DeprecationTypes.CUSTOM_DIR].message as Function)(
'bind',
'beforeMount',
),
).toHaveBeenWarned()
expect(
(deprecationData[DeprecationTypes.CUSTOM_DIR].message as Function)(
'inserted',
'mounted',
),
).toHaveBeenWarned()
const message = deprecationData[DeprecationTypes.CUSTOM_DIR]
.message as Function
expect(message('bind', 'beforeMount')).toHaveBeenWarned()
expect(message('inserted', 'mounted')).toHaveBeenWarned()

vm.foo++
await nextTick()
expect(getCalls()).toMatchObject([1, 1, 1, 1, 0])

expect(
(deprecationData[DeprecationTypes.CUSTOM_DIR].message as Function)(
'update',
'updated',
),
).toHaveBeenWarned()
expect(
(deprecationData[DeprecationTypes.CUSTOM_DIR].message as Function)(
'componentUpdated',
'updated',
),
).toHaveBeenWarned()
expect(message('update', 'updated')).toHaveBeenWarned()
expect(message('componentUpdated', 'updated')).toHaveBeenWarned()
})

test('ATTR_FALSE_VALUE', () => {
Expand All @@ -196,16 +178,28 @@ test('ATTR_FALSE_VALUE', () => {
expect(vm.$el).toBeInstanceOf(HTMLDivElement)
expect(vm.$el.hasAttribute('id')).toBe(false)
expect(vm.$el.hasAttribute('foo')).toBe(false)
expect(
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
'id',
),
).toHaveBeenWarned()
expect(
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
'foo',
),
).toHaveBeenWarned()

const message = deprecationData[DeprecationTypes.ATTR_FALSE_VALUE]
.message as Function
expect(message('id')).toHaveBeenWarned()
expect(message('foo')).toHaveBeenWarned()
})

test(`ATTR_FALSE_VALUE with 'suppress-warning' value shouldn't throw warning`, () => {
const vm = new Vue({
template: `<div :id="false" :foo="false"/>`,
compatConfig: {
ATTR_FALSE_VALUE: 'suppress-warning',
},
}).$mount()
expect(vm.$el).toBeInstanceOf(HTMLDivElement)
expect(vm.$el.hasAttribute('id')).toBe(false)
expect(vm.$el.hasAttribute('foo')).toBe(false)

const message = deprecationData[DeprecationTypes.ATTR_FALSE_VALUE]
.message as Function
expect(message('id')).not.toHaveBeenWarned()
expect(message('foo')).not.toHaveBeenWarned()
})

test("ATTR_FALSE_VALUE with false value shouldn't throw warning", () => {
Expand All @@ -221,16 +215,11 @@ test("ATTR_FALSE_VALUE with false value shouldn't throw warning", () => {
expect(vm.$el.getAttribute('id')).toBe('false')
expect(vm.$el.hasAttribute('foo')).toBe(true)
expect(vm.$el.getAttribute('foo')).toBe('false')
expect(
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
'id',
),
).not.toHaveBeenWarned()
expect(
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
'foo',
),
).not.toHaveBeenWarned()

const message = deprecationData[DeprecationTypes.ATTR_FALSE_VALUE]
.message as Function
expect(message('id')).not.toHaveBeenWarned()
expect(message('foo')).not.toHaveBeenWarned()
})

test('ATTR_ENUMERATED_COERCION', () => {
Expand All @@ -242,22 +231,10 @@ test('ATTR_ENUMERATED_COERCION', () => {
expect(vm.$el.getAttribute('draggable')).toBe('false')
expect(vm.$el.getAttribute('spellcheck')).toBe('true')
expect(vm.$el.getAttribute('contenteditable')).toBe('true')
expect(
(
deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
.message as Function
)('draggable', null, 'false'),
).toHaveBeenWarned()
expect(
(
deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
.message as Function
)('spellcheck', 0, 'true'),
).toHaveBeenWarned()
expect(
(
deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
.message as Function
)('contenteditable', 'foo', 'true'),
).toHaveBeenWarned()

const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
.message as Function
expect(message('draggable', null, 'false')).toHaveBeenWarned()
expect(message('spellcheck', 0, 'true')).toHaveBeenWarned()
expect(message('contenteditable', 'foo', 'true')).toHaveBeenWarned()
})