From 1333be0c6ad22fc49792a76478fcb231314bb765 Mon Sep 17 00:00:00 2001 From: Filip Ambrosius Date: Mon, 27 Mar 2023 11:02:12 +0200 Subject: [PATCH] fix: Regression `itemscope` as `boolean_attribute` (#8414) Microdata are a strange set of attributes which are ONLY defined in markup, and have no relationship to the underlying Document Object Model node. As such programmatically defining an element and setting a property on it with a given Microdata attribute will not work: https://codepen.io/iambrosius/full/jOvXBBG One can read more about microdata here: https://developer.mozilla.org/en-US/docs/Web/HTML/Microdata The fix is to remove itemscope being a boolean attribute, because that opts into a transformation as a DOM property, which is wrong. --- .../render_dom/wrappers/Element/Attribute.ts | 1 - src/shared/boolean_attributes.ts | 1 - .../attribute-boolean-hidden/_config.js | 10 ++++++ .../attribute-boolean-hidden/main.svelte | 5 +++ .../attribute-boolean-itemscope/_config.js | 11 ------- .../attribute-boolean-itemscope/main.svelte | 5 --- .../samples/attribute-microdata/_config.js | 25 +++++++++++++++ .../samples/attribute-microdata/main.svelte | 31 +++++++++++++++++++ 8 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 test/runtime/samples/attribute-boolean-hidden/_config.js create mode 100644 test/runtime/samples/attribute-boolean-hidden/main.svelte delete mode 100644 test/runtime/samples/attribute-boolean-itemscope/_config.js delete mode 100644 test/runtime/samples/attribute-boolean-itemscope/main.svelte create mode 100644 test/runtime/samples/attribute-microdata/_config.js create mode 100644 test/runtime/samples/attribute-microdata/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts index 6cb3a00218..64178030f6 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts @@ -364,7 +364,6 @@ const attribute_lookup: { [key in BooleanAttributes]: AttributeMetadata } & { [k indeterminate: { applies_to: ['input'] }, inert: {}, ismap: { property_name: 'isMap', applies_to: ['img'] }, - itemscope: {}, loop: { applies_to: ['audio', 'bgsound', 'video'] }, multiple: { applies_to: ['input', 'select'] }, muted: { applies_to: ['audio', 'video'] }, diff --git a/src/shared/boolean_attributes.ts b/src/shared/boolean_attributes.ts index 668dd97975..10513ec712 100644 --- a/src/shared/boolean_attributes.ts +++ b/src/shared/boolean_attributes.ts @@ -13,7 +13,6 @@ const _boolean_attributes = [ 'hidden', 'inert', 'ismap', - 'itemscope', 'loop', 'multiple', 'muted', diff --git a/test/runtime/samples/attribute-boolean-hidden/_config.js b/test/runtime/samples/attribute-boolean-hidden/_config.js new file mode 100644 index 0000000000..cb38feb93d --- /dev/null +++ b/test/runtime/samples/attribute-boolean-hidden/_config.js @@ -0,0 +1,10 @@ +export default { + props: { + hidden: true + }, + html: '