fix(announcements): submit button could never enable on the new-announcement form - #974
Merged
Merged
Conversation
…ncement form Found by browser-verifying the page in dev: every field filled, the form reporting `ng-valid`, and "Create draft" still disabled. No announcement could be authored from the UI at all. `canSubmit` is a `computed`, and a computed tracks the signals read during its *last* execution — so an early `return` shortens its dependency set. The guard chain read `isSubmitting()` and then `if (this.form.invalid) return false`, and `FormGroup.invalid` is a plain getter, not a signal. On the first evaluation the form was empty, so it returned there having tracked only `isSubmitting`. No later edit could schedule a recompute, and `isSubmitting` changes only inside `onSubmit` — which the disabled button prevented. Two changes, both load-bearing: - form validity is mirrored into a signal fed by `statusChanges`, like the other `valueChanges` mirrors already in this component; - every input is read unconditionally before being combined, so no branch can shrink the tracked dependency set again. The three new tests read `canSubmit()` while the form is still **empty**, then fill it. That ordering is the whole point: the existing 24 specs only ever read it after filling, so the computed's first evaluation saw a valid form, tracked everything, and stayed reactive — all 24 pass against the broken code. Verified by reverting the fix: the 3 new tests fail, the other 24 do not. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Follow-up to #972. The admin form shipped unable to create anything — this fixes that.
The bug
Browser-verifying the page in dev: every field filled, the form reporting
ng-validon every control, and "Create draft" still disabled. No announcement could be authored from the UI at all, which was the entire point of PR-3.canSubmitis acomputed, and a computed tracks the signals read during its last execution — so an earlyreturnshortens its dependency set:On the first evaluation the form was empty, so it returned at line 2 having tracked only
isSubmitting. Nothing else was a dependency, so no later edit could schedule a recompute — andisSubmittingonly changes insideonSubmit, which the disabled button prevented. A deadlock.The fix
Two changes, both load-bearing:
statusChanges, exactly like thevalueChangesmirrors this component already keeps for the template.canSubmitexplains why, because the guard-clause version reads as the more natural style and someone will want to refactor back to it.Why the existing tests missed it
They only ever read
canSubmit()after filling the form. In that order the computed's first evaluation sees a valid form, reads past theform.invalidcheck, tracks every signal, and stays reactive — so the bug is invisible. In the real page the first read happens while the form is still empty.The three new tests read
canSubmit()while empty first, then fill. That ordering is the entire test.I verified they actually catch it rather than assuming: reverting the fix makes the 3 new tests fail while all 24 original specs still pass.
Testing
npm test: 217 files, 2431 tests pass.npx tsc --noEmit: clean.Backend untouched.
Note for the epic
This is the second bug in this feature that unit tests passed and a browser caught (the first was PR-2's markdown rendering with inert
proseclasses). Both were in the SPA, and both were invisible to specs that exercised the logic without rendering it. Worth remembering when PR-4 (banner) and PR-5 (modal) land — those are the surfaces where a silent failure is most costly.🤖 Generated with Claude Code