Skip to content

fix(loops): each/filter reacts to outer-scope dependencies (#335) - #336

Merged
ErickXavier merged 1 commit into
mainfrom
fix/each-filter-outer-deps
Aug 14, 2026
Merged

fix(loops): each/filter reacts to outer-scope dependencies (#335)#336
ErickXavier merged 1 commit into
mainfrom
fix/each-filter-outer-deps

Conversation

@ErickXavier

Copy link
Copy Markdown
Collaborator

Fixes #335. A loop's filter/sort expression referencing an outer-scope state variable now re-evaluates when that variable changes.

Root cause (two parts, src/directives/loops.js):

  1. The loop's update watcher was key-scoped to the list path root keys only, so _notifyMeta skipped it when an outer-scope var (e.g. showActive, a model-bound query) changed.
  2. The same-reference optimization (list === prevList) returned early before the filter could re-run, since the source array reference is unchanged when only an outer var changes.

Fix: subscribe the filter and sort expressions' root keys to the update watcher (union into _keys), and bypass the same-reference guard when a filter expression exists.

Regression: 3 unit tests (toggle re-filter, search/includes re-filter, keyed loop outer-scope filter) + 2 e2e fixtures/tests. Full suite 2287/2287. dist rebuilt. Verified live: toggling an outer var now re-filters the list (was stale past 3s).

The loop's update watcher was only keyed on the listPath expression
(e.g. "items"), so key-scoped notifications for outer-scope variables
read during filter evaluation (e.g. "showActive") were silently
skipped. Additionally, the same-reference optimisation short-circuited
the update before the filter could re-evaluate when the source array
reference was unchanged.

Two changes:
1. Call _watchExpr for filterExpr and sortProp so their root keys are
   unioned into the update watcher's _keys set.
2. Bypass the same-reference optimisation when a filter expression
   exists, since the filter result can change even when the source
   array hasn't.

Closes #335
@ErickXavier
ErickXavier merged commit 521cf1d into main Aug 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

each/filter does not react to outer-scope dependencies in the filter expression

1 participant