Model Angular @defer blocks: triggers, prefetch, placeholder minimum and loading after and minimum
Problem
Angular 17's @defer block splits a part of a template into its own chunk and loads it only when a trigger fires. Its sub-blocks control what the user sees meanwhile: @placeholder (minimum 500ms), @loading (after 100ms; minimum 1s) and @error. The timing rules exist to stop flicker, and they are easy to get subtly wrong. Build a model of one @defer block that follows Angular's rules.
const block = createDeferBlock({
env,
loadDependencies: () => import("./chart.js"),
on: [{ type: "interaction" }],
prefetch: [{ type: "idle" }],
placeholder: { minimum: 500 },
loading: { after: 100, minimum: 1000 },
});
// t=0 placeholder. Idle: the chunk starts loading. Click: if it already loaded, the chart shows at once
// (after the placeholder's 500 ms); otherwise loading may appear after 100 ms and then stays at least 1 s.Ref. UR-1456 · © UIRound · uiround.com/questions/model-angular-defer-blocks-triggers-prefetch-placeholder-minimum-and-loading-after-and-minimum
Unlock this question
The full problem, its tests and the tested solution are part of Pro.
- 3
- code listings
- 8
- edge cases
- 5
- follow-up questions
What's inside
- The full problem, with examples
- Tests that check your solution
- Step-by-step
- Approach
- Solution
- Complexity
- Edge cases
- Follow-up questions
- Card worldwide
- UPI and net banking in India
- One-time payment, nothing renews
Stuck? Take a hint
- 1Keep two separate things: the dependency loading status (not started, in progress, complete, failed) and the rendered block (placeholder, loading, complete, error). Prefetch only touches the first; the main trigger moves both.
Try it in the editor
Run your code as often as you like. Submitting it to the full test suite is part of Pro.
Private, and saved in this browser as you type. All your notes are on My lists.