Preserve Sprockets context dependency metadata - #217
Open
OskarEichler wants to merge 1 commit into
Open
Conversation
januszm
reviewed
Aug 28, 2026
| context = input[:environment].context_class.new(input) | ||
| Slim::Template.new(input[:name]) { input[:data] }.render(context) | ||
| data = Slim::Template.new(input[:name]) { input[:data] }.render(context) | ||
| context.metadata.merge(data: data) |
Contributor
There was a problem hiding this comment.
Nice, thanks, could you confirm that the return value of self.call is not used anywhere (ie. it is discarded after call)?
januszm
approved these changes
Aug 28, 2026
Author
|
Confirmed the return value is consumed by Sprockets as the processor result; it is not otherwise called directly in this repository. Returning context.metadata merged with data follows that processor contract and preserves the dependency metadata instead of discarding it. |
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.
Summary
Preserve Sprockets context metadata when rendering a Slim asset so
depend_onchanges invalidate the compiled asset cache. The transformer currently returns only the rendered string and drops dependency metadata accumulated by the context.The return value now follows Sprockets' processor contract, as its ERB processor does:
context.metadata.merge(data: rendered_html).Reproduction
With Sprockets 4.4.1, put these files on the asset load path:
Compile
page.htmlusing this transformer and aSprockets::Cache::MemoryStore. Changepayload.txtfromfirsttosecond, advancing its mtime, then create a fresh environment sharing that cache and compile again. Before:<p>first</p>remains cached. After:<p>second</p>, changed digest, and payload dependency retained.Verification
Compatibility / limitations
No public rendering API break or dependency upgrade intended. The internal
Transformer.callreturn becomes a processor Hash instead of String; direct users of that internal method must account for this. Assets still expose rendered HTML. Sprockets 2/3 paths are unchanged; only Sprockets 4.4.1 was exercised here. The release-based consumer package retains version 4.0.0 and dependency requirements.