Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug] {{if @content}} breaks parent reference in conditionals when using "within" #598

Open
ericyhwang opened this issue Mar 5, 2022 · 0 comments

Comments

@ericyhwang
Copy link
Contributor

Short summary: When using within with custom content that has {{if parent.method()}}, the parent reference is wrong when the inner component surrounds the content usage with {{if @content}}. The parent reference incorrectly resolves to the inner component under those two exact conditions, when it should resolve to the outer component.

I wrote failing test cases in Derby that demonstrate this bug, on the branch bug-within-if-content-parent:
b4f45da


Say you have a picture-frame component that allows the inclusion of custom {{content}}. When using picture-frame from another component, say showcase, the default is that the "passed-in" custom content uses the context of showcase, where the custom content is declared.

It is possible to use the within attribute to have the custom content use the context internal to picture-frame, instead of the default of showcase. If the custom content also needs to use controller methods from the outer showcase, it can refer to them by {{parent.method()}}.

That all works fine, but there is a bug when both these are true:

  1. The custom content uses a {{if parent.method()}} binding.
    • The text binding{{parent.method()}} works regardless of the second point.
  2. picture-frame surrounds the content with {{if @content}} {{content}} {{/if}}.
    • {{if content}} (model path instead of attribute path) allows the first point to work fine.

Full example below.

showcase.html:

<index:>
<view is="picture-frame" within>
  {{frameInternalPath}}
  <!-- This works fine in both cases -->
  {{parent.showcaseName()}}
  <!-- This breaks when picture-frame uses {{if @content}} -->
  {{if parent.showcaseName()}} Uh oh! {{/if}}
</view>

showcase.js:

class Showcase {
  showcaseName() { return 'The Showcase'; }
}

picture-frame.html:

<index:>
{{if @content}}
  {{content}}
{{/if}}

picture-frame.js:

class PictureFrame {
  init() {
    this.model.set('frameInternalPath', 'Hello');
  }
}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant