Repository navigation
Compose: Preserve value type in useStateWithHistory - #85090
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
6033376 to
3b79e06
Compare
|
|
||
| ### Bug Fixes | ||
|
|
||
| - `useMergeRefs`, `useStateWithHistory`: Accept `false` in `useMergeRefs`, preserve the initial value type in `useStateWithHistory`, and allow omitting `isStaged` in `setValue` ([#85090](https://github.com/WordPress/gutenberg/pull/85090)). |
There was a problem hiding this comment.
Two things here:
- The
useMergeRefshalf already landed in Block Editor: PR 52: Convert the block list and useBlockProps to TypeScript #85029 (see line 12), and this PR no longer touchesuseMergeRefs. Keep only theuseStateWithHistorypart. The PR title needs the same update. - After the trunk merge, the entry sits under the released
## 9.0.0. Please move it under## Unreleased.
| }; | ||
|
|
||
| describe( 'useStateWithHistory', () => { | ||
| it( 'preserves the number value type through undo and redo', () => { |
There was a problem hiding this comment.
Nit: the expectTypeOf assertions are the new coverage here. The act/undo/redo blocks in this test and the next repeat what "should allow undo/redo" already checks, so these two tests could keep only the type assertions.
3b79e06 to
8d50bbd
Compare
What?
Follow up to #84382.
Tracks #67691.
Addresses the
useStateWithHistorytype follow-up noted during the@wordpress/composeTypeScript conversion in #84382. Preserves the initial value type and makesisStagedoptional insetValue. TheuseMergeRefsfollow-up landed in #85029.Why?
useStateWithHistoryreturnedvalueasunknowndue to unparameterizeduseReducerinference, and requiredisStagedonsetValue, even though callers typically omit it.How?
<T>toundoRedoReducerandinitReducerinuseReducer.isStaged?: booleanoptional in theRECORDaction andsetValue.value as stringand@ts-expect-errorfrom the tests, and adds type-only tests usingexpectTypeOf.packages/compose/CHANGELOG.md.Testing Instructions
nvm usenpm run test:unit -- packages/compose/src/hooks/use-state-with-historynpm run typecheck -- packages/composeUse of AI Tools
Drafted with AI assistance, verified and reviewed by me.
@coderabbitai review