From ab7752f1c22613077244e793d7c75a1b3f162902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E6=9D=89?= Date: Fri, 25 Feb 2022 15:48:41 +0800 Subject: [PATCH 1/2] fix: patch translate as an attr --- packages/runtime-dom/__tests__/patchProps.spec.ts | 7 +++++++ packages/runtime-dom/src/patchProp.ts | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/packages/runtime-dom/__tests__/patchProps.spec.ts b/packages/runtime-dom/__tests__/patchProps.spec.ts index 07aee676ded..24760695040 100644 --- a/packages/runtime-dom/__tests__/patchProps.spec.ts +++ b/packages/runtime-dom/__tests__/patchProps.spec.ts @@ -263,4 +263,11 @@ describe('runtime-dom: props patching', () => { ) expect(el.value).toBe('baz') }) + + test('translate attribute', () => { + const el = document.createElement('div') + patchProp(el, 'translate', null, 'no') + expect(el.translate).toBeFalsy() + expect(el.getAttribute('translate')).toBe('no') + }) }) diff --git a/packages/runtime-dom/src/patchProp.ts b/packages/runtime-dom/src/patchProp.ts index e10d189c581..a25258adf86 100644 --- a/packages/runtime-dom/src/patchProp.ts +++ b/packages/runtime-dom/src/patchProp.ts @@ -105,6 +105,12 @@ function shouldSetAsProp( return false } + // #5462 translate is an enumerated attr, however its + // corresponding DOM property are actually boolean. + if (key === 'translate') { + return false + } + // native onclick with string value, must be set as attribute if (nativeOnRE.test(key) && isString(value)) { return false From 089b4c7e8ec26c3b7ca9facf6c98fd640efd655e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E6=9D=89?= Date: Tue, 1 Mar 2022 00:32:18 +0800 Subject: [PATCH 2/2] moveup --- packages/runtime-dom/src/patchProp.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/runtime-dom/src/patchProp.ts b/packages/runtime-dom/src/patchProp.ts index a25258adf86..6d65a63a88c 100644 --- a/packages/runtime-dom/src/patchProp.ts +++ b/packages/runtime-dom/src/patchProp.ts @@ -79,13 +79,13 @@ function shouldSetAsProp( return false } - // spellcheck and draggable are numerated attrs, however their - // corresponding DOM properties are actually booleans - this leads to - // setting it with a string "false" value leading it to be coerced to - // `true`, so we need to always treat them as attributes. + // these are enumerated attrs, however their corresponding DOM properties + // are actually booleans - this leads to setting it with a string "false" + // value leading it to be coerced to `true`, so we need to always treat + // them as attributes. // Note that `contentEditable` doesn't have this problem: its DOM // property is also enumerated string values. - if (key === 'spellcheck' || key === 'draggable') { + if (key === 'spellcheck' || key === 'draggable' || key === 'translate') { return false } @@ -105,12 +105,6 @@ function shouldSetAsProp( return false } - // #5462 translate is an enumerated attr, however its - // corresponding DOM property are actually boolean. - if (key === 'translate') { - return false - } - // native onclick with string value, must be set as attribute if (nativeOnRE.test(key) && isString(value)) { return false