-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: synchronous state updates in cacheable-sections and fix type generation #1391
Merged
Conversation
This file contains 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
amcgee
approved these changes
Nov 25, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
* fix(deps): remove cli-app-scripts peer dep * chore: group dependencies in package.json
#1380) * chore(deps): update yarn.lock * fix(query-playground): update dhis2 deps * fix: use imported font for consistency across platforms * fix(query-playground): use codemirror to fix cursor issue * chore: remove react-ace * fix: font and tab size * fix: scrolling for long codemirror blocks * fix(deps): downgrade @dhis2/cli-app-scripts to work with Node 14 * fix: try lower cli-app-scripts and UI version to fix Node version error
…1385) * fix(cacheable-sections): stable references * refactor: avoid needing eslint disable * chore: consistent test names
* fix: handle async parentAlertsAdd * chore: fix comment
f722f7a
to
122f06a
Compare
122f06a
to
04bc604
Compare
|
kabaros
approved these changes
Nov 26, 2024
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 from #1387
Quick tip:
I merged in
master
to include some recent fixes to avoid unnecessary rerenders fromuseCacheableSection
, which unfortunately clutters up the commit history -- for ease of browsing, this range of commits here includes the relevant test changes. A few small type changes and a bump for@dhis2/cli-app-scripts
are not included in these thoughThe cause:
The failing tests were correctly identifying a change in behavior with React 18: state updates in callbacks were being handled more asynchronously due to batching, which created an unwanted race condition. This section in the linked the batching article had a solution:
For some extra context on this hook:
While asynchronous behavior could work for
useCacheableSection
and the tests could be updated to handle that, the returned values from the hook are intended to give users the chance to make UI changes based on states and transitions. Based on that, I think it makes sense for things to happen sequentially so that consumers have some guarantees for what they can expect:startRecording()
is calledrecordingState
becomes'pending'
and the promise returned bystartRecording
resolves -- this is a minor detail]recordingState
becomesrecording
onStarted
callback provided tostartRecording()
is calledrecordingState
is guaranteed to be'recording'
by this point, so the consumer can more confidently make assumptions about the UI