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

Function getParentRElement

packages/core/src/render3/node_manipulation.ts:491–516  ·  view source on GitHub ↗
(
  tView: TView,
  tNode: TNode | null,
  lView: LView,
)

Source from the content-addressed store, hash-verified

489 * @param lView: Current `LView`.
490 */
491export function getParentRElement(
492 tView: TView,
493 tNode: TNode | null,
494 lView: LView,
495): RElement | null {
496 // `tNode` can genuinely be null here, not just as a defensive type-widening measure. An
497 // `@if`/`@switch` branch's content is its own embedded view with its own `TView`, built the
498 // first time that branch is rendered. If an error interrupts that first creation pass (for
499 // example, a hydration mismatch on one of the branch's later nodes, after an earlier node's
500 // `TNode` was already created), `TView.firstCreatePass` still gets flipped to `false` before
501 // the error propagates (see `renderView()`'s `catch` block in `instructions/render.ts`),
502 // permanently marking the view's `TNode` data as "already created" even though it isn't.
503 // Unlike a component's `TView`, nothing rebuilds an embedded view's `TView` afterward, so the
504 // next time that same branch is selected, its instructions read directly from the still-null
505 // slot in `tView.data` instead of creating a fresh `TNode` — which is what surfaces here.
506 // Guard against it so production throws a coded RuntimeError instead of a raw TypeError when
507 // dereferencing `tNode.parent` below.
508 if (tNode === null) {
509 throw new RuntimeError(
510 RuntimeErrorCode.PARENT_NODE_NOT_FOUND,
511 ngDevMode &&
512 'getParentRElement() was called with a null TNode, so no parent element could be resolved. This usually means a TNode was never created for this node, or was already destroyed.',
513 );
514 }
515 return getClosestRElement(tView, tNode.parent, lView);
516}
517
518/**
519 * Get closest `RElement` or `null` if it can't be found.

Callers 3

describeExpectedDomFunction · 0.90
appendChildFunction · 0.85
applyProjectionFunction · 0.85

Calls 1

getClosestRElementFunction · 0.85

Tested by

no test coverage detected