mithril.js: Route is not resolved on hash change in IE

Hello!

I found that in IE supportsPushState is true, but onpopstate will never be called. So links does not work.

Example here: https://jsfiddle.net/1bj54j8v/

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (16 by maintainers)

Commits related to this issue

Most upvoted comments

@isiahmeadows Worse, I recently realised that onhashchange wasn’t debounced as I thought it was due to a JSBin bug(https://github.com/jsbin/jsbin/issues/3078) (and not enough cross checking on my hand)…

I’m afraid the fix for this will be breaking: https://github.com/pygy/mithril.js/commit/bd7230fc54c80695187ad94d8f987f3295e0dd3a#diff-08af55052ff6ecc22309ea97e4711428R101

This is impossible to implement for IE9 (and it has never been), but if we want the router to work identically in every env in hash mode, we can’t cheat with replaceState() when the routed tree is mounted.

This test would have passed in non-IE browsers…

There’s also https://github.com/pygy/mithril.js/commit/bd7230fc54c80695187ad94d8f987f3295e0dd3a#diff-08af55052ff6ecc22309ea97e4711428R799 that must be elucidated, it may be a pushStateMock bug or a router bug.

Edit: here’s the problem child in full:

if (prefix[0] !== "#") {
	o("default route doesn't break back button", function(done) {
		// impossible to do with onhashchange, "new.com" should equal "old.com"
		init("")
		$window.location.href = "http://old.com"
		$window.location.href = "http://new.com"

		route(root, "/a", {
			"/a" : {
				view: function() {
					return m("div")
				}
			}
		})

		callAsync(function() {
			o(root.firstChild.nodeName).equals("DIV")

			o(route.get()).equals("/a")

			$window.history.back()

			o($window.location.pathname).equals("/")
			o($window.location.hostname).equals("old.com")

			done()
		})
	})
}

Before this, onhashchange-based routing wasn’t tested at all 😕