Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follow-up to #11947. Right now our HTML validation (for checking which elements are allowed inside which other elements) isn't great — we have special handling for
<p>
(why?) and interactive elements, and #11947 added some logic for preventing<form><form></form></form>
that doesn't prevent<form><Form></Form></form>
.This PR is a naive attempt to fix it by having a single place to define disallowed children/parents that can be used in multiple places (parsing, validation, SSR) rather than having a bunch of special-case logic. Unfortunately it doesn't quite work, because it prevents children from having certain descendant elements, when the required logic is a bit more subtle. For example one test fails because an
<li>
has a valid descendant (not child)<li>
. Examples of nuances that aren't captured by our current validation or this PR:<ul>
and<ol>
can only contain<li>
,<script>
or<template>
— we don't have the concept of an allowlist of direct children<li>
must be a direct child of<ul>
or<ol>
or<menu>
— we don't have the concept of an allowlist of direct parents<table>
can contain<tr>
directly — the intermediate<tbody>
is automatically created if absent. we only insist on it because we're not sophisticated enough to handle the resulting hydration complexities<p>
inside<p>
) result in broken DOM, others (<h1>
inside<dd>
) are invalid but do not result in broken DOMI also wonder if an error is appropriate. In one app I converted to Svelte 5, I hit an error immediately because a
<button>
contained another<button>
— this is incorrect, but the app had been working just fine. For people who aren't using SSR, this case is a potential accessibility pitfall but it won't result in a hydration mismatch, and so maybe a warning is actually more appropriate?Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint