-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't support pushState when the original request method was anything…
… other than GET We cannot use pushState if the initial request method is a POST for two reasons: 1. Up.js replaces the initial state so it can handle the pop event when the user goes back to the initial URL later. If the initial request was a POST, Up.js will wrongly assumed that it can restore the state by reloading with GET. 2. Some browsers have a bug where the initial request method is used for all subsequently pushed states. That means if the user reloads the page on a later GET state, the browser will wrongly attempt a POST request. Modern Firefoxes, Chromes and IE10+ don't seem to be affected by this, but we saw this behavior with Safari 8 and IE9 (IE9 can't do pushState anyway). The way that we work around this is that we don't support pushState if the initial request method was anything other than GET (but allow the rest of the Up.js framework to work). This way Up.js will fall back to full page loads until the framework was booted from a GET request.
- Loading branch information
1 parent
85822e7
commit d81d900
Showing
6 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require "upjs/rails/version" | ||
require "upjs/rails/engine" | ||
require "upjs/rails/current_location" | ||
require "upjs/rails/request" | ||
require "upjs/rails/request_echo_headers" | ||
require "upjs/rails/request_method_cookie" | ||
require "upjs/rails/request_ext" |
6 changes: 3 additions & 3 deletions
6
lib/upjs/rails/current_location.rb → lib/upjs/rails/request_echo_headers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# See | ||
# https://github.com/rails/turbolinks/search?q=request_method&ref=cmdform | ||
# https://github.com/rails/turbolinks/blob/83d4b3d2c52a681f07900c28adb28bc8da604733/README.md#initialization | ||
module Upjs | ||
module Rails | ||
module RequestMethod | ||
|
||
COOKIE_NAME = '_up_request_method' | ||
|
||
def self.included(base) | ||
base.before_filter :set_up_request_method_cookie | ||
end | ||
|
||
private | ||
|
||
def set_up_request_method_cookie | ||
if request.get? | ||
cookies.delete(COOKIE_NAME) | ||
else | ||
cookies[COOKIE_NAME] = request.request_method | ||
end | ||
end | ||
|
||
ActionController::Base.send(:include, self) | ||
|
||
end | ||
end | ||
end |