You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 694b1e8
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: packages/rangojs-router/docs/internal/rendered-barrier.md
+58-28Lines changed: 58 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,21 +2,30 @@
2
2
3
3
**Status**: Experimental. Works in DSL loaders, including streaming trees that use `loading()` (the barrier waits for the streaming handlers to settle).
4
4
5
-
## Problem
5
+
If you're about to touch how loaders read handle data — or you just hit
6
+
`ctx.rendered()` in a loader and want to know what it actually promises —
7
+
start here. This is a small feature with a sharp edge, and the edge is exactly
8
+
where the scar tissue lives.
6
9
7
-
Loaders run before handlers. A loader that needs to know which data the
8
-
handler tree produced (e.g., which product IDs were rendered) must either
9
-
duplicate the fetch or create a loader-to-loader waterfall.
10
+
## The problem it solves
10
11
11
-
Handles accumulate data from handlers/layouts for downstream consumption,
12
-
but loaders cannot read handles because handles are populated after loaders
13
-
start.
12
+
Loaders run before handlers. That ordering is fine until a loader needs to know
13
+
what the handler tree produced — say, which product IDs ended up rendered. With
14
+
nothing to lean on, that loader has two bad options: duplicate the fetch the
15
+
handler already did, or chain itself behind another loader and create a
16
+
loader-to-loader waterfall. Neither is something you want to write twice.
14
17
15
-
## Solution
18
+
Handles look like the natural answer — they exist precisely to accumulate data
19
+
from handlers and layouts for downstream consumption. But there's a timing
20
+
mismatch: handles are populated _after_ loaders start, so a loader that reads a
21
+
handle reads it empty. The data it wants hasn't been written yet.
16
22
17
-
Add `await ctx.rendered()` to loader context. After the promise resolves,
18
-
the non-loader render tree has settled and all handle data is available.
19
-
The loader can then read handles via `ctx.use(handle)`.
23
+
## The fix
24
+
25
+
Give the loader a way to wait. `await ctx.rendered()` is that wait: once the
26
+
promise resolves, the non-loader render tree has settled and all handle data is
27
+
in place. From there the loader can read handles via `ctx.use(handle)` and get
0 commit comments