mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
c6e4a36be1
locateOrCreateElementNodeImpl looks up the DOM node for an element during hydration and immediately checks its nodeType. If the client-rendered DOM has fewer nodes than the server-rendered HTML, the lookup returns null, and in production that null flows straight into the nodeType check and crashes with a raw, uncoded "Cannot read properties of null (reading 'nodeType')" TypeError. The dev-mode check that would normally catch this (validateMatchingNode) already handles a missing node, but it's compiled out of production builds, so the crash only shows up outside of dev mode. Add a null check ahead of the nodeType check that throws a coded RuntimeError using the existing HYDRATION_MISSING_NODE (NG0502) code, with a descriptive message in dev mode and a cheap fallback in production. Also add a regression test that removes a server-rendered element before hydration runs and asserts a coded RuntimeError is thrown instead of a raw TypeError.