-
Notifications
You must be signed in to change notification settings - Fork 159
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
Prevent context matching if the oldContext is null #242
Conversation
Why is it not possible to test (can you explain)? |
d38fd5c
to
2273bd2
Compare
This comment was wrong.To trigger the issue the route actually needs to be processed asynchronously. The faked-in asynchronous behavior isn't enough to trigger it.So, I would need to modify this line like so: diff --git a/tests/router_test.js b/tests/router_test.js
index 07b2d69..cb3bafd 100644
--- a/tests/router_test.js
+++ b/tests/router_test.js
@@ -28,7 +28,15 @@ var scenarios = [
getHandler: function(name) {
// Treat 'loading' route transitions are synchronous
var handler = handlers[name] || (handlers[name] = {});
- return name === 'loading' ? handler : Promise.resolve(handler);
+ if (name === 'loading') {
+ return handler;
+ } else {
+ return new Promise(function(resolve) {
+ setTimeout(function() {
+ resolve(handler);
+ }, 1);
+ });
+ }
},
getSerializer: function(name) {
return serializers && serializers[name]; And then approximately every async test fails since it is now running out of turn compared to the test suite. |
2271b3c
to
77502fb
Compare
The problem with the old code is that it was simply comparing equality of the We need to check to see if there actually is a context, and if that context is shared. Only in that case is it a valid assumption to copy over params. |
if (result.names.length > 0 && newHandlerInfo.context === oldContext) { | ||
if ( | ||
result.names.length > 0 && | ||
!!oldContext && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be specific here I think. For example, a 0
or ’’
(empty string) are probably fine...
77502fb
to
2273bd2
Compare
The bug is triggered by this process:
|
d964229
to
dc7c598
Compare
(Travis lost its mind. Restart the failing test one to see it actually fail.) |
Restarted a few times, seems to not fail? |
649954f
to
5508ba1
Compare
if (result.names.length > 0 && newHandlerInfo.context === oldContext) { | ||
if ( | ||
result.names.length > 0 && | ||
oldHandlerInfo.hasOwnProperty('context') && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does adding this guard allow us to delete this
router.js/lib/router/handler-info.js
Lines 240 to 254 in 2bfd8e5
// this is bonkers, we require that `context` be set on on the | |
// HandlerInfo prototype to null because the checks in | |
// `NamedTransitionIntent.prototype.applyToHandlers` here | |
// https://github.com/tildeio/router.js/blob/v1.2.8/lib/router/transition-intent/named-transition-intent.js#L76-L81 | |
// check of `oldHandlerInfo.context === newHandlerInfo.context` and assumes | |
// that the params _must_ match also in that case. | |
// | |
// The only reason `oldHandlerInfo.context` and `newHandlerInfo.context` did not | |
// match in prior versions is because if the context isn't set yet (on newHandlerInfo) | |
// is because it inherits the `null` from the prototype vs `undefined` (on | |
// the oldHandlerInfo). | |
// | |
// A future refactoring should remove that conditional, and fix the hand full of | |
// failing tests. | |
HandlerInfo.prototype.context = null; |
If we can do that, we don't need the hasOwnProperty
check here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're still going to need hasOwnProperty
for the scenario where: oldHandlerInfo.context === undefined && newHandlerInfo.context === undefined
because neither explicitly set it.
It's also theoretically possible that use as a microlib would set context to a "meaningful" undefined
value on the instance.
Regardless, I believe that hasOwnProperty
is the correct check here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(See step 7 in #242 (comment))
tests/router_test.js
Outdated
@@ -1594,6 +1594,27 @@ scenarios.forEach(function(scenario) { | |||
showPost: showPostHandler, | |||
}; | |||
|
|||
// Check for mid-transition correctness. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this into a test of its own? Seems odd to just be an extra assertion in a somewhat unrelated test...
28979ce
to
cb0b43f
Compare
I opted to never explicitly set the |
Fixes:
ember-transitioning-in
CSS class applied incorrectly when passing ID instead of the whole model to {{link-to}} helper emberjs/ember.js#10989ember-transitioning-in
stuck emberjs/ember.js#10195