Problem/Motivation

#3538483: Form build caching is broken in Drupal 11 addressed some caching bugs caused by this core change in Drupal 11 #2578855: Form tokens are now rendered lazily, allow forms to opt in to be cacheable, but it didn't solve all the issues.

See my comment in the other issue for a more detailed explanation.

Steps to reproduce

  1. Spin up a new Drupal 11 test site
  2. Install Webform 6.3.x
  3. Enable the dynamic_page_cache module
  4. Create a Webform "Test Webform", can just be a single checkbox field.
  5. Under the webforms Settings -> Submissions, set Submission limit settings -> Per user -> Per user submission limit to be 1
  6. Create 2 new user accounts, "user1" and "user2" (no roles needed)
  7. Add the webform as a block on a page somewhere on the site
  8. Submit form as "user1". Visit form again and observe you get message indicating form is closed (good).
  9. Visit form as "user2". Get message indicating form is closed (bad). This closed message was cached by user1's request and it shouldn't have been.

Proposed resolution

Short term, for authenticated users, ensure that max-age=0 is set on the form. This restores behavior that Drupal 10 had.

Longer term, in the follow-up #3583047: [Drupal 11.1+] Integrate with Dynamic page cache, we need to ensure all the proper cache contexts are set on the form in every situation. This is especially important These means examining all code paths that depend on some external context (user data, query string params, url, etc). It's possible we're missing a bunch and were getting away with it because core was making the entire form uncacheable anyway.

We for sure know we were missing the user cache context which led to this bug that #3538483: Form build caching is broken in Drupal 11 attempted to fix. The fix there added the cache contexts in the wrong area (and added it to ALWAYS even if the feature for per-user submission limit was off) though so that at least needs to be fixed. However just adding user cache context here is probably not enough. The feature that sets individual user submission limits needs to also be aware of how much TIME has passed, since that feature lets you say for example "this user can submit 1 submission per 5 minutes". In that case the form caching should be disabled entirely anyway.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#20 Screenshot_20260413_230624.png215.31 KBmxr576

Issue fork webform-3561066

Command icon 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

bkosborne created an issue. See original summary.

bkosborne’s picture

liam morland’s picture

Title: Additional changes needed to fix caching issues in Drupal 11 » Fix caching issues in Drupal 11
Issue tags: +Drupal 11 compatibility

bkosborne’s picture

Status: Active » Needs review

Submitted an MR with the short term fix to restore caching behavior that Drupal 10 had, which is that max-age=0 is set for authenticated users. To restate: D10 added max-age=0 to entity forms for authenticated users. D11 doesn't do that anymore. Without that, caching bugs in Webform are revealed (missing cache contexts).

I also updated the existing test added in #3538483: Form build caching is broken in Drupal 11 to prove that this change was needed. Without this change, the test changes I made show a failure.

bkosborne’s picture

Issue summary: View changes
bkosborne’s picture

Issue summary: View changes
liam morland’s picture

Status: Needs review » Needs work

Tests are not passing.

idebr made their first commit to this issue’s fork.

liam morland’s picture

This issue and #3505669: Prevent max-age=0 from bubbling for anonymous users to restore caching on CDN 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?

bkosborne’s picture

Yes IMO this should 100% be a release blocker

liam morland’s picture

liam morland’s picture

Tests are not passing. This likely needs to be solved in tandem with #3505669: Prevent max-age=0 from bubbling for anonymous users to restore caching on CDN.

byrond made their first commit to this issue’s fork.

jwineichen’s picture

Issue tags: +Drupalcon Chicago 2026

Testing at DrupalCon Chicago 2026, the 1e5fa74c commit successfully fixes the caching issue for me.

liam morland’s picture

Just that commit and not the other changes? If so, please update the merge request and see if the tests will pass.

rachel_norfolk’s picture

Issue tags: -Drupalcon Chicago 2026 +Chicago2026

Correcting the issue tag for DrupalCon

idebr’s picture

Title: Fix caching issues in Drupal 11 » Set max-age:0 for authenticated users to exclude Webforms from Dynamic page cache
Status: Needs work » Needs review
Related issues: +#3583047: [Drupal 11.1+] Integrate with Dynamic page cache

I updated the issue summary to limit the scope to the short term solution: ensure that max-age=0 is set on the form. This is also the current behavior for Drupal 10.

I created a follow-up to integrate with Dynamic page cache, see #3583047: [Drupal 11.1+] Integrate with Dynamic page cache

Updated test assertions to match the max-age set in WebformSubmissionForm

idebr’s picture

Issue summary: View changes
mxr576’s picture

Status: Needs review » Needs work
StatusFileSize
new215.31 KB

Limiting the scope to restoring the behavior in Drupal 10 makes complete sense to me, this was the goal of the previous attempt, since providing support for proper form caching :tm: could require considerable amount of work.

The changes in the MR looks good to me however neither myself nor my colleague could reproduce the issue based on steps to reproduce with latest dev. (Last commit 794afa).

I have used the default Contact form and modified id based on step 5 and placed it inside the content region.

Enabled render caching debugging and I saw user cache context on the Webform Contact form blocker render.

What did I miss?

idebr’s picture

Status: Needs work » Needs review

@mxr576 The merge request contains a failing test, you can use the steps from the automated test to reproduce the issue. The test-only pipeline shows it fails: https://git.drupalcode.org/issue/webform-3561066/-/jobs/9223532

j-lee’s picture

Code looks good to me.

luke.leber’s picture

I cannot reproduce this on Webform 6.3.x-dev and 11.4.x-dev even using the minimal profile.

I think the steps to reproduce might need to be updated with other enabling criteria? I've seen issues before that can be reproduced within tests, but not in reality. I'm wondering if perhaps this is one of those kinds nowadays (assuming something upstream shifted to break the original steps to reproduce).

That said, I don't see anything wrong with the change, but want to call out the comment

We should be able to remove this once we are confident that all required cache contexts and tags are set.

to add some expectations. Cacheability affects more than just the webform module. All downstream users that have customized things now have to take on this burden too -- something that might not be fit for slipping into a minor release.