Skip to content

Client: Add, drop and reorder the rows a collection's payload asks for - #2276

Merged
marcoroth merged 1 commit into
slots/displacedfrom
slots/collections
Aug 18, 2026
Merged

Client: Add, drop and reorder the rows a collection's payload asks for#2276
marcoroth merged 1 commit into
slots/displacedfrom
slots/collections

Conversation

@marcoroth

Copy link
Copy Markdown
Owner

This pull request lets a collection be edited and not only updated.

apply filled the rows both sides already agreed on and deferred every change to which rows there were, so rows could never be added, removed or moved. Two thirds of that was pessimism: removing a row and moving one need no markup at all, only the row's own range.

The third needed something to copy. Every row of a collection is the same shape by construction, so any row on the page is a template for the rest: one is cloned, emptied, given the key it is being built for, and filled from the payload like any other row. Which leaves one case that genuinely cannot be done, a collection with no rows at all, and that is what deferred now reports.

slots.reconcile(collection, ["3", "1", "2"])
// { added: [], removed: [], moved: ["3", "1"], kept: [...], unchanged: false }

So the server parks a row for a collection that rendered none, and _herb_covered_branches does the deciding exactly as it does for a branch: a collection with rows on the page marks itself covered and parks nothing, because the page already holds a better copy than the compiler could write. The parked row carries an empty key, since a row's key is an expression and has no static form, and whatever builds a row from it has to say which row it is building anyway.

Parking happens before the key marker goes in and not after, because the statics printer refuses a tree it cannot print, and an expression is exactly what it cannot print. Parking afterwards silently parked nothing at all.

Two notes on the mechanics. The rows sort by moving each one to the end in the order asked for, measured against the collection's own closing marker, which is the one node no row can be inside, and that works in a table where the parser puts the rows in a tbody and leaves the markers around them at another depth. And JavaScript sorts integer-like object keys numerically, so JSON.parse loses the order the server wrote for a collection keyed by id. Ascending is what an append wants, so it rarely shows, but a collection whose order the server decides has to be keyed by something that is not a number. There is a test saying so.

@github-actions github-actions Bot added ruby Ruby source for the gem and its libraries typescript TypeScript source across the javascript/ packages rbs RBS type signatures in sig/ engine Herb engine and Rails template compilation rubygem The herb RubyGem and its packaging labels Aug 18, 2026
@nx-cloud

nx-cloud Bot commented Aug 18, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit d1e5c4b

Command Status Duration Result
nx run-many -t test --all --parallel --exclude=... ✅ Succeeded 3m 31s View ↗
nx run-many -t build --all --exclude=herb-langu... ✅ Succeeded 14s View ↗
nx build @herb-tools/tailwind-class-sorter ✅ Succeeded 1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-08-18 03:42:23 UTC

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit d1e5c4b


✅ Preview deployment has been cleaned up.

@pkg-pr-new

pkg-pr-new Bot commented Aug 18, 2026

Copy link
Copy Markdown
npx https://pkg.pr.new/@herb-tools/formatter@2276
npx https://pkg.pr.new/@herb-tools/language-server@2276
npx https://pkg.pr.new/@herb-tools/linter@2276

commit: d1e5c4b

@marcoroth marcoroth added reactivity Reactive ERB templates: diff and re-render only what changed client-runtime Browser runtime for the Herb slots. labels Aug 18, 2026
@marcoroth
marcoroth merged commit 8ac72b1 into main Aug 18, 2026
72 of 79 checks passed
@marcoroth
marcoroth deleted the slots/collections branch August 18, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client-runtime Browser runtime for the Herb slots. engine Herb engine and Rails template compilation rbs RBS type signatures in sig/ reactivity Reactive ERB templates: diff and re-render only what changed ruby Ruby source for the gem and its libraries rubygem The herb RubyGem and its packaging typescript TypeScript source across the javascript/ packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant