Analysis: Number a node the way SlotVisitor and SubtreeCompiler do - #2279
Merged
Conversation
|
View your CI Pipeline Execution ↗ for commit f2276ea
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
🌿 Interactive Playground and Documentation PreviewA preview deployment has been built for this pull request. Try out the changes live in the interactive playground: 🌱 Grown from commit ✅ Preview deployment has been cleaned up. |
commit: |
marcoroth
force-pushed
the
slots/node-path
branch
from
August 18, 2026 16:17
1768bab to
f2276ea
Compare
marcoroth
added a commit
that referenced
this pull request
Aug 19, 2026
This pull request teaches the dependency analysis that a block's
parameters carry whatever that block iterates, in one template and
across a `render` call, and in all three languages that implement it.
```erb
<ul>
<% @items.each do |item| %>
<li><%= item.name %></li>
<% end %>
</ul>
```
`item` is `@items`, one at a time. Matching is by name, so nothing
connected the two, and `item.name` was attributed to nothing.
Ruby learned this within a single template in #2280. This finishes it:
the two ports learn the same thing, and the Ruby trace learns it across
a render boundary, which is where it was answering a user-facing
question incorrectly.
`affected_templates` and `state_flow` back `herb dependencies` and `herb
actionview flow`, and their whole product is the list of templates a
piece of state reaches. One shape was missing from it.
traced:
```erb
<%= render partial: "posts/card", collection: @posts %>
```
not traced:
```erb
<% @posts.each do |post| %>
<%= render "posts/card", card: post %>
<% end %>
```
For the second, `affected_templates(entry, "@posts")` returned
`["index.html.erb"]` and omitted `_card.html.erb`, and `state_flow`
returned a tree with no child. `trace_state` asks whether a render
call's local carries the state, and `card: post` names a block parameter
that nothing tied to the collection that bound it.
The collector now records the blocks open around a render call, with the
names each binds, and a local whose value is one of those names carries
what its block iterates.
`analyze` now parses with `iteration_nodes`, so a block running per item
and a block running once are different node types. Without that,
`form_with model: @post do |f|` looks like a collection and `f` carries
`@post` into every partial rendered inside the form.
Once the trace reaches `_card.html.erb`, its slots become addressable,
and they came back as an `identity`, which is a client writing one value
into every card. A render inside an iterating block is now per item the
same way `collection:` is, and the modes below a block that runs once
are left alone.
Follow up on #2279, #2280, #2281, #2282 and #2283.
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.
This pull request makes the three implementations of the dependency analysis number a node the same way, so a
node_pathfrom any of them names the same node.SubtreeCompilersays the target it renders is named by "the same pathSlotVisitorrecords for a slot andTemplateDependenciesreports for a node, so a caller that has one from either has one that works here". That is the join the slot work depends on.SlotVisitorwalks an element'sbodyandSubtreeCompilerindexes:body, while the analysis collector walkedchild_nodes, which is[open_tag, *body, close_tag]. Every element level shifted the index by one:An attribute was addressed by descending into the open tag, where a path does not go, so it reported
[0, 0, 1]where the visitor recorded[0]for the element carrying it. The bodies of blocks and loops were walked without pushing a path at all, so nothing inside a loop was addressable.