Skip to content

only run render effect for children of non-void <svelte:element> #10884

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

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 16 additions & 1 deletion packages/svelte/src/internal/client/dom/blocks/svelte-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ function swap_block_dom(effect, from, to) {
}
}

let void_elements = new Map();

/**
* @param {Element} element
* @returns {boolean}
*/
function is_void(element) {
if (!void_elements.has(element.nodeName)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hoist nodeName into a var

void_elements.set(element.nodeName, !element.outerHTML.includes('/'));
}

return void_elements.get(element.nodeName);
}

/**
* @param {Comment} anchor
* @param {() => string} get_tag
Expand Down Expand Up @@ -110,7 +124,7 @@ export function element(anchor, get_tag, is_svg, render_fn) {
? document.createElementNS(ns, next_tag)
: document.createElement(next_tag);

if (render_fn) {
if (render_fn && !is_void(element)) {
let anchor;
if (hydrating) {
// Use the existing ssr comment as the anchor so that the inner open and close
Expand All @@ -120,6 +134,7 @@ export function element(anchor, get_tag, is_svg, render_fn) {
anchor = empty();
element.appendChild(anchor);
}

render_fn(element, anchor);
}

Expand Down