fix: render success message via React state instead of DOM mutation (#1161)#1236
Open
wendyamoni-creator wants to merge 1 commit into
Conversation
The success message in the newsletter signup form was set via direct DOM
mutation (formStatusRef.current.textContent = ...) after a successful
subscription. This worked only by chance—React never re-rendered different
children into that node, so the imperative update persisted. Any future
change that adds real JSX children to the live-region div, or triggers a
re-render after success, could silently clobber the announcement.
Fix:
- Remove formStatusRef and the imperative textContent assignment
- Render {isSubmitted && t('hero.successMessage')} as JSX children inside
the div with role=status aria-live=polite
Tests:
- Add LandingPage.live-region.test.tsx with 5 tests covering:
• Success message appears in DOM via React state after submission
• The text is rendered as real child nodes, not injected imperatively
• Live-region is empty before form submission
• ARIA attributes (role=status, aria-live=polite, aria-atomic=true) present
• No imperative mutation occurs (ref prop removed from the div)
All 50 LandingPage tests pass (4 suites). Build succeeds with zero warnings.
Closes solutions-plug#1161
|
@wendyamoni-creator Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1161 — the newsletter signup success message was announced to screen readers via a direct DOM mutation (
formStatusRef.current.textContent = ...) rather than through React state, making it a fragile unmanaged side-channel.Root Cause
After a successful subscription, the code did:
This bypassed React's render cycle. Any future re-render that gives the
role=statusdiv real JSX children, or a state change that re-renders the form, could silently clobber or fail to update the announcement.Fix
frontend/src/components/LandingPage.tsxformStatusRef(the ref is no longer needed)textContentmutationScreen readers continue to receive the announcement because the
aria-live="polite"region gets a text child injected by React on the same render that setsisSubmitted = true.Tests
Added
frontend/src/components/__tests__/LandingPage.live-region.test.tsx(5 tests):#form-statusafter successful submissionrole=status,aria-live=polite,aria-atomic=true) are presentrefprop is absent from the div (no imperative mutation possible)Checklist
fix/success-message-live-region-announcement-is-setcd frontend && npm test -- LandingPage— 50 tests, 4 suites, all passedcd frontend && npm run build— compiled successfully, 0 warnings closes [Bug] Success-message live-region announcement is set via direct DOM mutation instead of React state #1161