Problem/Motivation
Core marked any entity form as uncacheable (max-age = 0) in #2578855: Form tokens are now rendered lazily, allow forms to opt in to be cacheable and this will be fixed in #3395524: Make entity forms cacheable.
However, after upgrading to Drupal 11 and seeing the flow on effects on our projects, I think we should manually remove this max-age in WebformSubmissionForm and opt back in to caching.
If you are using Webform on Drupal 11 with https://www.drupal.org/project/cache_control_override you will get pages without a max-age set in the Cache-Control header resulting in pages being uncacheable by the CDN (bad).
WebformSubmissionForms are cached in D10.4 and I don't think any of the issues that #3395524: Make entity forms cacheable will tackle will really apply to Webforms.
Steps to reproduce
- Install Standard profile
- Install webform 6.3.x
- Install webform_node
- Add a Webform node and reference the Contact form
- Visit the node and check headers, see that
X-Drupal-Cache-Max-Age: 0 (Uncacheable). Note this header is only available whenhttp.response.debug_cacheability_headersis enabled
Proposed resolution
Prevent max-age=0 from bubbling for anonymous users to restore caching on CDN
Issue fork webform-3505669
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
acbramley commentedComment #4
acbramley commentedComment #5
acbramley commentedGonna be a bit trickier than I first expected by the looks of the test failures. It seems like some things perhaps aren't setting the cacheable metadata that they should be on Webform's end and were just coincidentally passing before.
Comment #6
pminf@acbramley Is this a general issue with Webform in Drupal 11 or just in combination with cache_control_override?
Comment #7
acbramley commented@pminf unrelated to cache_control_override, it's just webform + D11
Comment #9
j-leeIs #3538483: Form build caching is broken in Drupal 11 a duplicated or a related issue?
Comment #10
bkosborneThis seems like it's a feature request, not a bug?
In any case, I'm confused. Webforms ARE currently being cached in D11 (which has led to the bug reported in #3538483: Form build caching is broken in Drupal 11).
Core is only marking the form as uncacheable (max-age = 0) if the form doesn't already have a max-age set.
But webform submissions forms DO have a max-age set as I described in this comment.
Comment #11
bkosborneComment #12
acbramley commentedIt's definitely a bug, they were cacheable pre D11. And the line of code you linked to is not the bit that sets them as uncacheable, that's here
At least, this was the state of webform caching when I opened this issue.
Comment #13
acbramley commentedConfirmed with a fresh install. Updated steps to reproduce.
Comment #14
bkosborneOkay, I was conflating this a bit with #3538483: Form build caching is broken in Drupal 11 which has other circumstances that are leading to cache issues.
First I think we need to define what "cacheable" means here. I think for the purpose of this issue it means that the form doesn't bubble up a max-age of 0. That would make it uncacheble by Dynamic Page Cache, and it would also make it uncacheable by your CDN if you were using the Cache Control Override module which exposes that max-age to the cache header response (Drupal doesn't do this normally).
I agree that prior to core issue #2578855: Form tokens are now rendered lazily, allow forms to opt in to be cacheable, anonymous visits to a webform were cacheable and didn't have max-age=0. Authenticated visits wouldn't have been cacheable (by dynamic page cache) because the CSRF form token got added and had a hardcoded max-age=0 which bubbled up. After that core issue, the webform submission form has a forced max-age=0 regardless of there being a CSRF for token added or not.
Comment #15
bkosborneComment #16
liam morlandComment #17
bkosborneI took a brief look at the failing test and it's related to the added cache context for the user authenticated role. It wasn't a simple/obvious fix. I may get to it this coming week.
Comment #19
liam morlandThis issue and #3561066: Set max-age:0 for authenticated users to exclude Webforms from Dynamic page cache are classed as release-blockers for 6.3.0. Are the caching issues big enough that they ought to be release-blockers? Is there anyone able to look at this?
Comment #20
bkosborneYes IMO this should 100% be a release blocker
Comment #21
liam morlandComment #22
thiagomoraesp commentedConfirmed here for logged in users, the entire page got
x-drupal-cache-max-age: 0 (Uncacheable)
The form is being showed on a paragraph using entity reference.
Have discovered a workaround on my specific scenario, use the "Use a lazy builder to render the form after the page is built/loaded." option on the entity reference content display and it should display the form and cache the page :D
Comment #23
liam morlandTests are not passing. This likely needs to be solved in tandem with #3561066: Set max-age:0 for authenticated users to exclude Webforms from Dynamic page cache.
Comment #24
jwineichen commentedTesting at DrupalCon Chicago 2026, running through the steps:
Comment #25
rachel_norfolkCorrecting the issue tag for DrupalCon
Comment #26
idebr commentedThe issue summary made the scope of this issue seem a bit bigger that it actually is:
page_cachemodule caches pages with a Webform regardless of max-age, at least until #2352009: Bubbling of elements' max-age to the page's headers and the page cache is fixed in CoreI have updated the issue summary to limit the scope to anonymous users to fix only the bubbling of max-age=0.
Comment #27
idebr commentedThe code changes are now limited in scope to anonymous users.
Comment #28
j-leeCode looks fine to me. But I can not test it on a CDN.
Comment #29
luke.leberSetting back to NW based on review over in Gitlab.