Skip to content

Commit 27b090b

Browse files
effect-botagcty
andauthored
Record empty, watcher, and per-render causedBy on MessageLog.FetchStarted (#11268)
Co-authored-by: Alex <12101091+agcty@users.noreply.github.com>
1 parent aa0be5a commit 27b090b

15 files changed

Lines changed: 395 additions & 60 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": patch
3+
---
4+
5+
`effect/ui/MessageLog` now shows whether a fetch started without a cached success (`empty`) and which component's watch or `$.loadMore` started it (`watcher`). Watch fetches retain their render's `causedBy` when updates are batched.

‎ai-docs/src/90_ui/10_testing/95_timeline.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,20 @@ describe("App timeline", () => {
7373
assert.isUndefined(replay.divergence)
7474
assert.strictEqual(replay.model.saved, "Oat milk")
7575
}))
76+
77+
// Initial-render watch fetches have `causedBy === log[0].seq` (SessionStarted).
78+
// Check other cold watch fetches against the page's expected dependent reads;
79+
// `watcher` identifies the component, but the log cannot prove a dependency.
80+
// After Router.prefetch, check the navigation's log for cold watch fetches
81+
// to find reads that still started without a cached success.
82+
it.effect("starts no cold watch fetch behind another query on initial load", () =>
83+
Effect.gen(function*() {
84+
const { log } = yield* session("queued")
85+
const start = log[0]!.seq
86+
const late = log.filter((entry) =>
87+
entry._tag === "FetchStarted" && entry.trigger === "watch" &&
88+
entry.empty && entry.causedBy !== start
89+
)
90+
assert.deepStrictEqual(late, [])
91+
}))
7692
})

‎packages/effect/src/ui/MessageLog.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,10 @@ export interface SessionStarted extends Base {
875875
* `restart` marks a fetch that replaced an interrupted one, under the same
876876
* trigger. `inWindow` marks a fetch of a hydrated entry while the
877877
* fetch-free window is open. `stored: false` marks a fetcher call whose
878-
* result goes to `get` callers only. A caller that joins a fetch in flight
879-
* logs nothing.
878+
* result goes to `get` callers only. `empty` is true when the entry held no
879+
* current or previous `Success` when the fetch started. `watcher` is the path
880+
* of the instance whose watch or `$.loadMore` started the fetch. A caller that
881+
* joins a fetch in flight logs nothing.
880882
*
881883
* An infinite query logs each page it requests as its own entry: `page` is the
882884
* page's index, from 0, and `cursor` the cursor encoded by the list's
@@ -895,6 +897,8 @@ export interface FetchStarted extends Base {
895897
readonly restart: boolean
896898
readonly inWindow: boolean
897899
readonly stored: boolean
900+
readonly empty: boolean
901+
readonly watcher?: string
898902
readonly page?: number
899903
readonly cursor?: Schema.Json
900904
/** The parent span's trace id, absent when the fetch starts its own trace. */
@@ -1063,7 +1067,7 @@ export const fanout = <
10631067
* @category Wire
10641068
* @since 4.2.0
10651069
*/
1066-
export const wireVersion = 1
1070+
export const wireVersion = 2
10671071

10681072
/**
10691073
* Where a log comes from, as `Hello` reports it.
@@ -1213,6 +1217,8 @@ export const Wire = Schema.Union([
12131217
restart: Schema.Boolean,
12141218
inWindow: Schema.Boolean,
12151219
stored: Schema.Boolean,
1220+
empty: Schema.optionalKey(Schema.Boolean),
1221+
watcher: Schema.optionalKey(Schema.String),
12161222
page: Schema.optionalKey(Schema.Number),
12171223
cursor: Schema.optionalKey(Schema.Json),
12181224
traceId: Schema.optionalKey(Schema.String),
@@ -1580,6 +1586,10 @@ export const makeEncoder = (options?: {
15801586
restart: entry.restart,
15811587
inWindow: entry.inWindow,
15821588
stored: entry.stored,
1589+
empty: entry.empty,
1590+
...(entry.watcher === undefined
1591+
? undefined
1592+
: { watcher: entry.watcher }),
15831593
...(entry.page === undefined ? undefined : { page: entry.page }),
15841594
...(entry.cursor === undefined
15851595
? undefined

0 commit comments

Comments
 (0)