fix(RelativeDateField): read latest state on deferred blur#287
Open
dgaponov wants to merge 1 commit into
Open
Conversation
useFocusWithin now dispatches onBlurWithin asynchronously (via setTimeout), so confirmValue could run after an external value update with a stale render closure and re-commit the old value — clobbering a reset to null. Read the current text/value/parsedDate from a ref so the deferred blur always sees fresh state. Also await the async blur in the "restores last correct value" test, which asserted synchronously before the deferred blur fired. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
Contributor
|
Preview is ready. |
Contributor
|
🎭 Tests Report is ready. |
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.
Проблема
После обновления
@gravity-ui/uikit(7.45.1)useFocusWithinстал диспатчитьonBlurWithinасинхронно — черезsetTimeout(…, 0). Из-за этого падал тестRelativeDateField > clears invalid draft text when controlled value becomes null:now - 1x(это draft; закоммиченное значение остаётсяnow - 1d).setValue(null)→ текст сбрасывается в''.confirmValue()выполняется со старым замыканием (text="now - 1x",value="now - 1d"), восстанавливает и заново коммититnow - 1d, затирая сброс.Исправление
useRelativeDateFieldState:confirmValueчитает актуальныеtext/value/parsedDateиз ref, а не из замыкания рендера. Теперь отложенный blur, сработавший после внешнего обновления значения, видит свежее состояние (text="") и корректно выходит, ничего не перекоммичивая.restores the last correct value on blur: падал по той же причине (проверял значение синхронно, до отложенного blur). Заменён наawait expect.poll(...), чтобы дождаться асинхронного blur.Проверка
npx vitest run --project unit src/components/RelativeDateField— все 6 тестов проходят стабильно (проверено несколькими прогонами), lint чистый.🤖 Generated with Claude Code