quirkey / sammy

Sammy is a tiny javascript framework built on top of jQuery, It's RESTful Evented Javascript.
http://sammyjs.org
MIT License
2.99k stars 384 forks source link

Chrome 404s when requesting same url twice in a row #20

Closed pdelanauze closed 14 years ago

pdelanauze commented 14 years ago

This is some odd behaviour that seems specific to chrome, safari and firefox are unaffected.

I have a request to #/settings/ this request basically toggles a component's visibility and then redirects to #/

This will work the first time But when requesting this URL the second time, a 404 will be printed and the event won't reach the sammy application.

Now, this only happens when requesting an identical URL a second time without asking for something else in the meanwhile. Example if I ask for #/settings/ and then #/main/ and then #/settings/ everything will work. But if I ask for #/settings/ and then #/settings/ sequentially, the second request will fail with a 404.

mrb commented 14 years ago

Can you post some sample code that illustrates this? I use Sammy in Chrome all the time, with redirects, and have never had this issue.

pdelanauze commented 14 years ago
<a href="#/hello">Test</a>

Then in the sammy application:

this.get("#/hello", function(context){
  context.redirect("#/");
});

Now if you click on the "test" link the first time, it will be fine, "#/hello" gets triggered and then redirected to #/ Then click on it again, and the request will get stuck in "#/hello" and does not get redirected.

Here's what happens in the logs when doing 2+ clicks on the link element.

runRoute get #/
XHR finished loading: "http://localhost/~pat/widget/src/main/webapp/templates/quotes.template".
native hash change exists, using
runRoute get #/hello
Entering hello
runRoute get #/
Exiting hello, should have gotten redirected to #/ now.
XHR finished loading: "http://localhost/~pat/widget/src/main/webapp/templates/quotes.template".
pengwynn commented 14 years ago

I'm seeing this too, only in chrome

mrb commented 14 years ago

Can one of you guys post a Sammy one page app that makes this reproducable? Aaron and I can't get this error to pop up!

quirkey commented 14 years ago

last_location was being overriden if you redirected back multiple times. Closed by 66c1fc103b491796e694df25cb1183e1774f1561

All the tests are passing on it, though I'm a little worried its going to break something bigger.

pengwynn commented 14 years ago

This indeed fixed the problem I was having in chrome. Thanks!