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: handle sole empty expression tags #10433

Merged
merged 4 commits into from
Feb 9, 2024
Merged

Conversation

dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Feb 8, 2024

When there's only a single expression tag and its value evaluates to the empty string, special handling is needed to create and insert a text node
fixes #10426

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

  • 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.

Tests and linting

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

When there's only a single expression tag and its value evaluates to the empty string, special handling is needed to create and insert a text node
fixes #10426
Copy link

changeset-bot bot commented Feb 8, 2024

🦋 Changeset detected

Latest commit: 4ef53cf

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
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

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

one tiny detail but otherwise LGTM

current_hydration_fragment.unshift(text);
if (first_node) {
/** @type {DocumentFragment} */ (first_node.parentNode).insertBefore(text, first_node);
}
return text;
}

if (first_node !== null) {
if (first_node) {
Copy link
Member

Choose a reason for hiding this comment

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

I believe the explicit comparison is deliberate, since it results in more efficient bytecode

Suggested change
if (first_node) {
if (first_node !== null) {

Copy link
Member Author

@dummdidumm dummdidumm Feb 9, 2024

Choose a reason for hiding this comment

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

I did change it because the comparison will be wrongfully false when first_node is undefined when the array is empty.

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: Displaying component-bound prop causes ERR_SVELTE_HYDRATION_MISMATCH
2 participants