Skip to content

[fix] hydrate correct elements when using @html #6946

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

Merged
merged 1 commit into from
Jan 9, 2022
Merged

[fix] hydrate correct elements when using @html #6946

merged 1 commit into from
Jan 9, 2022

Conversation

baseballyama
Copy link
Member

@baseballyama baseballyama commented Nov 20, 2021

fixes #7115

After executing this line from Kit, nodes contains (maybe unexpected) #text node at the top and end.

const nodes = children(options.target);

In this case, start_index is more than 0 (mostly 1).
And the second argument of splice is delete_count.
Therefore it will splice more than expected.

const html_tag_nodes = nodes.splice(start_index, end_index + 1);

If start_index is possibly more than 0, I think it should be modified to look like this PR.

On the other hand, should we prevent containing unexpected #text nodes at the top and end?
I think we can not control it because a template file containing %svelte.body% can be freely created by a user.


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

  • Run the tests with npm test and lint the project with npm run lint

@benmccann
Copy link
Member

@hbirler you may be interested in reviewing this hydration fix

@baseballyama
Copy link
Member Author

@tanhauhau

I'm sorry for mentioning it.
But could you please review this PR?
This is just 1 line fix.
And the last committer is you, so I believe you can review it in less time.

@hbirler
Copy link
Contributor

hbirler commented Jan 9, 2022

Hi, sorry I did not notice my mention earlier, the fix seems good to me as well.

@benmccann benmccann changed the title [fix] fix @html Hydration with SSR (kit-2806) [fix] hydrate correct elements when using @html Jan 9, 2022
@benmccann benmccann merged commit 895b4c6 into sveltejs:master Jan 9, 2022
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.

Bug with SSR and Hydration (Probably Caused by @html)
4 participants