🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

Issue #3202583: Views cache settings not added to headers - #10

Open
Decipher wants to merge 2 commits into
8.x-1.xfrom
feature/3202583-cache-settings-headers
Open

Issue #3202583: Views cache settings not added to headers#10
Decipher wants to merge 2 commits into
8.x-1.xfrom
feature/3202583-cache-settings-headers

Conversation

@Decipher

@Decipher Decipher commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Mirrors Drupal.org issue #3202583.

Two commits:

  1. Credit commit (authored as yahyaalhamad): applies the approach from their patch (view_cache_dependency-3202583-13.patch, comment 11) — deriving the JSON:API response's cacheable metadata from the view's own render array via CacheableMetadata::createFromRenderArray().
  2. Follow-up (authored as deciphered): keeps the original access-check-before-execution ordering instead of the patch's execute-first approach (avoids running the view's query for denied requests), removes the now-dead BubbleableMetadata handling, and generalizes the test suite's assertCacheContext() helper to walk the full cache-context ancestor chain (this fix surfaces a broader url context that collapses the narrower url.query_args:* contexts under Drupal's cache-context optimizer, which the helper didn't previously recognize).

Verified on Drupal 10 and 11, and via the gitlab.local DrupalCI-mirror pipeline (real DB service): pipeline #1314, all green.

Summary by CodeRabbit

  • Bug Fixes
    • Improved caching behavior for rendered views and successful responses.
    • Ensured access-denied responses retain the correct cache metadata without executing the view.
    • Improved handling of cache contexts, including progressively broader context variations.

yahyaalhamad and others added 2 commits August 4, 2026 00:04
…ders

Derive the JSON:API response's cacheable metadata from the view's own
render array via CacheableMetadata::createFromRenderArray(), which
already aggregates cache tags, contexts, and max-age from every Views
plugin and handler that implements CacheableDependencyInterface. Fixes
missing cache contexts (e.g. `user`, for contextual filters defaulting
to the current user) that were causing the same cached response to be
served across different users.

Patch: https://www.drupal.org/files/issues/2024-11-20/view_cache_dependency-3202583-13.patch

Applied by deciphered on behalf of yahyaalhamad, credited as author.

Fixes #3202583
Keep the original access-check-before-execution ordering rather than
patch #13's approach (execute first, reuse one cacheable metadata
object for both the 403 and 200 paths) — that runs the view's query
even for requests that end up denied. The 403 path now derives its
own cacheability via $view->getDisplay()->getCacheMetadata() instead,
the same aggregation, without requiring execution. This also adds
cache contexts (not just the static config:views.view.<id> tag) to
the denial response for the first time, since access checks can
themselves depend on contexts the view contributes (e.g. `user`).

Also removes the now-fully-dead BubbleableMetadata::createFromObject()
handling in the 200 path (patch #13 worked around it rather than
removing it), and generalizes
JsonapiViewsResourceTest::assertCacheContext() to walk the full
cache-context ancestor chain: this fix surfaces broader contexts (bare
`url`, from Views' own exposed-form/pager plugins) that Drupal's cache
context optimizer uses to collapse the narrower explicit
url.query_args:* contexts this module adds, which the test helper
only checked one level of (added in #3587949 for the narrower
url.query_args case).

Fixes #3202583
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 177ea0f3-564d-44e3-90c6-14bc6350e6de

📥 Commits

Reviewing files that changed from the base of the PR and between 3e50d79 and e798075.

📒 Files selected for processing (3)
  • .cspell.json
  • src/Resource/ViewsResource.php
  • tests/src/Functional/JsonapiViewsResourceTest.php

📝 Walkthrough

Walkthrough

Views resource responses now derive cacheability from display metadata, rendered output, and bubbled render metadata. Functional cache-context assertions now support hierarchical contexts. The spelling dictionary includes yahyaalhamad.

Changes

Views response cacheability

Layer / File(s) Summary
Render-derived response cacheability
src/Resource/ViewsResource.php
Access-denied responses use display metadata and the view configuration cache tag. Successful responses use the preview render result and bubbled render metadata.
Cache-context validation and spelling support
tests/src/Functional/JsonapiViewsResourceTest.php, .cspell.json
Cache-context assertions check progressively broader dotted contexts. The spelling dictionary includes yahyaalhamad.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ViewsResource
  participant ViewDisplay
  participant RenderContext
  ViewsResource->>ViewDisplay: check access or execute view
  ViewDisplay->>RenderContext: render preview and bubble metadata
  RenderContext->>ViewsResource: return render result and bubbled metadata
  ViewsResource->>ViewsResource: attach cache metadata to response
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the issue and the main change: adding Views cache settings to response headers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/3202583-cache-settings-headers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.98%. Comparing base (3e50d79) to head (e798075).

Additional details and impacted files
@@             Coverage Diff             @@
##           8.x-1.x      #10      +/-   ##
===========================================
- Coverage    94.11%   93.98%   -0.14%     
===========================================
  Files            3        3              
  Lines          136      133       -3     
===========================================
- Hits           128      125       -3     
  Misses           8        8              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant