Page data form shows stale values after publishing, and radio groups drop a 0 value

Problem

Values shown in the page data form do not match what is stored. Steps to reproduce, using Simple Sitemap's per-entity index setting as an example of a value stored during entity save:

  1. Open a page in the editor.
  2. Set "Do not index", publish.
  3. The form shows the previous value. A full page reload shows the stored one.

Separately, a radio group whose stored value is 0 renders with no option selected.

Cause

Three defects, each needed for the symptom.

  1. DrupalRadioGroup seeds its state with attributes.value || attributes['data-canvas-radio-default-value'] || null. canvas_stark_preprocess_radios() correctly sends 0, but 0 is falsy, so the default is discarded and the state starts as null.
  2. publishAllPendingChanges invalidates the Layout cache tag but not PageDataForm, so the form is not refetched after publishing.
  3. PageDataFormField memoises the props it passes to the wrapped component with a dependency array that omits props itself. After a refetch, the field still passes the previous props down.

Defects 2 and 3 are independent. With only 2 fixed, a network trace shows the form refetched with the correct value while the panel still renders the old one.

Proposed resolution

  1. Use ??, and treat only undefined and '' as absent.
  2. Invalidate { type: 'PageDataForm', id: 'FORM' } after publishing.
  3. Add props to the dependency array.

Remaining known limitation

Auto-saved drafts cannot carry values that are not entity fields. Such values apply on publish only. Out of scope here.

#3591346 reports the same pattern for the layout model. The fixes do not overlap: that one dispatches setLayoutModel in componentAndLayout.ts, this one covers the page data form.

This affects any module storing a value during entity save that the form displays, not only sitemap settings. Found while fixing simple_sitemap #3577889 https://www.drupal.org/project/simple_sitemap/issues/3577889.

Edited by Fons Vandamme