DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

Angular NG0502: How to Fix “Hydration Missing Node”

NG0502 means Angular expected a node during hydration and could not find it. Compare server output with the browser DOM, then check DOM mutations, invalid markup, scripts, and whitespace settings.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Angular’s NG0502: Hydration Missing Node means hydration expected a DOM node at a particular location but could not find it. The server-rendered page and the browser DOM no longer match where Angular is trying to reuse the server output. Compare those two DOM states, then check for code or scripts that changed the page, invalid HTML nesting, or inconsistent whitespace settings. Fix the mismatch if possible; skipping hydration is a limited workaround, not a general repair.

What NG0502 means

During hydration, Angular reuses DOM created by server-side rendering rather than building the entire page from scratch. It expects the browser’s DOM structure to match the server-rendered structure. NG0502 reports that an expected node is missing at a particular position. It belongs to the broader family of hydration node mismatch errors; Angular’s NG0502 reference points to NG0500 for additional debugging guidance.

As an Amazon Associate I earn from qualifying purchases.

The error code alone does not identify the missing node, component, template, or script. Finding the cause requires inspecting the affected route’s server output, the DOM when hydration starts, and code that can change that DOM.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to find the mismatch

  1. Reproduce it on the affected route. Note the browser console error and which part of the page appears affected. The NG0502 reference directs developers to NG0500’s debugging information; it does not name the responsible node for your application.
  2. Compare server HTML with the browser DOM at hydration time. Inspect the HTML returned by server-side rendering and the DOM in the browser before Angular hydrates it. Look for nodes, comments, or whitespace that are missing, inserted, or moved. Angular’s hydration guide explains that the server-rendered DOM must not be altered before hydration.
  3. Trace code that manipulates the DOM. Search the affected component and its dependencies for native DOM operations such as document queries, appendChild, node removal or movement, and assignments to innerHTML or outerHTML. These can put the browser DOM in a state Angular does not expect.
  4. Validate the template’s HTML structure. Check whether the browser is correcting invalid markup as it parses it. Angular specifically advises declaring a <tbody> in tables and avoiding a <div> inside a <p>; nested anchors are another invalid structure to check.
  5. Check scripts that run before hydration. A third-party script, including analytics code, may insert, remove, or move nodes before Angular starts. Where feasible, defer page-mutating scripts until after hydration, for example with Angular’s AfterNextRender guidance.
  6. Review whitespace configuration if the structure still differs. Angular recommends the default preserveWhitespaces: false. If whitespace preservation is enabled, keep that setting consistent in server and browser builds. This is one possible contributor, not a diagnosis for every NG0502.

Fix the source of the DOM change

Use Angular rendering patterns instead of native DOM changes

When application code creates or changes content, prefer Angular-supported template and rendering approaches over direct DOM manipulation. This lets Angular keep the rendered structure consistent with the structure it expects to hydrate. Revisit operations such as moving existing nodes or replacing a block through innerHTML; correcting the code that changes the DOM is preferable to suppressing the symptom.

Make the template valid and explicit

Correct invalid nesting so the browser does not silently produce a different tree from the one implied by the template. For tables, include the <tbody> explicitly. Keep block elements such as <div> out of paragraphs, and do not nest anchors.

Delay scripts that mutate the page

If a dependency or third-party script modifies the DOM before Angular hydrates, determine whether it can run later. Angular recommends deferring such work until after hydration where possible; its hydration guide describes using AfterNextRender as an example.

When to use ngSkipHydration

If an incompatible component cannot be refactored immediately, Angular’s ngSkipHydration can be a temporary, narrowly scoped workaround. It must be applied to a component host. Angular skips hydration for that component and its children, destroying and re-rendering that subtree instead of reusing the server-rendered DOM. That can restore operation in the short term, but the subtree loses hydration’s reuse benefits. It does not fix the underlying mismatch, and it should not be placed on arbitrary elements or casually on the root application host. See Angular’s guidance on hydration and ngSkipHydration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose between correction and a temporary workaround

Option Use it when Trade-off
Correct the DOM behavior or markup You can identify and change the code, template, or script that causes the mismatch. Preserves hydration for the component.
Defer a page-mutating script A script changes the DOM before Angular hydrates and can run later. Requires the script’s behavior to remain valid when delayed.
Apply ngSkipHydration to a component host The component cannot be made hydration-compatible immediately. Angular re-renders that component and its descendants instead of hydrating them; this is a workaround, not a mismatch fix.

Prefer the smallest correction that restores a consistent server and browser DOM. The appropriate choice depends on where the mismatch originates and whether its cause can be changed or delayed.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.