Repository navigation
Studio: show HF token tick only after validation - #7268
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Hugging Face token success indicator to only display once the token has been successfully validated, rather than just saved. It also updates the corresponding localization files and adds a contract test. The review feedback highlights a potential UX race condition where a stale validation state might briefly flash a success tick due to debouncing, and points out a PEP 8 formatting violation in the new test file.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const tokenIsCurrent = | ||
| draftToken.trim().length > 0 && draftToken.trim() === (hfToken ?? ""); | ||
| const tokenValidation = useHfTokenValidation(hfToken ?? ""); | ||
| const tokenValidated = tokenIsCurrent && tokenValidation.isValid === true; |
There was a problem hiding this comment.
There is a potential UX race condition / stale state flash here. When hfToken is updated (e.g., on blur), tokenIsCurrent immediately becomes true. However, useHfTokenValidation debounces the token check by 500ms. During this 500ms window, the hook's internal debouncedToken is still the old token, and since completed.token matches debouncedToken, the hook returns isValid: true (the validation result of the old token). This causes tokenValidated to briefly evaluate to true, flashing the green success tick for up to 500ms before the debounce timer fires and resets the state to isChecking: true.
To fix this, useHfTokenValidation should be updated to compare completed.token against the raw (normalized) token instead of debouncedToken before returning the cached validation state. Since use-hf-token-validation.ts is not modified in this PR, please update that hook in a separate change or include it here to ensure the success tick doesn't flash stale states.
There was a problem hiding this comment.
This is exactly what the PR fixes. The hook now compares completed.token against normalizedToken (line 104) and guards on normalizedToken (line 103), so a just-edited token drops into the isChecking branch and the previous valid result is never returned. The tick can no longer flash, so no further change to the hook is needed.
|
|
||
|
|
||
| def test_success_tick_requires_the_current_token_to_be_validated(): | ||
| source = GENERAL_TAB.read_text(encoding = "utf-8") |
There was a problem hiding this comment.
According to PEP 8, spaces should not be used around the = sign when used to indicate a keyword argument.
| source = GENERAL_TAB.read_text(encoding = "utf-8") | |
| source = GENERAL_TAB.read_text(encoding="utf-8") |
References
- PEP 8: Don't use spaces around the = sign when used to indicate a keyword argument, or when used to indicate a default value for an unannotated function parameter. (link)
There was a problem hiding this comment.
This repo intentionally keeps spaces around = for keyword arguments. scripts/enforce_kwargs_spacing.py enforces it as a pre-commit hook and E251 is not in the ruff select set, so the existing tests already use encoding = "utf-8" throughout. Switching to encoding="utf-8" would be reverted by the formatter, so leaving it as is.
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Root cause
The indicator was driven only by whether the input matched the persisted token. That made malformed, expired, or revoked tokens look accepted even when token validation reported an error.
User impact
The success indicator now communicates confirmed validity instead of storage state.
Validation
npm run buildnpm run typechecknpm run i18n:checknpx eslint src/features/settings/tabs/general-tab.tsx src/i18n/locales/*.tsuvx --from pytest pytest -q tests/studio/test_hf_token_validation_tick_contract.py tests/studio/test_settings_compact_overflow_contract.py(4 passed)git diff --check