fix(agera): queue batch and trigger writes onto a running flush instead of draining it - #256
Merged
Merged
Conversation
…nstead of draining it A `batch` or `trigger` that ended inside a running flush drained the rest of the queue on the caller's stack, while a plain signal write already joined the running flush. Code rendered from a flush that batched a write could then run queued effects in the middle of the render: a deferred scope started before its body finished, and rows created by the same reconcile were never started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #256 +/- ##
==========================================
+ Coverage 83.30% 83.41% +0.11%
==========================================
Files 98 98
Lines 2557 2557
Branches 552 552
==========================================
+ Hits 2130 2133 +3
Misses 314 314
+ Partials 113 110 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A plain signal write inside a running flush joins its queue (
!batchDepth && !flushDepth), butbatchandtriggeronly checkedbatchDepth. When one of them ended inside a flush, it calledflush()again and drained the rest of the queue on the caller's stack.In nanoviews this happens when code rendered from a flush (a swapped
if_/switch_branch, afor_reconcile) callsbatchortrigger, directly or through a library call:show_toggle starts the branch's deferred scope while its body is still running, so effects created before thebatchrun before the tree is built, and the ones after it see a started scope;startRowsearly, and the rows created after it in the same reconcile are never started:for_going from[1]to[1, 2, 3]left the new rows'value$bindings empty.What
batchandtriggerflush only whenbatchDepthdrops to zero outside a running flush. Inside a flush their writes are picked up by the flush that is already running.batch > should queue writes onto the running flush when called inside an effectandtrigger > should queue updates onto the running flush when called inside an effect. Both fail onmain: the queued effects ran before the effect that calledbatch/triggerfinished.Size
No limit changes. agera, measured with
size-limitagainst the rebuilt dist:size-limitpasses in every package that has it, and every limit still equals its size rounded up to 0.05 kB.Checks
oxlint,tsc --noEmitandvitest runpass inpackages/agera(183 tests).vitest runpasses in kida, store, query, router, intl, ssr, react, preact, svelte, react-router, preact-router, svelte-router, next-router, svelte-kit, react-ssr, preact-ssr, svelte-ssr and platform-web.internals/effects.spec.ts"should stop rows when the branch is hidden during rows start", which pins the old immediate teardown throughbatch(() => $show(false))inside a row effect. It has to be updated when nanoviews picks up this version.