fix(auth): backfill login form when injected defaults arrive after mount - #33
Open
ggfto wants to merge 1 commit into
Open
fix(auth): backfill login form when injected defaults arrive after mount#33ggfto wants to merge 1 commit into
ggfto wants to merge 1 commit into
Conversation
`LoginGate` seeds its local state with `useState(gatewayUrlInit)` /
`useState(tokenInit)`, but the store those values come from is populated by an
effect in `<App>`:
useEffect(() => {
hydrate({ gatewayUrl, token: gatewayToken });
}, [hydrate, gatewayUrl, gatewayToken]);
React runs a parent's effects only after its children have mounted, so
`LoginGate` always reads the pre-hydration store — two empty strings. A plain
re-render never revisits a `useState` initializer, so the fields stay blank for
the lifetime of the page.
The result is a deployment that injects `gatewayUrl` and `gatewayToken` into the
page, and still shows the user an empty sign-in form. Reloading does not help,
because the mount order is the same every time.
Fix: backfill both fields once the defaults arrive, using functional updates so
that anything the user has already typed always wins.
This does not change the credential-restore policy. `loadStoredCredentials()` is
still never called on startup, as `auth-store.ts` documents on purpose: a stale
token from a previous deployment would start a silent connect attempt and block
the user from submitting a corrected value.
Tests: the first case fails without this change
(`expected '' to be 'ws://gateway.test/gateway-ws'`); the second guards against
a late default clobbering user input.
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.
Problem
A deployment can inject
gatewayUrlandgatewayTokeninto the page, and thesign-in form still renders empty. Reloading never helps.
LoginGateseeds its local state from the auth store:But that store is populated by an effect in
<App>:React runs a parent's effects only after its children have mounted, so
LoginGatealways reads the pre-hydration store — two empty strings. A plainre-render never revisits a
useStateinitializer, so the fields stay blank forthe lifetime of the page. The mount order is deterministic, which is why
reloading has no effect.
Fix
Backfill both fields once the defaults arrive, using functional updates so that
anything the user has already typed always wins:
18 lines in one component, plus tests.
What this deliberately does not change
The credential-restore policy stays exactly as it is.
loadStoredCredentials()is still never called on startup, which
auth-store.tsexplains is intentional:a stale token or URL from a previous deployment would start a silent connect
attempt, leave the UI on "connecting", and block the user from submitting a
corrected value. This PR only fixes the prefill path, which is the one that is
already meant to run.
Tests
src/components/auth/LoginGate.test.tsx, two cases:second — the same order the browser produces. This case fails without the
change:
expected '' to be 'ws://gateway.test/gateway-ws'.correction in progress.
Full suite: 64 files, 546 tests passing.
tsc --noEmitclean.I left the repo's existing formatting untouched — running
oxfmtwith defaultsettings wanted to reflow unrelated lines in the same file, and that noise did
not belong in a fix this small.