-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
History native calls #3006
History native calls #3006
Conversation
dependency in History
@jdalton can you verify this works in all versions of IE? My VM isn't booting on me. |
removeEventListener('popstate', this.checkUrl); | ||
} else if (this._wantsHashChange && 'onhashchange' in window && !this._oldIE) { | ||
removeEventListener('hashchange', this.checkUrl); | ||
} |
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.
Need to pass false
for useCapture
here as well, no?
* No need for `_oldIE` when we can just use `this.iframe`. * Added `this._hasHashchange`.
👍 This is good stuff. There's a quick tweak or two in akre54#2, tested in IE7-9. |
@braddunbar — You like this change in general? Or only in conjunction with other patches that make it easier to untangle jQuery? |
Remove `_oldIE` variable.
I like this one in general, regardless of what we decide about |
); | ||
this.iframe = body.appendChild(frame).contentWindow; | ||
} | ||
} catch(e){} |
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 we remove the try/catch if we check 'documentMode' in document
instead?
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.
The try-catch is also for the createElement call. Although that likely shouldnt matter if your check is there.
I also seem to recall that Safari doesnt expose document.body until the page has finished downloading (i.e. scripts in the head
tag that use it are broken)
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 were using document.body
already so I'm not too worried about that. I'm not certain about documentMode
though.
Removed |
Remove `isExplorer` RegEx.
One more in akre54#4. 😃 |
I'll run it through the VMs again this evening. To see if anything changed after the cleanup. |
Glad to see that after all the discussion on #2959 (trolling included) we might end up having native Router and a View you can cleanly patch regardless of 👍 |
Check `documentMode` and combine checks.
@akre54 Tested latest from history-native-hooks in IE6-11, and IE9 in IE7 compat mode, all unit tests pass. |
Remove `onpopstate` check.
Add a comment about clearInterval.
@@ -1448,7 +1455,16 @@ | |||
// Disable Backbone.history, perhaps temporarily. Not useful in a real app, | |||
// but possibly useful for unit testing Routers. | |||
stop: function() { | |||
Backbone.$(window).off('popstate', this.checkUrl).off('hashchange', this.checkUrl); | |||
// Add a cross-platform `removeEventListener` shim for older browsers. | |||
var removeEventListener = window.removeEventListener || function (eventName, listener) { |
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.
@braddunbar Just wondering, but do we have to get rid of the iframe
here? It looks like it just hangs around in the DOM with no listeners after stop
is called, and creates a new one on each start
. Potential memory leak?
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.
Yep yep, we should remove it. Good catch!
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 only store a reference to the iframe's contentWindow
. Any idea how to turn this into a reference we can remove from the DOM?
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.
Hmm...let's punt on it for this issue and address it separately. It's not a regression in any case.
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.
okey #3015
|
That seems quite a bit nastier than simply sniffing the UA. We shouldn't be attempting to create an iframe in environments where we know that none is needed in the first place. |
Relying on a unique and relevant behavior to the target browsers is better than an arbitrary UA sniff. It also reduces the code needed to create the iframe, the try-catch is barely there.
True, it could be done under a |
In this particular case, hogwash. It's not at all out of the realm of plausibility that a new browser introduced in future years would allow HTML to be passed to document.createElement. |
It's not hogwash, and it simplifies creating the iframe element at the expense of ~15 chars for the try-catch.
Specs try to avoid breaking the web, doing research into api usage, and this area is well paved with IE opting to actually align with spec and drop the behavior in later releases. If your hangup is on the specific feature test that can be adjusted. |
Can we feature detect var oldIE = document.compatMode || (document.documentMode || 0) < 8; |
Others have |
Ergh |
http://www.nczonline.net/blog/2009/12/29/feature-detection-is-not-browser-detection/ https://github.com/jquery/jquery-migrate/blob/master/src/core.js#L50 As much as I'd like to feature detect unique old IE features, I just don't think it's reliable. IE 6 was widespread enough that everyone else started copying over stuff. @jashkenas is right. The try catch createElement block is a little too clever and I think it will trip people up during maintenance. |
I have a stupid question: Why can't we do something like this? if (!this._hasHashChange && this._wantsHashChange &&
(!this._wantsPushState || !this._hasPushState)) {
// make iframe
} Why go thru the trouble detecting old browser features and/or UA sniff at all? |
That's a great question. :) |
Backbone is already employing feature inferences. If the |
Create iframe conditional on options and hashchange and pushstate support
Looking good, just ran the tests in IE7-9 successfully. 👍 |
...and also a test page to ensure routing worked correctly. |
So this looks ready to go ... but it seems like a patch that only really makes sense in conjunction with one of the native-view patches. By itself, it simply uses jQuery a little bit less. Should the current state of this changed be merged into the open native-view patches ... instead of being merged directly? |
Not so fast. #3015 is not a real problem. Fixing it is fine, but it doesn't matter. I understand that this PR doesn't have a direct dependency — but that's not the question. This change, looked at in isolation, is a step backwards. If we merge it, and then never merge the two-steps-forward, then that's no good. Instead, let's try adding it in to the proposed patches that would rely on it (or make use of it). |
To be fair #3015 isnt a showstopper -- by a long shot. Should be no harm in merging this now and working out the kinks in View in the next few days |
How so? One could avoid jquery entirely if they only wanted routing and not views. We're almost there with #3003. |
I disagree. Removing the jQuery dependency allows use of Further, it removes the browser sniffing and fixes a long standing issue regarding starting history before the page loads. All wins in my book. |
Alright then. |
Split from #3003, this removes
Backbone.$
from Backbone.History and leaves View untouched.