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

fix(component): @layout accept template factory #451

Closed
wants to merge 12 commits into from

Conversation

buschtoens
Copy link
Collaborator

@buschtoens buschtoens commented Jul 1, 2019

emberjs/ember.js#18096

This PR changed how templates get transpiled under the hood.
The export from templates are now factory functions which expect to be passed the owner.

emberjs/ember.js#18096

This PR changed how templates get transpiled under the hood.
The export from templates are now factory functions which expect to be
passed the `owner`.
@rwjblue
Copy link
Contributor

rwjblue commented Jul 2, 2019

CI is failing due to using Node 6:

@ember-data/-build-infra/node_modules/broccoli-rollup/dist/index.js:31
    async build() {
          ^^^^^

@buschtoens
Copy link
Collaborator Author

Should we pin the Ember Data dependency for now and do a major release later that drops Node 6?

emberjs/data#6048

The linked PR dropped support for Node v6 and was released a `3.11.0`.
To fix our CI we pin `ember-data@~3.10.0`. We will later drop support
for Node v6 ourself, but this will likely require a major release.
@buschtoens buschtoens force-pushed the fix/component/layout-template-factory branch from c17a45a to 727d8f7 Compare July 3, 2019 11:49
@buschtoens buschtoens force-pushed the fix/component/layout-template-factory branch from 727d8f7 to a094cc6 Compare July 3, 2019 12:13
(() => typeof template === 'object' && typeof template.indexOf === 'undefined')()
(() =>
typeof template === 'function' ||
(typeof template === 'object' && typeof template.indexOf === 'undefined'))()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

btw is there any reason this is an IIFE? If not, I'd remove that in this PR as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

No not particularly. I'd only use an IIFE in order to simplify the boolean logic, e.g.:

assert(
  'whatever',
  (() => {
    if (condition) { return true; }
    if (otherThing) { return true; }
    return false;
  })()

It would probably make this specific case easier to think about, but isn't a giant deal.

@buschtoens
Copy link
Collaborator Author

I am sure that the typescript@next error is caused by microsoft/TypeScript#30790.

Error: Errors in typescript@next for external dependencies:
../../../node_modules/@types/node/index.d.ts(187,11): error TS2300: Duplicate identifier 'IteratorResult'.
../../../node_modules/dtslint/typescript-installs/next/node_modules/typescript/lib/lib.es2015.iterable.d.ts(41,6): error TS2300: Duplicate identifier 'IteratorResult'.

I reported it here: microsoft/TypeScript#30790 (comment)

@buschtoens
Copy link
Collaborator Author

Oh come on FFS, how hard can it be to get a freaking one-line change merged? 😂

ember-cli-addon-docs and all the dependencies it brings in are just causing sooo many issues. I'll open another PR to get master clean first, when I can find some time.

@buschtoens
Copy link
Collaborator Author

Alright, I discovered another issue with emberjs/ember.js#18096 in combination with @layout in production builds. It's a reprise of #327.

In development builds or builds that only target browsers that support arrow functions, the returned TemplateFactory and thus first argument passed to @layout is an arrow function, e.g. owner => { ... }.

Importantly, arrow functions have no prototype key, while regular functions (function(owner) { ... }) do.

function isClassDescriptor(possibleDesc) {
let [target] = possibleDesc;
return (
possibleDesc.length === 1 &&
typeof target === 'function' &&
'prototype' in target &&
!target.__isComputedDecorator
);
}

This causes the above code to report a false positive in production builds an lets the @layout decorator fail with:

Error: Assertion Failed: The @layout decorator requires parameters

Since decoratorWithRequiredParams thinks the decorator is invoked like:

@layout
class {}

// instead of
@layout(template)
class {}

I suggest we stop using decoratorWithRequiredParams for @layout. Unfortunately we use a check here then, but I don't see any other way to fix this.

Copy link
Contributor

rwjblue commented Jul 5, 2019

Ya, that seems fine to me...

@josemarluedke
Copy link
Contributor

@buschtoens @rwjblue Is there anything that I can help with to move this forward? I'm currently blocked on upgrading Ember Canary because of the issue this solves.

@rwjblue
Copy link
Contributor

rwjblue commented Aug 1, 2019

AFAIK the blocker is just implementing the change @buschtoens suggested

@buschtoens
Copy link
Collaborator Author

I fixed the decoratorWithRequiredParams usage and removed the IIFE, but I expect CI to still fail spectacularly, because of all the other unrelated issues 🙈

@buschtoens buschtoens force-pushed the fix/component/layout-template-factory branch from 152262f to faec94f Compare August 1, 2019 15:45
@rwjblue
Copy link
Contributor

rwjblue commented Aug 1, 2019

@pzuraq - Thoughts on the path forward here?

@pzuraq
Copy link
Contributor

pzuraq commented Aug 1, 2019

I think the solution looks good, I'm not actually sure what the test failures on Canary are, it looks like they're coming from pretty deep inside the VM O_o

Also unsure what's going on with production tests. I can try to take a look sometime next week, going to be busy for the remainder of this week. I also think we could make canary tests optional at this point, since we don't expect much to be changing with regards to the object model in the near future. Ideally we wouldn't, but we could to get unblocked.

@buschtoens
Copy link
Collaborator Author

buschtoens commented Aug 1, 2019

The canary failure is caused by emberjs/ember-test-helpers#677

Edit: I might be mistaken, but I think this was the error I set out to fix with above PR.

@rwjblue
Copy link
Contributor

rwjblue commented Aug 2, 2019

Ya, could be but I thought I fixed those issues in ember so it didn't require changes in addons (e.g. didn't need to upgrade @ember/test-helpers).

@josemarluedke
Copy link
Contributor

Failures are agast "canary" and "production", could it be that when the tests ran, the build didn't pick up the changes that @rwjblue is referring as fixed?

Error: Cannot read property 'lookup' of undefined

The error does seem to be related, maybe some can restart the tests to see if it passes now?

Looking forward to having this fixed.

@rwjblue
Copy link
Contributor

rwjblue commented Aug 6, 2019

The production build failure was not related to the lookup failure (it was Error: Browser failed to connect within 30s. testem.js not loaded?).

Apparently my fix in ember-source only fixed setupRenderingTest style tests, not moduleForComponent. I haven't had a chance to dig into that yet though. It is blocking a couple legit bug fixes over in @ember/test-helpers though.

@rwjblue
Copy link
Contributor

rwjblue commented Aug 6, 2019

A plausible path forward here would be to run the codemod to migrate to setupRenderingTest to work around the bug in moduleForComponent.

@rwjblue
Copy link
Contributor

rwjblue commented Aug 9, 2019

OK, now ready for a rebase...

@rwjblue
Copy link
Contributor

rwjblue commented Aug 12, 2019

Rebased and merged in #454

@rwjblue rwjblue closed this Aug 12, 2019
@rwjblue rwjblue deleted the fix/component/layout-template-factory branch August 12, 2019 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants