Problem/Motivation

CheckboxTree::processCheckboxTree() builds the widget options by querying the term tables directly (via _term_reference_tree_get_term_hierarchy()), but attaches no cacheability metadata to the element. Any render-cached artifact containing the form (Internal Page Cache, Dynamic Page Cache, render cache) is therefore never invalidated when terms change.

Steps to reproduce

1. Add a field with the Term reference tree widget to a form that is cacheable for anonymous users (e.g. the user register form), with Internal Page Cache enabled.
2. Visit the form as anonymous to warm the cache.
3. Add or rename a term in the referenced vocabulary.
4. Reload the form: the tree still shows the old options.

Proposed resolution

Declare the bundle-specific term list cache tag for each rendered vocabulary in CheckboxTree::processCheckboxTree():

  foreach ($element['#vocabularies'] as $vocabulary) {
    $element['#cache']['tags'] = Cache::mergeTags(
      $element['#cache']['tags'] ?? [],
      ['taxonomy_term_list:' . $vocabulary->id()]
    );
  }

Remaining tasks

User interface changes

API changes

Data model changes

Comments

marcoscano created an issue.