Skip to content

feat(no-nested-tags): deny nesting a and p tags #2398

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sod
Copy link

@sod sod commented Apr 28, 2025

What

Shows this lint error on nested a or p tags:
CleanShot 2025-04-28 at 16 13 59@2x

Why

If a browser encounters nested a or p tags, it'll de-nest them. It's possible via appendChild though - so if you use angular without Ssr, this won't apply to you.

With the addition of https://angular.dev/guide/incremental-hydration for Ssr this is a problem though. If you have a component that creates:

[<a>{<a>()</a>}</a>]

Then Ssr will send:

[<a>{</a><a>()</a>}]

Which is a DOM mismatch and incremental-hydration will throw an error:

ERROR RuntimeError: NG0500: During hydration Angular expected but the node was not found.

and not successfully bootstrap.

This lint rule tries to prevent this. Of course not across components, but at least if it happens inside a single template.

related: angular/angular#51399

You can observe this behavior also if you try to throw this into a page via the dev toolbar:

CleanShot.2025-04-28.at.16.09.23-converted.mp4

If give a browser nested a or p tags, it'll de-nest them. It's possible via `appendChild` though. So if you never used Ssr and use angular only browser you may never notices.

But now with the addition of https://angular.dev/guide/incremental-hydration this is a problem. If you have a component that creates:

`<a>  <div>  <a>inner</a>  </div>  </a>`

Then Ssr will send:

`<a>  </a><div><a>  </a><a>inner</a>  </div>`

Whis is a DOM mismatch and incremental-hydration will throw an error and not successfully bootstrap.

This lint rule tries to prevent this. Of course not across components, but at least if it happens inside a single template.

related: angular/angular#51399
@sod
Copy link
Author

sod commented Apr 29, 2025

Here a reproduction for what I mean https://github.com/sod/issue-ssr-reproduction-2398

CleanShot 2025-04-29 at 13 42 08@2x

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.

1 participant