react_on_rails_pro 17.0.0.rc.7 → 17.0.0.rc.8
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 +4 -4
- data/Gemfile.lock +3 -3
- data/app/helpers/react_on_rails_pro_helper.rb +31 -13
- data/lib/react_on_rails_pro/cache.rb +0 -40
- data/lib/react_on_rails_pro/version.rb +1 -1
- data/sig/react_on_rails_pro/cache.rbs +0 -6
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6013b40c199b7e3a943a2b2d77321d8f5481d9f6e5a63b9d02d8a52e1d91753b
|
|
4
|
+
data.tar.gz: e33168cb4f032e3ea0fcd9668eef969e0769dac6b9fb6d62da622205f9e1f9eb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c99af25077139ada7aa948a235c0020f95ae007ce0c4294bf73a4f12e561d63dd6138bb3f5b5e13cd52deffdc4c8b3d1fa5b8c892df47adde5fcd40d4a947762
|
|
7
|
+
data.tar.gz: 40d17fa6a656718d015ab0195974a135d199ea11c6db12b63ac4e3be5636bcf531fcc103908c1625facd68728e2f0ddc855d4c02b6fa4b6c52f123604ea7c6b4
|
data/Gemfile.lock
CHANGED
|
@@ -9,7 +9,7 @@ GIT
|
|
|
9
9
|
PATH
|
|
10
10
|
remote: ..
|
|
11
11
|
specs:
|
|
12
|
-
react_on_rails (17.0.0.rc.
|
|
12
|
+
react_on_rails (17.0.0.rc.8)
|
|
13
13
|
addressable
|
|
14
14
|
connection_pool
|
|
15
15
|
execjs (~> 2.5)
|
|
@@ -20,14 +20,14 @@ PATH
|
|
|
20
20
|
PATH
|
|
21
21
|
remote: .
|
|
22
22
|
specs:
|
|
23
|
-
react_on_rails_pro (17.0.0.rc.
|
|
23
|
+
react_on_rails_pro (17.0.0.rc.8)
|
|
24
24
|
async (>= 2.29)
|
|
25
25
|
async-http (~> 0.95)
|
|
26
26
|
execjs (~> 2.9)
|
|
27
27
|
io-endpoint (~> 0.17.0)
|
|
28
28
|
jwt (>= 2.5, < 4)
|
|
29
29
|
nokogiri (>= 1.12, < 2)
|
|
30
|
-
react_on_rails (= 17.0.0.rc.
|
|
30
|
+
react_on_rails (= 17.0.0.rc.8)
|
|
31
31
|
|
|
32
32
|
GEM
|
|
33
33
|
remote: https://rubygems.org/
|
|
@@ -46,19 +46,6 @@ module ReactOnRailsProHelper
|
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def fetch_react_component(component_name, options, &)
|
|
50
|
-
ReactOnRailsPro::Cache.fetch_react_component(
|
|
51
|
-
component_name,
|
|
52
|
-
options,
|
|
53
|
-
{
|
|
54
|
-
on_cache_hit: lambda do |cached_component_name, cached_options|
|
|
55
|
-
load_pack_for_cached_react_component(cached_component_name, cached_options)
|
|
56
|
-
end
|
|
57
|
-
},
|
|
58
|
-
&
|
|
59
|
-
)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
49
|
# Provide caching support for react_component in a manner akin to Rails fragment caching.
|
|
63
50
|
# All the same options as react_component apply with the following difference:
|
|
64
51
|
#
|
|
@@ -446,6 +433,37 @@ module ReactOnRailsProHelper
|
|
|
446
433
|
|
|
447
434
|
private
|
|
448
435
|
|
|
436
|
+
def fetch_react_component(component_name, options)
|
|
437
|
+
return yield unless ReactOnRailsPro::Cache.use_cache?(options)
|
|
438
|
+
|
|
439
|
+
cache_key = ReactOnRailsPro::Cache.react_component_cache_key(component_name, options)
|
|
440
|
+
Rails.logger.debug { "React on Rails Pro cache_key is #{cache_key.inspect}" }
|
|
441
|
+
cache_options = ReactOnRailsPro::Cache.cache_write_options(options[:cache_options])
|
|
442
|
+
if ReactOnRailsPro::Cache.cache_write_expired?(options[:cache_options])
|
|
443
|
+
return add_component_cache_metadata(yield, cache_key, false)
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
cache_hit = true
|
|
447
|
+
normalized_cache_tags = []
|
|
448
|
+
result = Rails.cache.fetch(cache_key, cache_options) do
|
|
449
|
+
cache_hit = false
|
|
450
|
+
normalized_cache_tags = ReactOnRailsPro::Cache.normalize_tags(options[:cache_tags])
|
|
451
|
+
yield
|
|
452
|
+
end
|
|
453
|
+
ReactOnRailsPro::Cache.register_normalized_tags(normalized_cache_tags, cache_key, cache_options) unless cache_hit
|
|
454
|
+
load_pack_for_cached_react_component(component_name, options) if cache_hit
|
|
455
|
+
|
|
456
|
+
add_component_cache_metadata(result, cache_key, cache_hit)
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
def add_component_cache_metadata(result, cache_key, cache_hit)
|
|
460
|
+
return result unless result.is_a?(Hash)
|
|
461
|
+
|
|
462
|
+
result[:RORP_CACHE_KEY] = cache_key
|
|
463
|
+
result[:RORP_CACHE_HIT] = cache_hit
|
|
464
|
+
result
|
|
465
|
+
end
|
|
466
|
+
|
|
449
467
|
def load_pack_for_cached_react_component(component_name, options)
|
|
450
468
|
render_options = ReactOnRails::ReactComponent::RenderOptions.new(
|
|
451
469
|
react_component_name: component_name,
|
|
@@ -23,32 +23,6 @@ module ReactOnRailsPro
|
|
|
23
23
|
RSC_BUNDLE_MISSING_CACHE_KEY = "rsc-bundle-missing"
|
|
24
24
|
|
|
25
25
|
class << self
|
|
26
|
-
# options[:cache_options] can include :compress, :expires_in, :race_condition_ttl and
|
|
27
|
-
# other options
|
|
28
|
-
def fetch_react_component(component_name, options = nil, callback_options = nil)
|
|
29
|
-
options ||= {}
|
|
30
|
-
on_cache_hit = cache_hit_callback(callback_options)
|
|
31
|
-
|
|
32
|
-
return yield unless use_cache?(options)
|
|
33
|
-
|
|
34
|
-
cache_key = react_component_cache_key(component_name, options)
|
|
35
|
-
Rails.logger.debug { "React on Rails Pro cache_key is #{cache_key.inspect}" }
|
|
36
|
-
cache_options = cache_write_options(options[:cache_options])
|
|
37
|
-
return add_component_cache_metadata(yield, cache_key, false) if cache_write_expired?(options[:cache_options])
|
|
38
|
-
|
|
39
|
-
cache_hit = true
|
|
40
|
-
normalized_cache_tags = []
|
|
41
|
-
result = Rails.cache.fetch(cache_key, cache_options) do
|
|
42
|
-
cache_hit = false
|
|
43
|
-
normalized_cache_tags = normalize_tags(options[:cache_tags])
|
|
44
|
-
yield
|
|
45
|
-
end
|
|
46
|
-
register_normalized_tags(normalized_cache_tags, cache_key, cache_options) unless cache_hit
|
|
47
|
-
on_cache_hit&.call(component_name, options) if cache_hit
|
|
48
|
-
|
|
49
|
-
add_component_cache_metadata(result, cache_key, cache_hit)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
26
|
# Registers cache tags for an already-written cache entry so a later
|
|
53
27
|
# ReactOnRailsPro.revalidate_tag can delete it. Call after a successful
|
|
54
28
|
# cache write (never on a cache hit). No-op when tags are nil or [].
|
|
@@ -126,20 +100,6 @@ module ReactOnRailsPro
|
|
|
126
100
|
|
|
127
101
|
private
|
|
128
102
|
|
|
129
|
-
def cache_hit_callback(callback_options)
|
|
130
|
-
return nil unless callback_options
|
|
131
|
-
|
|
132
|
-
callback_options[:on_cache_hit]
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def add_component_cache_metadata(result, cache_key, cache_hit)
|
|
136
|
-
return result unless result.is_a?(Hash)
|
|
137
|
-
|
|
138
|
-
result[:RORP_CACHE_KEY] = cache_key
|
|
139
|
-
result[:RORP_CACHE_HIT] = cache_hit
|
|
140
|
-
result
|
|
141
|
-
end
|
|
142
|
-
|
|
143
103
|
def meaningful_revalidation_tags(tags)
|
|
144
104
|
tags.flat_map do |tag|
|
|
145
105
|
if tag.is_a?(Array)
|
|
@@ -13,12 +13,6 @@
|
|
|
13
13
|
|
|
14
14
|
module ReactOnRailsPro
|
|
15
15
|
class Cache
|
|
16
|
-
def self.fetch_react_component: (
|
|
17
|
-
String component_name,
|
|
18
|
-
?Hash[Symbol, untyped] options,
|
|
19
|
-
?Hash[Symbol, untyped] callback_options
|
|
20
|
-
) { () -> untyped } -> untyped
|
|
21
|
-
|
|
22
16
|
def self.use_cache?: (Hash[Symbol, untyped] options) -> bool
|
|
23
17
|
|
|
24
18
|
def self.base_cache_key: (String type, ?prerender: bool?) -> Array[String]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: react_on_rails_pro
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 17.0.0.rc.
|
|
4
|
+
version: 17.0.0.rc.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Gordon
|
|
@@ -111,14 +111,14 @@ dependencies:
|
|
|
111
111
|
requirements:
|
|
112
112
|
- - '='
|
|
113
113
|
- !ruby/object:Gem::Version
|
|
114
|
-
version: 17.0.0.rc.
|
|
114
|
+
version: 17.0.0.rc.8
|
|
115
115
|
type: :runtime
|
|
116
116
|
prerelease: false
|
|
117
117
|
version_requirements: !ruby/object:Gem::Requirement
|
|
118
118
|
requirements:
|
|
119
119
|
- - '='
|
|
120
120
|
- !ruby/object:Gem::Version
|
|
121
|
-
version: 17.0.0.rc.
|
|
121
|
+
version: 17.0.0.rc.8
|
|
122
122
|
- !ruby/object:Gem::Dependency
|
|
123
123
|
name: bundler
|
|
124
124
|
requirement: !ruby/object:Gem::Requirement
|