Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Don't call customizeComponentName on curly components #1255

Merged
merged 3 commits into from
Jan 30, 2021

Conversation

dfreeman
Copy link
Contributor

The change in #1253 caused customizeComponentName to be called on block-form curly components, while before it was only invoked for angle-bracket components. For anyone making ahem questionable use of :: in curly component names in Ember, this meant those would always be converted to / instead.

This change restores the previous behavior and adds a test to cover it. Thanks to @pzuraq for confirming what was going on and the likely fix!

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fix is a nice stepping stone (and the test cases are good), but I think we still have a bit more to fix up here...

Comment on lines 90 to 92
// If the name in question is an uppercase (i.e. angle-bracket) component invocation, run
// the optional `customizeComponentName` function provided to the precompiler.
if (resolution.resolution() === SexpOpcodes.GetFreeAsComponentHead && isUpperCase(name)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We chatted a bit about this in discord, but I think even after this change we still have an issue. I would expect (for example) that {{#Foo}}{{/Foo}} should also not call customizeComponentName, prior to #1253 we only attempted transformation for element.tag specifically.

Comment on lines +75 to +96
test('customizeComponentName is not invoked on curly components', function (assert) {
let wire = JSON.parse(
precompile('{{#my-component}}hello{{/my-component}}', {
customizeComponentName(input: string) {
return input.toUpperCase();
},
})
);

let block: WireFormat.SerializedTemplateBlock = JSON.parse(wire.block);

let [[, componentNameExpr]] = block[0] as [WireFormat.Statements.Block];

glimmerAssert(
Array.isArray(componentNameExpr) &&
componentNameExpr[0] === SexpOpcodes.GetFreeAsComponentHead,
`component name is a free variable lookup`
);

let componentName = block[3][componentNameExpr[1]];
assert.equal(componentName, 'my-component', 'original component name was used');
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make another (I think failing) test that looks like:

{{#Foo}}hello{{/Foo}}

And also confirms that customizeComponentName is not called? I believe that the current implementation will fail a test like this, but prior to #1253 would have passed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (thanks @jamescdavis!)

@jamescdavis jamescdavis mentioned this pull request Jan 26, 2021
@dfreeman
Copy link
Contributor Author

Thanks for the review, @rwjblue! Chatting with @pzuraq, it sounds like this is going to be a bit more complex to completely restore the previous behavior.

We generally treat a green ember-release build in CI as required for our internal addons, since the canary/beta train usually gives us plenty of time to react to incoming changes. Given that this entered the scene relatively late in the 3.25 beta cycle, what do you think the likelihood is of either landing the partial fix or reverting the change before 3.25 becomes stable?

@rwjblue
Copy link
Member

rwjblue commented Jan 27, 2021

The issue is that reverting #1253 also leaves us in a bad state, the following is broken (and was the original reported issue in emberjs/ember.js#19334):

<div class="rentals">
  <ul class="results">
    {{#each @model as |rental|}}
      <li><Rental @rental={{rental}} /></li>
    {{/each}}
  </ul>
</div>

Prior to #1253 this snippet would assume that <Rental /> was invoking the block param rental (because customizeComponentName('Rental') results in rental).

@rwjblue
Copy link
Member

rwjblue commented Jan 27, 2021

Also, to be super clear here: We absolutely must fix this prior to an [email protected] release. I think @pzuraq is going to try to poke at it a bit more today, hopefully he can spot the right path forward.

@rwjblue
Copy link
Member

rwjblue commented Jan 27, 2021

@dfreeman / @jamescdavis - Would one y'all mind opening an issue on the Ember side for this also? I would love to make sure that there is something that others running into issues in the 3.25.0-beta series could find upon a search over there (since not everyone understands the repo relationships).

@jamescdavis
Copy link
Contributor

I fixed up #1256 by making the no conflict test a todo, just for illustrative purposes (or, you know, if all else fails).

@rwjblue rwjblue added the bug label Jan 30, 2021
@rwjblue rwjblue merged commit 40171c1 into glimmerjs:master Jan 30, 2021
@chancancode
Copy link
Contributor

When this is incorporated into beta, can someone open a PR to revert ember-learn/super-rentals-tutorial@cc75067 and confirm we can get a clean build?

@rwjblue
Copy link
Member

rwjblue commented Feb 1, 2021

When this is incorporated into beta

The PR is still pending emberjs/ember.js#19363

@jamescdavis
Copy link
Contributor

@dfreeman dfreeman deleted the leave-blocks-alone branch May 19, 2021 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants