-
Notifications
You must be signed in to change notification settings - Fork 621
Add Turbolinks-Status header to show custom error page #334
base: master
Are you sure you want to change the base?
Conversation
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.
Perhaps we should have turbolinks-rails always return a response header that indicates a successful Turbolinks page load. Then apps wouldn't need to take on the burden of remembering to return a special "I'm Turbolinks compatible" header on app-generated error responses.
If we always indicated Turbolinks response status: turbolinks --- a/src/turbolinks/http_request.coffee
+++ b/src/turbolinks/http_request.coffee
@@ -29,7 +29,7 @@ class Turbolinks.HttpRequest
requestLoaded: =>
@endRequest =>
- if 200 <= @xhr.status < 300
+ if 200 <= @xhr.status < 300 or @xhr.getResponseHeader("Turbolinks-Status") is "OK"
@delegate.requestCompletedWithResponse(@xhr.responseText, @xhr.getResponseHeader("Turbolinks-Location"))
else
@failed = true turbolinks-rails def render(*)
super.tap do
response.headers["Turbolinks-Status"] = "OK"
end
end |
7ec426a
to
a4c0e54
Compare
Sorry for late, updated PR..! |
Here’s the same change updated for the recent port to TypeScript: index 55eba8f..5be0d2a 100644
--- a/src/http_request.ts
+++ b/src/http_request.ts
@@ -68,7 +68,7 @@ export class HttpRequest {
this.endRequest(xhr => {
const contentType = xhr.getResponseHeader("Content-Type")
if (contentTypeIsHTML(contentType)) {
- if (xhr.status >= 200 && xhr.status < 300) {
+ if (xhr.status >= 200 && xhr.status < 300 || xhr.getResponseHeader("Turbolinks-Status") == 'OK') {
const redirectedToLocation = Location.wrap(xhr.getResponseHeader("Turbolinks-Location"))
this.delegate.requestCompletedWithResponse(xhr.responseText, redirectedToLocation)
} else { Trying to include this PR with the release of the TypeScript port might save some people a bit of trouble since the TypeScript port is likely to break the monkey patches currently in use to allow Turbolink to work well with custom error pages using the Rails application layout. @ypresto are you still interesting in trying to move this forward, or would you like me to take over from you? |
#179
PassingCalling render method withturbolinks: true
turbolinks-rails
gem will correctly replaces page with error response (non-2xx).gem PR:
turbolinks/turbolinks-rails#25turbolinks/turbolinks-rails#35