Skip to content

Commit

Permalink
add an aditional check for is in element attributes/props for custo…
Browse files Browse the repository at this point in the history
…m elements (#348)
  • Loading branch information
titoBouzout authored and ryansolid committed Sep 9, 2024
1 parent 02547f8 commit f9a00f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/babel-plugin-jsx-dom-expressions/src/dom/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function transformElement(path, info) {
config = getConfig(path),
wrapSVG = info.topLevel && tagName != "svg" && SVGElements.has(tagName),
voidTag = VoidElements.indexOf(tagName) > -1,
isCustomElement = tagName.indexOf("-") > -1 || !!path.get("openingElement").get("attributes").find(a => a.node.name?.name === "is"),
isCustomElement = tagName.indexOf("-") > -1 || path.get("openingElement").get("attributes").some(a => a.node?.name?.name === "is" || a.name?.name === "is"),
isImportNode = (tagName === 'img'||tagName === 'iframe') && path.get("openingElement").get("attributes").some(a => a.node.name?.name === "loading" && a.node.value?.value === "lazy"
),
results = {
Expand Down Expand Up @@ -273,7 +273,7 @@ function transformAttributes(path, results) {
attributes = path.get("openingElement").get("attributes");
const tagName = getTagName(path.node),
isSVG = SVGElements.has(tagName),
isCE = tagName.includes("-"),
isCE = tagName.includes("-") || attributes.some(a => a.node.name?.name === 'is'),
hasChildren = path.node.children.length > 0,
config = getConfig(path);

Expand Down Expand Up @@ -1000,7 +1000,7 @@ function detectExpressions(children, index, config) {
} else if (t.isJSXElement(child)) {
const tagName = getTagName(child);
if (isComponent(tagName)) return true;
if (config.contextToCustomElements && (tagName === "slot" || tagName.indexOf("-") > -1))
if (config.contextToCustomElements && (tagName === "slot" || tagName.indexOf("-") > -1 || child.openingElement.attributes.some(a => a.name?.name === 'is')))
return true;
if (
child.openingElement.attributes.some(
Expand Down
8 changes: 4 additions & 4 deletions packages/dom-expressions/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export function assign(node, props, isSVG, skipChildren, prevProps = {}, skipRef
for (const prop in prevProps) {
if (!(prop in props)) {
if (prop === "children") continue;
prevProps[prop] = assignProp(node, prop, null, prevProps[prop], isSVG, skipRef);
prevProps[prop] = assignProp(node, prop, null, prevProps[prop], isSVG, skipRef, props);
}
}
for (const prop in props) {
Expand All @@ -223,7 +223,7 @@ export function assign(node, props, isSVG, skipChildren, prevProps = {}, skipRef
continue;
}
const value = props[prop];
prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG, skipRef);
prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG, skipRef, props);
}
}

Expand Down Expand Up @@ -323,7 +323,7 @@ function toggleClassKey(node, key, value) {
node.classList.toggle(classNames[i], value);
}

function assignProp(node, prop, value, prev, isSVG, skipRef) {
function assignProp(node, prop, value, prev, isSVG, skipRef, props) {
let isCE, isProp, isChildProp, propAlias, forceProp;
if (prop === "style") return style(node, value, prev);
if (prop === "classList") return classList(node, value, prev);
Expand Down Expand Up @@ -356,7 +356,7 @@ function assignProp(node, prop, value, prev, isSVG, skipRef) {
(isChildProp = ChildProperties.has(prop)) ||
(!isSVG &&
((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop)))) ||
(isCE = node.nodeName.includes("-"))
(isCE = (node.nodeName.includes("-") || 'is' in props))
) {
if (forceProp) {
prop = prop.slice(5);
Expand Down
2 changes: 1 addition & 1 deletion packages/lit-dom-expressions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export function createHTML(r: Runtime, { delegateEvents = true, functionBuilder
topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`
);
const isSVG = r.SVGElements.has(node.name);
const isCE = node.name.includes("-");
const isCE = node.name.includes("-") || node.attrs.some((e) => e.name === "is");
options.hasCustomElement = isCE;
options.isImportNode = (node.name === 'img'||node.name === 'iframe') && node.attrs.some((e) => e.name === "loading" && e.value ==='lazy');

Expand Down

0 comments on commit f9a00f7

Please sign in to comment.