ActionView: Dependency analysis, state tracing, reverse node index - #1667
Draft
marcoroth wants to merge 1 commit into
Draft
ActionView: Dependency analysis, state tracing, reverse node index#1667marcoroth wants to merge 1 commit into
marcoroth wants to merge 1 commit into
Conversation
commit: |
馃尶 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 |
This was referenced Aug 3, 2026
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 introduces template dependency analysis, a system that statically traces which pieces of state (instance variables, constants, locals) each template depends on, how that state flows through
rendercalls into partials, and, down to the AST node, which parts of a template are affected when a given piece of state changes.Motivation
The render graph introduced in #1663 answers "which templates render which partials?". This pull request answers the next question reactivity needs: "when
@userchanges, which templates, and which exact nodes inside them, need to re-render?"This is the dependency-tracking foundation for reactive rendering: a reverse index from state to affected templates and nodes. When state changes at runtime, or a template changes on disk during development, this index tells us precisely what to re-evaluate instead of re-rendering the world.
The
node_pathcoordinates it produces are the same child-index paths the Syntax Tree Diff Engine (#1518) emits, so diff operations and dependency lookups address the tree in the same coordinate space.How it works
Herb::ActionView::TemplateDependenciesanalyzes each template with three visitors:DependencyCollectorwalks the HTML+ERB AST and, via Prism, the embedded Ruby, collecting instance variables, constants, declared strict locals, received locals, render calls (with their locals and collections), helper calls (checked against the ActionView helper registry plus scannedapp/helpers/), and unknown calls.NodeDependencyCollectorfinds the specific AST nodes affected by a given state name, text content, expressions, conditionals, attributes, and render calls, each reported with itsnode_path(child indices from the document root) and source location.LocalScannerpre-scans templates for local assignments so locals aren't misclassified as unknown calls.State flow is traced through the render graph:
affected_templatesstarts at an entry point, followsrendercalls whose locals or collections reference the state (including renamed locals,render "card", user: @authorflows@authorinto the partial asuser), and returns every reachable template that carries it.API
Full manifest for one template
Which templates are affected when
@postchanges?Which nodes inside a template are affected?
Reverse index: state name => affected nodes
CLI
Manifest for all templates or one template:
herb actionview checknow also flags dependency warnings:app/helpers/.