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

Function renderDeferBlockState

packages/core/src/defer/rendering.ts:166–236  ·  view source on GitHub ↗
(
  newState: DeferBlockState,
  tNode: TNode,
  lContainer: LContainer,
  skipTimerScheduling = false,
)

Source from the content-addressed store, hash-verified

164 * between states via `DeferFixture.render` method.
165 */
166export function renderDeferBlockState(
167 newState: DeferBlockState,
168 tNode: TNode,
169 lContainer: LContainer,
170 skipTimerScheduling = false,
171): void {
172 const hostLView = lContainer[PARENT];
173 const hostTView = hostLView[TVIEW];
174
175 // Check if this view is not destroyed. Since the loading process was async,
176 // the view might end up being destroyed by the time rendering happens.
177 if (isDestroyed(hostLView)) return;
178
179 // Make sure this TNode belongs to TView that represents host LView.
180 ngDevMode && assertTNodeForLView(tNode, hostLView);
181
182 const lDetails = getLDeferBlockDetails(hostLView, tNode);
183
184 ngDevMode && assertDefined(lDetails, 'Expected a defer block state defined');
185
186 const currentState = lDetails[DEFER_BLOCK_STATE];
187
188 const ssrState = lDetails[SSR_BLOCK_STATE];
189 if (ssrState !== null && newState < ssrState) {
190 return; // trying to render a previous state, exit
191 }
192
193 if (
194 isValidStateChange(currentState, newState) &&
195 isValidStateChange(lDetails[NEXT_DEFER_BLOCK_STATE] ?? -1, newState)
196 ) {
197 const tDetails = getTDeferBlockDetails(hostTView, tNode);
198 // Skips scheduling on the server since it can delay the server response.
199 const needsScheduling =
200 !skipTimerScheduling &&
201 (typeof ngServerMode === 'undefined' || !ngServerMode) &&
202 (getLoadingBlockAfter(tDetails) !== null ||
203 getMinimumDurationForState(tDetails, DeferBlockState.Loading) !== null ||
204 getMinimumDurationForState(tDetails, DeferBlockState.Placeholder));
205
206 if (ngDevMode && needsScheduling) {
207 assertDefined(
208 applyDeferBlockStateWithSchedulingImpl,
209 'Expected scheduling function to be defined',
210 );
211 }
212
213 const applyStateFn = needsScheduling
214 ? applyDeferBlockStateWithSchedulingImpl!
215 : applyDeferBlockState;
216 try {
217 applyStateFn(newState, lDetails, lContainer, tNode, hostLView);
218 } catch (error: unknown) {
219 // If we are executing synchronously inside `hostLView`'s creation or refresh pass
220 // (e.g. `@placeholder`, `@loading`, `when`, or an already-loaded `@defer` block),
221 // rethrow so `renderView`/`refreshView` aborts immediately and lets enclosing
222 // error boundaries handle it like any other template error.
223 if (getLView() === hostLView) {

Callers 5

triggerDeferBlockFunction · 0.90
callbackFunction · 0.85
renderPlaceholderFunction · 0.85
renderMethod · 0.85

Calls 11

isDestroyedFunction · 0.90
assertTNodeForLViewFunction · 0.90
getLDeferBlockDetailsFunction · 0.90
assertDefinedFunction · 0.90
getTDeferBlockDetailsFunction · 0.90
getLoadingBlockAfterFunction · 0.90
getLViewFunction · 0.90
handleViewErrorFunction · 0.90
handleUncaughtErrorFunction · 0.90
isValidStateChangeFunction · 0.85

Tested by

no test coverage detected