NG.II · Angular 22 practice question

A developer is implementing a custom DOM manipulation routine that requires reading the current element dimensions immediately before applying a calculated style change. To ensure the most efficient execution order and avoid layout thrashing, which phase of `afterRenderEffect` should be utilized for this operation?

afterRenderEffect({ 
  earlyRead: () => { /* ... */ }, 
  write: () => { /* ... */ }, 
  mixedReadWrite: () => { /* ... */ }, 
  read: () => { /* ... */ } 
});
Choose one answer
Check answer and explanation

Correct answer: The `earlyRead` phase, as it allows reading the DOM before subsequent write callbacks.

Explanation

The `earlyRead` phase is explicitly designed for reading from the DOM before a subsequent write callback, which matches the requirement for reading dimensions before applying a style change.

Common trap

The `mixedReadWrite` phase is tempting because it allows both reading and writing, but the documentation warns against using it if the work can be separated for optimization. The `read` phase is incorrect because it explicitly forbids writing to the DOM.

Source: Angular docs: Effects — Render phases
Checked against the cited text on 2026-11-25.

Report an error in this question