inertia_rails 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/inertia_rails/middleware.rb +1 -1
- data/lib/inertia_rails/version.rb +1 -1
- data/lib/inertia_rails.rb +3 -0
- data/lib/patches/better_errors.rb +17 -0
- data/lib/patches/debug_exceptions/patch-4-1.rb +41 -0
- data/lib/patches/debug_exceptions/patch-4-2.rb +52 -0
- data/lib/patches/debug_exceptions/patch-5-0.rb +23 -0
- data/lib/patches/debug_exceptions/patch-5-1.rb +26 -0
- data/lib/patches/debug_exceptions.rb +23 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0536ef39b6fe79eef541a105295cd99516701bc54feb5d0b1e323d58e28da62e
|
4
|
+
data.tar.gz: 219c6c1b1109edca4282233e94b2b429827f1c88da172d90084c8d02b0c5ef74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13fab1b82e088b1917748c5d2547c59723680a253e9268b9f29753afac8b83df89fe952cc4125ad0ccfea8ec2c6b848a901207596fcbb94ee7563c09c7a5d91b
|
7
|
+
data.tar.gz: 024b161f76d4cced631537f3454092b53cf5ee48e72723a6825a9aa20bdf2ad59eaeeef72537d1971889ebac8652e6b29c8a9ed9bcd4123b11736814a39d08cf
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [1.2.2] - 2020-01-21
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
|
11
|
+
* Added patches to allow Rails errors to show properly in the inertia modal
|
12
|
+
* Fixed a middleware issue caused by a breaking change in Rack v2.1.*
|
13
|
+
|
7
14
|
## [1.2.1] - 2019-12-6
|
8
15
|
|
9
16
|
### Fixed
|
@@ -40,7 +40,7 @@ module InertiaRails
|
|
40
40
|
|
41
41
|
def force_refresh(request)
|
42
42
|
request.flash.keep
|
43
|
-
Rack::Response.new('', 409, {'X-Inertia-Location' => request.original_url})
|
43
|
+
Rack::Response.new('', 409, {'X-Inertia-Location' => request.original_url}).finish
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
data/lib/inertia_rails.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Patch BetterErrors::Middleware to render HTML for Inertia requests
|
2
|
+
#
|
3
|
+
# Original source:
|
4
|
+
# https://github.com/BetterErrors/better_errors/blob/v2.5.1/lib/better_errors/middleware.rb
|
5
|
+
#
|
6
|
+
|
7
|
+
if defined?(BetterErrors)
|
8
|
+
BetterErrors::Middleware.class_eval do
|
9
|
+
prepend(InertiaBetterErrors = Module.new do
|
10
|
+
def text?(env)
|
11
|
+
return false if env["HTTP_X_INERTIA"]
|
12
|
+
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
|
2
|
+
#
|
3
|
+
# Original source:
|
4
|
+
# https://github.com/rails/rails/blob/4-1-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
|
5
|
+
#
|
6
|
+
|
7
|
+
ActionDispatch::DebugExceptions.class_eval do
|
8
|
+
prepend(InertiaDebugExceptions = Module.new do
|
9
|
+
def render_exception(env, exception)
|
10
|
+
wrapper = ExceptionWrapper.new(env, exception)
|
11
|
+
log_error(env, wrapper)
|
12
|
+
|
13
|
+
if env['action_dispatch.show_detailed_exceptions']
|
14
|
+
request = Request.new(env)
|
15
|
+
template = ActionView::Base.new([RESCUES_TEMPLATE_PATH],
|
16
|
+
request: request,
|
17
|
+
exception: wrapper.exception,
|
18
|
+
application_trace: wrapper.application_trace,
|
19
|
+
framework_trace: wrapper.framework_trace,
|
20
|
+
full_trace: wrapper.full_trace,
|
21
|
+
routes_inspector: routes_inspector(exception),
|
22
|
+
source_extract: wrapper.source_extract,
|
23
|
+
line_number: wrapper.line_number,
|
24
|
+
file: wrapper.file
|
25
|
+
)
|
26
|
+
file = "rescues/#{wrapper.rescue_template}"
|
27
|
+
|
28
|
+
if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
|
29
|
+
body = template.render(template: file, layout: false, formats: [:text])
|
30
|
+
format = "text/plain"
|
31
|
+
else
|
32
|
+
body = template.render(template: file, layout: 'rescues/layout')
|
33
|
+
format = "text/html"
|
34
|
+
end
|
35
|
+
render(wrapper.status_code, body, format)
|
36
|
+
else
|
37
|
+
raise exception
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end)
|
41
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
|
2
|
+
#
|
3
|
+
# Original source:
|
4
|
+
# https://github.com/rails/rails/blob/4-2-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
|
5
|
+
#
|
6
|
+
|
7
|
+
ActionDispatch::DebugExceptions.class_eval do
|
8
|
+
prepend(InertiaDebugExceptions = Module.new do
|
9
|
+
def render_exception(env, exception)
|
10
|
+
wrapper = ExceptionWrapper.new(env, exception)
|
11
|
+
log_error(env, wrapper)
|
12
|
+
|
13
|
+
if env['action_dispatch.show_detailed_exceptions']
|
14
|
+
request = Request.new(env)
|
15
|
+
traces = wrapper.traces
|
16
|
+
|
17
|
+
trace_to_show = 'Application Trace'
|
18
|
+
if traces[trace_to_show].empty? && wrapper.rescue_template != 'routing_error'
|
19
|
+
trace_to_show = 'Full Trace'
|
20
|
+
end
|
21
|
+
|
22
|
+
if source_to_show = traces[trace_to_show].first
|
23
|
+
source_to_show_id = source_to_show[:id]
|
24
|
+
end
|
25
|
+
|
26
|
+
template = ActionView::Base.new([RESCUES_TEMPLATE_PATH],
|
27
|
+
request: request,
|
28
|
+
exception: wrapper.exception,
|
29
|
+
traces: traces,
|
30
|
+
show_source_idx: source_to_show_id,
|
31
|
+
trace_to_show: trace_to_show,
|
32
|
+
routes_inspector: routes_inspector(exception),
|
33
|
+
source_extracts: wrapper.source_extracts,
|
34
|
+
line_number: wrapper.line_number,
|
35
|
+
file: wrapper.file
|
36
|
+
)
|
37
|
+
file = "rescues/#{wrapper.rescue_template}"
|
38
|
+
|
39
|
+
if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
|
40
|
+
body = template.render(template: file, layout: false, formats: [:text])
|
41
|
+
format = "text/plain"
|
42
|
+
else
|
43
|
+
body = template.render(template: file, layout: 'rescues/layout')
|
44
|
+
format = "text/html"
|
45
|
+
end
|
46
|
+
render(wrapper.status_code, body, format)
|
47
|
+
else
|
48
|
+
raise exception
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end)
|
52
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
|
2
|
+
#
|
3
|
+
# Original source:
|
4
|
+
# https://github.com/rails/rails/blob/5-0-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
|
5
|
+
#
|
6
|
+
|
7
|
+
ActionDispatch::DebugExceptions.class_eval do
|
8
|
+
prepend(InertiaDebugExceptions = Module.new do
|
9
|
+
def render_for_default_application(request, wrapper)
|
10
|
+
template = create_template(request, wrapper)
|
11
|
+
file = "rescues/#{wrapper.rescue_template}"
|
12
|
+
|
13
|
+
if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
|
14
|
+
body = template.render(template: file, layout: false, formats: [:text])
|
15
|
+
format = "text/plain"
|
16
|
+
else
|
17
|
+
body = template.render(template: file, layout: 'rescues/layout')
|
18
|
+
format = "text/html"
|
19
|
+
end
|
20
|
+
render(wrapper.status_code, body, format)
|
21
|
+
end
|
22
|
+
end)
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
|
2
|
+
#
|
3
|
+
# Original source (unchanged since Rails 5.1):
|
4
|
+
# https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
|
5
|
+
# https://github.com/rails/rails/blob/5-2-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
|
6
|
+
# https://github.com/rails/rails/blob/6-0-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
|
7
|
+
#
|
8
|
+
|
9
|
+
ActionDispatch::DebugExceptions.class_eval do
|
10
|
+
prepend(InertiaDebugExceptions = Module.new do
|
11
|
+
def render_for_browser_request(request, wrapper)
|
12
|
+
template = create_template(request, wrapper)
|
13
|
+
file = "rescues/#{wrapper.rescue_template}"
|
14
|
+
|
15
|
+
if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
|
16
|
+
body = template.render(template: file, layout: false, formats: [:text])
|
17
|
+
format = "text/plain"
|
18
|
+
else
|
19
|
+
body = template.render(template: file, layout: "rescues/layout")
|
20
|
+
format = "text/html"
|
21
|
+
end
|
22
|
+
|
23
|
+
render(wrapper.status_code, body, format)
|
24
|
+
end
|
25
|
+
end)
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
|
2
|
+
#
|
3
|
+
# Rails has introduced text rendering for XHR requests with Rails 4.1 and
|
4
|
+
# changed the implementation in 4.2, 5.0 and 5.1 (unchanged since then).
|
5
|
+
#
|
6
|
+
# The original source needs to be patched, so that Inertia requests are
|
7
|
+
# NOT responded with plain text, but with HTML.
|
8
|
+
|
9
|
+
if defined?(ActionDispatch::DebugExceptions)
|
10
|
+
if ActionPack.version.to_s >= '5.1'
|
11
|
+
require 'patches/debug_exceptions/patch-5-1'
|
12
|
+
elsif ActionPack.version.to_s >= '5.0'
|
13
|
+
require 'patches/debug_exceptions/patch-5-0'
|
14
|
+
elsif ActionPack.version.to_s >= '4.2'
|
15
|
+
require 'patches/debug_exceptions/patch-4-2'
|
16
|
+
elsif ActionPack.version.to_s >= '4.1'
|
17
|
+
require 'patches/debug_exceptions/patch-4-1'
|
18
|
+
else
|
19
|
+
# No patch required, because text rendering for
|
20
|
+
# XHR requests was introduced with Rails 4.1:
|
21
|
+
# https://github.com/rails/rails/pull/11960
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inertia_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Knoles
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-01-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -126,6 +126,12 @@ files:
|
|
126
126
|
- lib/inertia_rails/renderer.rb
|
127
127
|
- lib/inertia_rails/rspec.rb
|
128
128
|
- lib/inertia_rails/version.rb
|
129
|
+
- lib/patches/better_errors.rb
|
130
|
+
- lib/patches/debug_exceptions.rb
|
131
|
+
- lib/patches/debug_exceptions/patch-4-1.rb
|
132
|
+
- lib/patches/debug_exceptions/patch-4-2.rb
|
133
|
+
- lib/patches/debug_exceptions/patch-5-0.rb
|
134
|
+
- lib/patches/debug_exceptions/patch-5-1.rb
|
129
135
|
homepage: https://github.com/inertiajs/inertia-rails/
|
130
136
|
licenses:
|
131
137
|
- MIT
|