sinatra-inertia 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7de309624cb7ee8a887b982e7d020e486719b96defded22dd65ce6bcf453182e
4
- data.tar.gz: ce297cacb5f432432ebc1fc4f9a18676debb86f282a229bfef275fda4cf1c13a
3
+ metadata.gz: 52d1f4d245c4bc1d97964a1b6b92a8dc091cde035738df4b8fc1b8bcf8017b8f
4
+ data.tar.gz: 7237b568ccdb58addccffbcb20a51da0ade11d49ab2fa4dc35acc9c698444c1d
5
5
  SHA512:
6
- metadata.gz: 73a205b6715443da834849840c7b84dbceb18f7cf7527c23cb647c0808a3c5c29c074ed96e18d4ac90a1303a26aa59f80f71d4c5b00b32364ef0565d0b8a113c
7
- data.tar.gz: 48edc99e03cfbdeeb674099d369f81ee415b5838b139d7f208076804cb64d5d94dcd989b1ad3bf21538973d4491b3323d2c9f17d4f6b4c93f0cad7f489830618
6
+ metadata.gz: 868d4070d399099ff8e31643d90aa8488dcd34dacf1e2e580c579547d0d599e4a3c117cf91e23e70cff58684be566ed4cd6c42857aae19f7c21bc0d3109a0c33
7
+ data.tar.gz: ff829335676a68745d9a2c450d24f53ac08798b089e547619a416e63e9695ca2f4038d5c5b8b2646acefa3a82d8ef9c94ce4a6241eb13ad9dbd2196998acf61f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.2 — 2026-04-29
4
+
5
+ - Fix: under Opal/Workers, the Inertia visit JSON body shipped with
6
+ `Content-Type: text/html` and missing `X-Inertia: true` /
7
+ `Vary: X-Inertia` headers. `Response#to_h` is an async function
8
+ (it `await`s any Proc-returned JS Promise), so the rest of the
9
+ `inertia` helper ran after a JS-level suspend; Sinatra finalised
10
+ the response with default headers before the awaited continuation
11
+ set them. We now set the protocol headers *before* touching
12
+ `to_h`, so the response's content type and Inertia headers are in
13
+ place regardless of how the runtime schedules the resumption.
14
+ Pure-MRI behaviour is unchanged.
15
+
3
16
  ## 0.1.1 — 2026-04-29
4
17
 
5
18
  - Add `spec.metadata['homura.auto_await'] = 'true'` so that when this
@@ -31,6 +31,19 @@ module Sinatra
31
31
  end
32
32
  clear = @inertia_clear_history == true
33
33
 
34
+ # Set the protocol response headers BEFORE we touch any async
35
+ # `to_h` resolution. Under Opal, `Response#to_h` is an `async`
36
+ # function (it `await`s any Proc-returned JS Promise), so the
37
+ # rest of this method runs after a JS-level suspend. Setting
38
+ # `content_type` / `X-Inertia` before the suspend guarantees
39
+ # Sinatra's dispatch sees them when it finalises the response,
40
+ # regardless of how the underlying runtime schedules the
41
+ # awaited continuation.
42
+ if inertia_request?
43
+ content_type 'application/json; charset=utf-8'
44
+ headers 'X-Inertia' => 'true', 'Vary' => 'X-Inertia'
45
+ end
46
+
34
47
  # Read errors *before* sweeping so the response carries them, then
35
48
  # sweep immediately so the next request sees a clean slate. The
36
49
  # sweep must happen before any further session writes that the
@@ -52,12 +65,7 @@ module Sinatra
52
65
  page_hash = response_obj.to_h
53
66
  page_json = page_hash.to_json
54
67
 
55
- if inertia_request?
56
- content_type 'application/json; charset=utf-8'
57
- headers['X-Inertia'] = 'true'
58
- headers['Vary'] = 'X-Inertia'
59
- return page_json
60
- end
68
+ return page_json if inertia_request?
61
69
 
62
70
  @page = page_hash
63
71
  @page_json = ::Rack::Utils.escape_html(page_json)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sinatra
4
4
  module Inertia
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-inertia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuhiro Homma