Prevent SelfDrop context mutation across render boundaries#2082
Prevent SelfDrop context mutation across render boundaries#2082karreiro wants to merge 3 commits into
SelfDrop context mutation across render boundaries#2082Conversation
aswamy
left a comment
There was a problem hiding this comment.
Not sure if liquid-spec also allows render tags, but ill update it to capture your test. Thank you for this ❤️
…drop_context_test.rb
ianks
left a comment
There was a problem hiding this comment.
We likely want to undef context as well, which serves as a signal that the drop doesn’t support contextualization
|
Thank you for the review, @ianks! I did consider |
74943a1 to
bc7f1ca
Compare
|
Hi 👋 This looks like a subtle change in policy for the I understand if you've decided this is a positive new feature. It's just that with this change partial templates are less isolated. They are potentially more tightly coupled to their parent templates, which I thought was one of the reasons for introducing And, of course, having arbitrary aliases of |
|
Thank you for the review, @jg-rp! That's a fair concern indeed. I had the same instinct when I first saw this, but talking with @ianks clarified this in my mind:
The positive feature we're introducing with The isolation boundary is still there. It just has a handle to a drop that was deliberately handed to it. I hope this clarifies the concern and motivation. Thanks again for the review! |
| @self_context.variable_defined?(key) | ||
| end | ||
|
|
||
| def context=(_); end |
There was a problem hiding this comment.
| def context=(_); end | |
| undef context |
this should be done so upstream implementations know the value is not contextualizable
This PR fixes
SelfDropscoping so aselfassigned in one template preserves its original scope when passed to a rendered template.# template1.liquid {% assign var = 42 %} {% assign s = self %} {% render 'template2', other_self: s %} # template2.liquid {% assign var = 43 %} {{ other_self.var }} => 43 (wrong — should be 42)The fix renames
@contextto@self_contextinSelfDrop, so the drop has a specific reference to its originating context instead of reusing the inheritedcontextthat gets overwritten at thecontext.rblevel on line 220.