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

chore: add missing test for #13158 #13255

Merged
merged 1 commit into from
Sep 16, 2024
Merged

chore: add missing test for #13158 #13255

merged 1 commit into from
Sep 16, 2024

Conversation

Rich-Harris
Copy link
Member

Adds a test for #13158. I maintain that we should probably just fix the HTML rather than issuing a slightly cryptic message (why would we say a valid parent element if we know which parent element it should be, and if we know that why don't we just insert it?), but that work can happen separately.

Another thought: the list of elements...

switch (tag) {
case 'body':
case 'caption':
case 'col':
case 'colgroup':
case 'frameset':
case 'frame':
case 'head':
case 'html':
case 'tbody':
case 'td':
case 'tfoot':
case 'th':
case 'thead':
case 'tr':
// These tags are only valid with a few parents that have special child
// parsing rules - if we're down here, then none of those matched and
// so we allow it only if we don't know what the parent is, as all other
// cases are invalid (and we only get into this function if we know the parent).
return false;
}
...includes things like <html>. Does that preclude valid use cases, like defining a document (only a subtree of which gets hydrated) in a .svelte file?

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

Copy link

changeset-bot bot commented Sep 15, 2024

⚠️ No Changeset found

Latest commit: de83171

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@dummdidumm
Copy link
Member

Does that preclude valid use cases, like defining a document (only a subtree of which gets hydrated) in a .svelte file?

Not 100% sure what you mean by that; but: you only ever reach that block during SSR (during static analysis the parent tag is always set). Therefore the only time you can run into this is if you have a Svelte component like <tr>..</tr> that hydrates inside a table (which isn't part of what Svelte sees) - and why would you ever do that? So we can either be a bit too strict and keep this logic, or trust people to know what they're doing in this edge case and remove that switch statement - I'm ok with both variants.

@Rich-Harris Rich-Harris merged commit 355730c into main Sep 16, 2024
9 checks passed
@Rich-Harris Rich-Harris deleted the test-for-13158 branch September 16, 2024 12:08
dummdidumm added a commit that referenced this pull request Nov 26, 2024
This reverts #13255 / #13158, and helps with the validation error part of #14120

The revert is justified because people should be free to render a component in isolation and then append it somewhere where they know the rendered output is valid. If someone renders a tag at the top level that is invalid without a certain parent (which itself is an edge case), then the likelihood that this is done on purpose is much higher than that it's done by accident.
dummdidumm added a commit that referenced this pull request Nov 26, 2024
This reverts #13255 / #13158, and helps with the validation error part of #14120

If you would have a component like this...
```svelte
<td>hi there</td>
```
...and then render it on the server via our `render` function like this:
```js
const result = render(Main);
```
...then right now you get an error saying that `td` is not valid at this position. But that doesn't seem right, because we should give people the benefit of the doubt: It may very well be that someone renders such a component and then correctly puts it into a `tr` tag themselves on the server (another example is rendering a full html document like in #14120).

All the other validation where there's a known parent (X not valid inside Y) is untouched by this.

Doing this as cleanup prior to tackling #13331
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