Skip to content

Derive keyed <for of> branch keys from the serialized list - #3354

Open
DylanPiercey wants to merge 1 commit into
mainfrom
for-derived-loop-keys
Open

Derive keyed <for of> branch keys from the serialized list#3354
DylanPiercey wants to merge 1 commit into
mainfrom
for-derived-loop-keys

Conversation

@DylanPiercey

Copy link
Copy Markdown
Contributor

Description

A stateful keyed loop serializes its list on the parent scope and a LoopKey per branch — but the keys are just by(list[i], i) over data already on the wire.

  • When the of= value is a plain read of a binding that always serializes (e.g. a stateful <let>), the server skips per-branch keys and writes a single LoopKeyList: reference to the list — identity-deduped against the state slot, so it costs a backreference, not a copy.
  • On the client, the loop assigns branch keys lazily on first update by running its compiled by (string or function form) over the serialized list — branch order matches SSR iteration order. No work happens at resume.
  • Guarded server-side to arrays with markers/branches on; anything else (derived expressions, param-conditional serialization, non-array iterables, <for in/to/until>) keeps per-branch keys.

Example: three keyed rows previously serialized {M:1},{M:2},{M:3}; now the branch fills are empty (elided) and the payload carries only Nb:_.a next to the existing list.

Checklist:

  • I have read the CONTRIBUTING document and have signed (or will sign) the CLA.
  • I have updated/added documentation affected by my changes.
  • I have added tests to cover my changes.

Generated by Claude Code

@changeset-bot

changeset-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f46d6fe

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@marko/runtime-tags Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 7 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aeb3bdef-cce3-4b9e-9859-8f699fc2bb80

📥 Commits

Reviewing files that changed from the base of the PR and between 92a8863 and f46d6fe.

⛔ Files ignored due to path filters (33)
  • packages/runtime-tags/src/__tests__/fixtures/basic-shared-node-ref/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/basic-shared-node-ref/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/basic-shared-node-ref/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/basic-shared-node-ref/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-mutated-option/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-mutated-option/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-mutated-option/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-mutated-option/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-by-use-index/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-by-use-index/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-by-use-index/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-by-use-index/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-by/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-by/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-by/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-by/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-derived-keys/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-derived-keys/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-derived-keys/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-derived-keys/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-derived-keys/__snapshots__/render.debug.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-derived-keys/__snapshots__/render.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-derived-keys/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-derived-keys/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-selector-class/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-selector-class/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-selector-class/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-selector-class/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-selector-prepend/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-selector-prepend/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-selector-prepend/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-selector-prepend/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/for-of-by-nullish-key/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
📒 Files selected for processing (45)
  • .changeset/for-derived-loop-keys.md
  • .sizes.json
  • .sizes/comments.csr/runtime.js
  • .sizes/dom.js
  • packages/runtime-tags/src/__tests__/fixtures/basic-nested-for/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/basic-push-pop-list/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/basic-shared-node-ref/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/cleanup-n-child-for-shallow/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/cleanup-single-child-for-deep/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/cleanup-single-child-for-shallow/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/conditional-dynamic-tag-in-loop-closure/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/controllable-checked-many/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-mutated-option/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/destructure-stateful-upstream-alias/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-array-destructure-rest/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-by-nested-branch-divergence/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-by-use-index/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-by/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-destructure/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-event-handler/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-item-member-intersection/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-derived-keys/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-derived-keys/template.marko
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-derived-keys/test.ts
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-selector-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-keyed-selector-prepend/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-loop-closure-remove-all-items/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-resume-cleanup-free-branch/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-resume-owns-branch-cleanup/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-tag-single-node-only-child-in-parent/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-tag-single-text-node-with-text-before/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-tag-with-state/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/for-to-range-resume-key/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/getter-on-single-node-only-child/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/known-tag-attr-tags-rest/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/let-bind-stateful-upstream-alias/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/native-tag-local-closures/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/nested-for-if-stateful/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/resume-single-node/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/spread-to-known-rest-input-with-attr-tags-deopt/sizes.json
  • packages/runtime-tags/src/common/accessor.debug.ts
  • packages/runtime-tags/src/common/accessor.ts
  • packages/runtime-tags/src/dom/control-flow.ts
  • packages/runtime-tags/src/html/writer.ts
  • packages/runtime-tags/src/translator/core/for.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch for-derived-loop-keys

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.10526% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.29%. Comparing base (9849a13) to head (f46d6fe).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
packages/runtime-tags/src/translator/core/for.ts 80.64% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3354      +/-   ##
==========================================
- Coverage   94.29%   94.29%   -0.01%     
==========================================
  Files         388      388              
  Lines       53085    53156      +71     
  Branches     4237     4246       +9     
==========================================
+ Hits        50058    50123      +65     
- Misses       2998     3004       +6     
  Partials       29       29              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant