MCPcopy Create free account
hub / github.com/angular/angular / ɵɵdeferHydrateWhen

Function ɵɵdeferHydrateWhen

packages/core/src/defer/instructions.ts:300–340  ·  view source on GitHub ↗
(rawValue: unknown)

Source from the content-addressed store, hash-verified

298 * @codeGenApi
299 */
300export function ɵɵdeferHydrateWhen(rawValue: unknown) {
301 const lView = getLView();
302 const tNode = getSelectedTNode();
303
304 if (ngDevMode) {
305 trackTriggerForDebugging(lView[TVIEW], tNode, 'hydrate when <expression>');
306 }
307
308 if (!shouldAttachTrigger(TriggerType.Hydrate, lView, tNode)) return;
309
310 // TODO(incremental-hydration): audit all defer instructions to reduce unnecessary work by
311 // moving function calls inside their relevant control flow blocks
312 const bindingIndex = nextBindingIndex();
313 const tView = getTView();
314 const hydrateTriggers = getHydrateTriggers(tView, tNode);
315 hydrateTriggers.set(DeferBlockTrigger.When, null);
316
317 if (bindingUpdated(lView, bindingIndex, rawValue)) {
318 if (typeof ngServerMode !== 'undefined' && ngServerMode) {
319 // We are on the server and SSR for defer blocks is enabled.
320 triggerDeferBlock(TriggerType.Hydrate, lView, tNode);
321 } else {
322 const injector = lView[INJECTOR];
323 const prevConsumer = setActiveConsumer(null);
324 try {
325 const value = Boolean(rawValue); // handle truthy or falsy values
326 if (value === true) {
327 // The `when` condition has changed to `true`, trigger defer block loading
328 // if the block is either in initial (nothing is rendered) or a placeholder
329 // state.
330 const lDetails = getLDeferBlockDetails(lView, tNode);
331 const ssrUniqueId = lDetails[SSR_UNIQUE_ID]!;
332 ngDevMode && assertSsrIdDefined(ssrUniqueId);
333 triggerHydrationFromBlockName(injector, ssrUniqueId);
334 }
335 } finally {
336 setActiveConsumer(prevConsumer);
337 }
338 }
339 }
340}
341
342/**
343 * Specifies that hydration never occurs.

Callers

nothing calls this directly

Calls 14

getLViewFunction · 0.90
getSelectedTNodeFunction · 0.90
trackTriggerForDebuggingFunction · 0.90
shouldAttachTriggerFunction · 0.90
nextBindingIndexFunction · 0.90
getTViewFunction · 0.90
getHydrateTriggersFunction · 0.90
bindingUpdatedFunction · 0.90
triggerDeferBlockFunction · 0.90
setActiveConsumerFunction · 0.90
getLDeferBlockDetailsFunction · 0.90
assertSsrIdDefinedFunction · 0.90

Tested by

no test coverage detected