MCPcopy Create free account
hub / github.com/angular/angular / verifySsrContentsIntegrity

Function verifySsrContentsIntegrity

packages/core/src/hydration/utils.ts:777–811  ·  view source on GitHub ↗
(doc: Document)

Source from the content-addressed store, hash-verified

775 * Note: this function is invoked only on the client, so it's safe to use DOM APIs.
776 */
777export function verifySsrContentsIntegrity(doc: Document): void {
778 for (const node of doc.body.childNodes) {
779 if (isSsrContentsIntegrity(node)) {
780 return;
781 }
782 }
783
784 // Check if the HTML parser may have moved the marker to just before the <body> tag,
785 // e.g. because the body tag was implicit and not present in the markup. An implicit body
786 // tag is unlikely to interfer with whitespace/comments inside of the app's root element.
787
788 // Case 1: Implicit body. Example:
789 // <!doctype html><head><title>Hi</title></head><!--nghm--><app-root></app-root>
790 const beforeBody = skipTextNodes(doc.body.previousSibling);
791 if (isSsrContentsIntegrity(beforeBody)) {
792 return;
793 }
794
795 // Case 2: Implicit body & head. Example:
796 // <!doctype html><head><title>Hi</title><!--nghm--><app-root></app-root>
797 let endOfHead = skipTextNodes(doc.head.lastChild);
798 if (isSsrContentsIntegrity(endOfHead)) {
799 return;
800 }
801
802 throw new RuntimeError(
803 RuntimeErrorCode.MISSING_SSR_CONTENT_INTEGRITY_MARKER,
804 typeof ngDevMode !== 'undefined' &&
805 ngDevMode &&
806 'Angular hydration logic detected that HTML content of this page was modified after it ' +
807 'was produced during server side rendering. Make sure that there are no optimizations ' +
808 'that remove comment nodes from HTML enabled on your CDN. Angular hydration ' +
809 'relies on HTML produced by the server, including whitespaces and comment nodes.',
810 );
811}

Callers 2

marker_spec.tsFile · 0.90
withDomHydrationFunction · 0.90

Calls 2

isSsrContentsIntegrityFunction · 0.85
skipTextNodesFunction · 0.85

Tested by

no test coverage detected