view_component 4.22.0 → 4.23.0

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: 347185365d72f04ae47e10751bdaafc79ca1b92a5cc60659464cd91ea3fe5b1d
4
- data.tar.gz: 8cc35ca70babcf15504c6cf3329357045b92cf5bce0b7059a376b465b9d82b3a
3
+ metadata.gz: d782aede72b310a730951e5b9357dcf8b02184f4d459d0ef0c7106671bfa80a1
4
+ data.tar.gz: 6edb2094b07d7245782cb1d1292dbd7983e70ce5d1872165a4bae99bde537275
5
5
  SHA512:
6
- metadata.gz: 1f65ef1db7168f46ff4c0e41bcd7d329e30f5da9cfb05b06500c67686eaef0705b9b26433f644b39138c79ecf5d904176451c511f8dc48438cae9d9d6cbe81f8
7
- data.tar.gz: 5b8df5a1f324a0fb481da6c822333e08e0bd424535310d851634da151702cb50a6a92d56be23f49f573c66aa5b9f9b8137a288969d85f4d5cec47ea59c114cca
6
+ metadata.gz: f9fbe9cd4bfdb862d5a6d2bda711380d43abbf744af542b09158f57adf0c5de0b32002fcd7710859743cc3abe80fce416f4280c638a0b436dd5495beff4c0269
7
+ data.tar.gz: '09cf2dd6d5b054283943b02feecd1037bc41cfcac37553ef1bc4823d32ab4e34ac2bb469105579d6144ec76972944c7ac5ace6bd4c711e5bdff1cc4e1b1227b7'
data/docs/CHANGELOG.md CHANGED
@@ -10,6 +10,16 @@ nav_order: 6
10
10
 
11
11
  ## main
12
12
 
13
+ ## 4.23.0
14
+
15
+ * Restore request-dependent URL generation when using `render_preview` inside `with_request_url`.
16
+
17
+ *Joel Hawksley*
18
+
19
+ * Speed up cold cache digests by skipping the `# Template Dependency:` scan for sources that declare none, and by not translating class names in synthetic templates, which only declare paths.
20
+
21
+ *Erik Axel Nielsen*
22
+
13
23
  ## 4.22.0
14
24
 
15
25
  * Comment on release pull requests with benchmark results compared to the previous release.
@@ -21,6 +21,10 @@ module ViewComponent
21
21
  dependencies = super
22
22
  source = template.source
23
23
 
24
+ # Synthetic templates already declare every dependency found in their
25
+ # sources, as paths.
26
+ next dependencies if name.start_with?("#{CacheDigest::VIRTUAL_PATH_PREFIX}/")
27
+
24
28
  # `# Template Dependency: SomeComponent` names a class, which Rails
25
29
  # would resolve as a template path and never find. Swap it for the path
26
30
  # the component is digested under, so the declaration resolves instead
@@ -29,8 +33,6 @@ module ViewComponent
29
33
  dependencies = dependencies - [declared] + [virtual_path]
30
34
  end
31
35
 
32
- # Synthetic templates already declare every dependency found in their sources.
33
- next dependencies if name.start_with?("#{CacheDigest::VIRTUAL_PATH_PREFIX}/")
34
36
  next dependencies unless CacheDigest.template_dependencies?(source, template.handler)
35
37
 
36
38
  component_paths, inferred_partials =
@@ -184,6 +184,10 @@ module ViewComponent
184
184
 
185
185
  def explicit_dependencies(sources)
186
186
  sources.flat_map { |source|
187
+ # A cheap check first: most sources declare nothing, and the
188
+ # pattern is slow to scan for in sources with many comments.
189
+ next [] unless source.include?("Template Dependency:")
190
+
187
191
  declared = source.scan(CacheDigest::EXPLICIT_DEPENDENCY).flatten
188
192
 
189
193
  # Component class names are translated to the path they're digested
@@ -89,14 +89,16 @@ module ViewComponent
89
89
  controller_class = Rails.application.config.view_component.previews.controller.constantize
90
90
  request = ActionDispatch::TestRequest.new(vc_test_request.env.dup)
91
91
  query_parameters = vc_test_request.query_parameters.deep_dup.merge(params.stringify_keys)
92
- request.path_parameters = vc_test_request.path_parameters.except(*params.keys.map(&:to_sym)).merge(
93
- controller: controller_class.controller_path,
94
- action: "previews",
95
- path: "#{from.preview_name}/#{name}"
96
- )
92
+ request.path_parameters = vc_test_request.path_parameters.deep_dup
97
93
  request.set_header("action_dispatch.request.query_parameters", query_parameters)
98
94
  request.set_header(Rack::QUERY_STRING, query_parameters.to_query)
99
95
  previews_controller = __vc_test_helpers_build_controller(controller_class, request: request)
96
+ # Dispatch the preview without replacing the request's URL generation context.
97
+ previews_controller.params = request.parameters.merge(params.stringify_keys).merge(
98
+ "controller" => controller_class.controller_path,
99
+ "action" => "previews",
100
+ "path" => "#{from.preview_name}/#{name}"
101
+ )
100
102
  previews_controller.set_response!(ActionDispatch::Response.new)
101
103
  previews_controller.process(:previews)
102
104
  @rendered_content = previews_controller.response.body
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 4
6
- MINOR = 22
6
+ MINOR = 23
7
7
  PATCH = 0
8
8
  PRE = nil
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.22.0
4
+ version: 4.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ViewComponent Team