Forms: fix Show summary toggle on blocks with legacy customThankyou#48185
Forms: fix Show summary toggle on blocks with legacy customThankyou#48185
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
53ebcb2 to
fc82fbc
Compare
Fixes #
Proposed changes
customThankyoumigrationuseEffectinedit.tsxso it (a) clearscustomThankyouto''in the samesetAttributescall that writes the modern attribute, and (b) only depends oncustomThankyouitself — notdisableSummary/confirmationType.Why
The previous
useEffect(added in #46866) re-fired every timecustomThankyou,confirmationType, ordisableSummarychanged. For a block saved withcustomThankyou: "noSummary":customThankyou === 'noSummary' && !disableSummary, calledsetAttributes({ disableSummary: true }), but leftcustomThankyouin place.disableSummarybecamefalse.disableSummary: trueagain → toggle reverted.The fix is small: on the first render that sees a legacy
customThankyou, clear it (customThankyou: '') in the same update that setsdisableSummary/confirmationType.customThankyou === ''is the default, so after that first update the condition is permanently false and nothing re-fires on subsequent user toggles.setAttributesalso properly dirties the post, so the cleaned attributes actually persist on save.PHP backward-compat fallbacks in
class-contact-form.phpare left in place so posts whosepost_contentstill hascustomThankyou(never re-opened in the editor) keep rendering correctly on the frontend.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
customThankyouis cleared anddisableSummary: trueis set. Save the post, then reload. Re-open Code Editor —customThankyouis gone from the comment and"disableSummary":trueis present."customThankyou":"redirect"— migration setsconfirmationType: "redirect"and the Redirect URL field appears."customThankyou":"message"— migrates todisableSummary: true(same behaviour asnoSummary).post_contentstill hascustomThankyou: "noSummary"(never re-opened in the editor) continues to hide the summary on render — the PHP fallback inclass-contact-form.phpis intentionally kept.