react-manifest-rails 0.3.1 → 0.3.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: adc189b9603ad36c8d986e8f90cac383fcb65cfabafc60d64b3155681cd21ca7
4
- data.tar.gz: 3cd94fbc6573c1548753ece80674a42d476619f7553b4fedffdd7d3b631cbe16
3
+ metadata.gz: d5ea479337143141722feeaa26cbf9e8d46e2158c399f5d29f4cb6bc5dbbdcd7
4
+ data.tar.gz: 0d4983f0b8ec3c35d7165fbfe801fc3f73286868e88bca1da83e76f6dcf963ce
5
5
  SHA512:
6
- metadata.gz: b382bb1ae0d2d9464402dbca4cacc0294897eea15e4a9a9917c447219ad8e5788ed22a2062d4dd2f28c7635c8e09ba2629972d8fc04a0e3b22d6769d87ec7a2c
7
- data.tar.gz: f32f2baa961dbcb50b048191ed46e81f5ea7f016994355b2cba3a332b7f846e7f889df41cbc3fefb5364e8a7c3189484f3181058d825e6935ca6fc9ddced033e
6
+ metadata.gz: dfeba95401019cb1233677138d89b99d9c286d55c89edc74fd1e9f10e4ade37f0038cfede9d12045a43d0143355c622c9c746178d0a8da75c3c6cf97e62b9a79
7
+ data.tar.gz: 29159646362cbdb7be57a57fdc77fd61010e607c7dfe2214f65e301b352b44914e1749304bb0f6e457b2cab97f0627f34ea5dfbbef1597ed3a93951069389baa
data/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.2] - 2026-10-13
11
+
12
+ ### Added
13
+ - `react_component` adds `data-react-persist="true"` to the root element when it runs after
14
+ `react_bundle_tag` in the same request. That is a component in the layout body (navbar,
15
+ footer, sidebar), since Rails renders the template first. A Turbolinks wrapper can keep it
16
+ mounted across visits and pass it new props. Template components are never marked.
17
+
10
18
  ## [0.3.1] - 2026-10-13
11
19
 
12
20
  ### Added
@@ -1,3 +1,3 @@
1
1
  module ReactManifest
2
- VERSION = "0.3.1".freeze
2
+ VERSION = "0.3.2".freeze
3
3
  end
@@ -18,6 +18,8 @@ module ReactManifest
18
18
  INLINE_BUNDLE_TAG = %r{<script\b[^>]*\sdata-react-manifest="([^"]*)"[^>]*></script>}
19
19
 
20
20
  def react_bundle_tag(**html_options)
21
+ request_store["react_manifest.bundle_tag_rendered"] = true
22
+
21
23
  # controller_path is not available in all view contexts (mailers, engines,
22
24
  # views rendered outside a request). Fall back gracefully rather than raising.
23
25
  ctrl = respond_to?(:controller_path, true) ? controller_path : nil
@@ -46,8 +48,11 @@ module ReactManifest
46
48
  # If a component-specific controller bundle can be inferred from the component
47
49
  # symbol, include that bundle at the call site before delegating to react-rails.
48
50
  # This avoids strict dependence on controller_path -> bundle naming alignment.
51
+ #
52
+ # A call after react_bundle_tag is in the layout body (page chrome), so its root gets
53
+ # data-react-persist: a Turbolinks wrapper keeps it mounted and hands it new props.
49
54
  def react_component(*args, **kwargs, &block)
50
- html = super
55
+ html = bundle_tag_rendered? ? super(*persistent_args(args, kwargs), &block) : super
51
56
 
52
57
  component_name = args.first
53
58
  bundles = ReactManifest.resolve_bundles_for_component_direct(component_name)
@@ -69,6 +74,18 @@ module ReactManifest
69
74
 
70
75
  private
71
76
 
77
+ def bundle_tag_rendered?
78
+ request_store["react_manifest.bundle_tag_rendered"]
79
+ end
80
+
81
+ # react-rails takes (name, props = {}, options = {}); trailing keywords fill the next slot.
82
+ def persistent_args(args, kwargs)
83
+ name, props, options = kwargs.empty? ? args : [*args, kwargs]
84
+ options = { tag: options } if options.is_a?(Symbol)
85
+ options ||= {}
86
+ [name, props || {}, options.merge(data: { react_persist: true }.merge(options[:data] || {}))]
87
+ end
88
+
72
89
  # Turbolinks 5 full-reloads when the tracked head elements differ between pages.
73
90
  # ux_shared is identical on every page, so tracking it forces one reload per deploy;
74
91
  # tracking controller bundles would reload on every cross-controller visit.
@@ -105,12 +122,16 @@ module ReactManifest
105
122
  end
106
123
 
107
124
  def emitted_bundles
108
- # ActionView can instantiate multiple helper contexts during one request.
109
- # Store emitted bundles in request env so layout + template helpers dedupe.
125
+ request_store["react_manifest.emitted_bundles"] ||= []
126
+ end
127
+
128
+ # ActionView can instantiate multiple helper contexts during one request.
129
+ # Request env is shared by layout + template helpers; fall back to the view itself.
130
+ def request_store
110
131
  if respond_to?(:request, true) && request
111
- request.env["react_manifest.emitted_bundles"] ||= []
132
+ request.env
112
133
  else
113
- @emitted_bundles ||= []
134
+ @request_store ||= {}
114
135
  end
115
136
  end
116
137
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react-manifest-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Noonan