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: stringify attribute values before comparison #9475

Merged
merged 2 commits into from
Nov 15, 2023
Merged

Conversation

Rich-Harris
Copy link
Member

This is one of two possible solutions to the following problem: when hydrating, we check to see if value is identical to the value of getAttribute(name), but value might not be a string. As a result, in cases like this...

<div aria-current={some_boolean}>

...we unnecessarily call setAttribute. Worse (and unrelated to hydration), calling setAttribute with a non-string value causes an inexplicable slowdown.

The alternative fix is to coerce values before the attr function is called. Doing so would result in fewer typeof checks (since in some cases we already know the attribute is a string), but would result in larger output.

Copy link

changeset-bot bot commented Nov 15, 2023

🦋 Changeset detected

Latest commit: 69df3a0

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

Copy link

vercel bot commented Nov 15, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
svelte-5-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 15, 2023 7:52pm

@Rich-Harris Rich-Harris merged commit e3e1fef into main Nov 15, 2023
@Rich-Harris Rich-Harris deleted the coerce-attributes branch November 15, 2023 20:19
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.

2 participants