/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * The name of an attribute that can be added to the hydration boundary node * (component host node) to disable hydration for the content within that boundary. */ export const SKIP_HYDRATION_ATTR_NAME = 'ngSkipHydration'; /** * Helper function to check if a given TNode has the 'ngSkipHydration' attribute. */ export function hasSkipHydrationAttrOnTNode(tNode) { const SKIP_HYDRATION_ATTR_NAME_LOWER_CASE = SKIP_HYDRATION_ATTR_NAME.toLowerCase(); const attrs = tNode.mergedAttrs; if (attrs === null) return false; // only ever look at the attribute name and skip the values for (let i = 0; i < attrs.length; i += 2) { const value = attrs[i]; // This is a marker, which means that the static attributes section is over, // so we can exit early. if (typeof value === 'number') return false; if (typeof value === 'string' && value.toLowerCase() === SKIP_HYDRATION_ATTR_NAME_LOWER_CASE) { return true; } } return false; } /** * Helper function to check if a given RElement has the 'ngSkipHydration' attribute. */ export function hasSkipHydrationAttrOnRElement(rNode) { return rNode.hasAttribute(SKIP_HYDRATION_ATTR_NAME); } /** * Checks whether a TNode has a flag to indicate that it's a part of * a skip hydration block. */ export function hasInSkipHydrationBlockFlag(tNode) { return (tNode.flags & 128 /* TNodeFlags.inSkipHydrationBlock */) === 128 /* TNodeFlags.inSkipHydrationBlock */; } /** * Helper function that determines if a given node is within a skip hydration block * by navigating up the TNode tree to see if any parent nodes have skip hydration * attribute. * * TODO(akushnir): this function should contain the logic of `hasInSkipHydrationBlockFlag`, * there is no need to traverse parent nodes when we have a TNode flag (which would also * make this lookup O(1)). */ export function isInSkipHydrationBlock(tNode) { let currentTNode = tNode.parent; while (currentTNode) { if (hasSkipHydrationAttrOnTNode(currentTNode)) { return true; } currentTNode = currentTNode.parent; } return false; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2tpcF9oeWRyYXRpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9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