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:
- Open a page in the editor.
- Set "Do not index", publish.
- 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.
DrupalRadioGroupseeds its state withattributes.value || attributes['data-canvas-radio-default-value'] || null.canvas_stark_preprocess_radios()correctly sends0, but0is falsy, so the default is discarded and the state starts asnull.publishAllPendingChangesinvalidates theLayoutcache tag but notPageDataForm, so the form is not refetched after publishing.PageDataFormFieldmemoises the props it passes to the wrapped component with a dependency array that omitspropsitself. 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
- Use
??, and treat onlyundefinedand''as absent. - Invalidate
{ type: 'PageDataForm', id: 'FORM' }after publishing. - Add
propsto 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.
Related
#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.