Skip to content

Hydration: detect when index.html is altered between the server and the client #51160

Closed

Description

@AndrewKushnir

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

The non-destructive hydration expects the DOM tree to have the same structure in both places. This also includes whitespaces and comment nodes that Angular produces during the rendering on the server. Those whitespaces and nodes must be present in the HTML generated by the server-side rendering process. This is also documented at: https://angular.io/guide/hydration#constraints.

In practice, some CDNs (example) have mechanisms to remove all comment nodes and spaces from all text nodes from HTML while serving the content (there are also cases where this type of optimization is performed at the build step). Those mechanisms are frequently enabled by default. This leads to situations where an application worked in dev mode correctly, but started failing in production. Since the production code is also minified, it makes it hard to look at the stack trace and identify the origin of the problem.

This feature requests proposes that we add a special detection mechanism for such cases. For example, we can do the following:

  • on the server, while serializing DOM, add a comment node to a well known location (e.g. as a first node in the <body>)
  • on the client (both in dev and prod modes), before starting hydration process, verify the presence of those "marker" nodes and throw an error if they are not present
  • we should also add an error guide for this error, so that the link to the guide is present in production mode

One of the examples where this issue becomes a hard-to-debug problem: #50133 (comment)

Activity

  1. added
    featureLabel used to distinguish feature request from other issues
    area: coreIssues related to the framework runtime
    feature: in backlogFeature request for which voting has completed and is now in the backlog
    on Jul 24, 2023
  2. modified the milestone: Backlog on Jul 24, 2023
  3. alxhub commented on Jul 25, 2023

    @alxhub
    Member

    Clever! I like it.

  4. self-assigned this
    on Jul 25, 2023
  5. angular-automatic-lock-bot commented on Sep 4, 2023

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  6. locked and limited conversation to collaborators on Sep 4, 2023
  7. added a commit that references this issue on Jan 23, 2024
    c926292
  8. added a commit that references this issue on Jan 31, 2024
    0a38dc3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: coreIssues related to the framework runtimecore: hydrationfeatureLabel used to distinguish feature request from other issuesfeature: in backlogFeature request for which voting has completed and is now in the backlog

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions