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: use importNode to clone templates for Firefox #15272

Merged
merged 3 commits into from
Feb 12, 2025

Conversation

paoloricciuti
Copy link
Member

@paoloricciuti paoloricciuti commented Feb 11, 2025

Before submitting the PR, please make sure you do the following

Closes #15268

Follow up to #15141 ...we now use importNode in FF (which based on some test i did in that PR seems to actually be faster in FF) and cloneNode in the rest...this also mean we don't have to do the trick we did for handle_lazy_img because it was only an issue in FF.

Not sure how to add a test for this.

Also do we have a way to be sure it's not messing with performance in FF?

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Feb 11, 2025

🦋 Changeset detected

Latest commit: 200bb4c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@15272

@@ -48,7 +48,7 @@ export function template(content, flags) {
}

var clone = /** @type {TemplateNode} */ (
use_import_node ? document.importNode(node, true) : node.cloneNode(true)
use_import_node || is_firefox ? document.importNode(node, true) : node.cloneNode(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be on line 28 instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Uh yeah it might be better

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually this might be too soon. Is is_firefox true at this point?

Copy link
Member Author

Choose a reason for hiding this comment

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

Uh you are right... it's initialized in init_operations so it might be too soon indeed. I need to check the other usage too

@sukeshpabolu
Copy link

I saw that importNode is supported in all browsers; https://developer.mozilla.org/en-US/docs/Web/API/Document/importNode

@trueadm
Copy link
Contributor

trueadm commented Feb 12, 2025

I saw that importNode is supported in all browsers; https://developer.mozilla.org/en-US/docs/Web/API/Document/importNode

It is, but it's also much slower in Chrome than cloneNode. https://issues.chromium.org/issues/371247940

@sukeshpabolu
Copy link

understood. thanks.

@paoloricciuti paoloricciuti merged commit 1848138 into main Feb 12, 2025
10 checks passed
@paoloricciuti paoloricciuti deleted the import-node-on-ff branch February 12, 2025 13:05
@github-actions github-actions bot mentioned this pull request Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

svelte 5 <img loading="lazy" srcset="..."> loads eagerly
3 participants