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 router event deprecations, update to Ember 3.7 #183

Merged
merged 6 commits into from
Jan 17, 2019

Conversation

RobbieTheWagner
Copy link
Contributor

@RobbieTheWagner RobbieTheWagner commented Jan 14, 2019

didTransition and willTransition have been deprecated. It is now recommended to use event handlers instead. See https://deprecations-app-prod.herokuapp.com/deprecations/v3.x/#toc_deprecate-router-events

It also seemed like Travis was not running ember-try, so the tests were only running on the most recent Ember version. In an attempt to remedy this, I updated everything with ember-cli-update.

Closes #181

@RobbieTheWagner RobbieTheWagner changed the title Convert router methods to event handlers Fix router event deprecations, update to Ember 3.7 Jan 14, 2019
.travis.yml Show resolved Hide resolved
Copy link
Collaborator

@snewcomer snewcomer left a comment

Choose a reason for hiding this comment

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

Nice job! This will be nice for many of apps! So travis tests as far back as 2.18. Why do these new API's work back to that version and what version do they not work?

@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016
Copyright (c) 2019
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

addon/index.js Outdated
scrollPosition = { x: hashElement.offsetLeft, y: hashElement.offsetTop };
} else {
scrollPosition = get(this, 'service.position');
}

const preserveScrollPosition = transitions.some((transition) => get(transition, 'handler.controller.preserveScrollPosition'));
const preserveScrollPosition = get(transition, 'handler.controller.preserveScrollPosition');
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@RobbieTheWagner
Copy link
Contributor Author

@snewcomer I am not sure when this new API was introduced. It is possible it has always existed.

@ef4
Copy link

ef4 commented Jan 15, 2019

Thanks @rwwagner90, this is one of the deps (transitive through ember-cli-addon-docs) that has been breaking ember-animated on ember 3.6+.

I think this deprecation is fallout from the work that implemented the router service RFC. IIRC, these deprecated methods receive arguments that leak a bunch of internals and were never properly designed or documented. The new events receive arguments that don't require you to crawl through handlerInfos, etc, to discover what's going on.

@RobbieTheWagner
Copy link
Contributor Author

@ef4 do you know what versions of Ember the new methods should work with? I think the main concern here is whether we need to keep the old way too and conditionally call one or the other based on Ember version or if the new way works pretty far back in Ember as well?

@snewcomer
Copy link
Collaborator

snewcomer commented Jan 16, 2019

Perhaps add 2.16 and then 2.12 to the travis config and see which one/if any fails?

@RobbieTheWagner
Copy link
Contributor Author

@snewcomer we can definitely test back to those versions, but I am concerned perhaps the tests are not truly testing this. It would be great to know the Ember version support for the router events. @ef4 @rwjblue and insights on this?

@rwjblue
Copy link

rwjblue commented Jan 16, 2019

Ember added these new router events in 3.6.

Copy link

@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.

@rwwagner90 - It's a tad difficult to review PR's that mix "mundane blueprint upgrade things" with deprecation fixes.

```


## Running Tests
Copy link

Choose a reason for hiding this comment

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

This seems like a thing for CONTRIBUTING.md (along with the greenkeeper mention)

addon/index.js Outdated

destroy() {
reset();
this.on('routeWillChange', () => {
Copy link

Choose a reason for hiding this comment

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

This change definitely is a breaking change (maybe thats fine?) as it only supports 3.6+

If you need to stay compatible, you would bring in ember-compatiblity-helpers and wrap these things in an if:

import { gte } from 'ember-compatibility-helpers';

// ...snip...
if (gte('3.6.0-beta.1')) {
  // code for new APIs
} else {
  // code for older deprecated APIs
}

During a production build, the unused condition will be completely stripped (meaning there is no additional bloat to applications by having these conditionals).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @rwjblue I will do that. It's odd that all our tests are passing on older Ember. They must not be truly testing things.

@rwjblue
Copy link

rwjblue commented Jan 16, 2019

I don't know, you'd have to evaluate the tests themselves to see if they are testing reality or just unit testing with stubs (or some combo of each).

@RobbieTheWagner
Copy link
Contributor Author

RobbieTheWagner commented Jan 16, 2019

@snewcomer @rwjblue I think I got everything wrapped in compatibility helpers. I am adding willTransition and didTransition in init. Is there a better spot or way to do this?

addon/index.js Outdated
});
} else {
this.willTransition = (...args) => {
this._super(...args);
Copy link

Choose a reason for hiding this comment

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

I don't think this._super will work in this context (because this arrow function won't be super wrapped which happens during .extend).

Copy link

Choose a reason for hiding this comment

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

I think generally speaking we want to restructure to something like:

let RouterScrollMixin = Mixin.create({
  // shared code, and new `init` (with `router.on('routeWillChange'` / `router.on('routeDidChange'` behind the gte guard)
});

if (!gte('3.6.0-beta.1')) {
  RouterScrollMixin = Mixin.create(RouterScrollMixin, {
    willTransition() {},
    didTransition() {},
  });
}

export default RouterScrollMixin;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, will update

@RobbieTheWagner
Copy link
Contributor Author

@rwjblue updated per your suggestions 👍

Copy link

@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.

Seems good overall, IMHO someone should smoke test in an app that uses this addon in 3.4 and 3.6+ to make sure all works well since we are unsure why CI was passing on versions without the new events when we weren't using willTransition / didTransition...

@RobbieTheWagner
Copy link
Contributor Author

I am using it in a 3.7 app, and the changes work nicely. @snewcomer do you have an app on something before 3.6 you use this addon in and could test with?

Copy link
Collaborator

@snewcomer snewcomer left a comment

Choose a reason for hiding this comment

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

Tested and works as expected! Perhaps needs some better smoke tests, but you/I can follow up after!

@RobbieTheWagner
Copy link
Contributor Author

Sounds good @snewcomer! Are you able to merge or do we need to wait for The DSC guys?

Copy link
Contributor

@yowainwright yowainwright left a comment

Choose a reason for hiding this comment

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

LGTM. Please provide a version bump before merging. 😄

@RobbieTheWagner
Copy link
Contributor Author

We don't do a bump to release after merging? Typically it's a separate commit and tag via npm version minor etc.

@yowainwright
Copy link
Contributor

@rwwagner90 sure. That works too.

@RobbieTheWagner
Copy link
Contributor Author

Sounds good. Please merge at your convenience then 😄

@yowainwright yowainwright merged commit 4452258 into DockYard:master Jan 17, 2019
@RobbieTheWagner
Copy link
Contributor Author

Can someone with npm permissions please bump the version and release?

@cibernox
Copy link
Contributor

On my quest to fix ember-animated I found that this is the last addon preventing the update. Could we get a new release including these changes?

@RobbieTheWagner
Copy link
Contributor Author

@snewcomer @yowainwright if you guys would be interested in giving me my permissions back, I would be happy to handle the release.

@simonihmig
Copy link

+1 for a release with this! 😀

@RobbieTheWagner
Copy link
Contributor Author

Still happy to release this myself, if I can get permissions back please.

@snewcomer
Copy link
Collaborator

I don’t have permissions to publish. Just on github. Thx a ton for this work. If you don’t have publish permissions, I bet Jeff will get to it soon!

@williamweckl
Copy link

@snewcomer @yowainwright Can you guys please release it?

@RobbieTheWagner
Copy link
Contributor Author

There is a PR up, but @snewcomer and myself do not have permissions to npm #187

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants