-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fixed an issue with useSelector
always computing fresh snapshots internally for uninitialized services
#3500
Conversation
…ternally for uninitialized services
🦋 Changeset detectedLatest commit: 214baeb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
👇 Click on the image for a new way to code review
Legend |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 214baeb:
|
const defaultGetSnapshot = (a, initialStateCacheRef) => { | ||
if (isService(a)) { | ||
if (a.status === 0 && initialStateCacheRef.current) { | ||
return initialStateCacheRef.current; | ||
} | ||
const snapshot = getServiceSnapshot(a); | ||
initialStateCacheRef.current = a.status === 0 ? snapshot : null; | ||
return snapshot; | ||
} | ||
return isActorWithState(a) ? a.state : undefined; | ||
}; |
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.
Is it pretty? Not at all. It's basically a hack to cache those results as they should represent the same thing, even if they are not preferentially transparent.
We can't easily refactor this in v4 because we can't compute the initial "true" snapshot when the service isn't initialized as computing this might lead to side-effects. This problem doesn't exist in v5
|
||
const [snapshot1] = snapshots; | ||
expect(snapshots.every((s) => s === snapshot1)); | ||
expect(console.error).toHaveBeenCalledTimes(0); |
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.
I'd love to find a more robust/flexible way of specifying the logging/error sinks for v5 (future note, not for this PR)
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.
Note that this doesn't test a log that we control. This one comes from React
Co-authored-by: David Khourshid <davidkpiano@gmail.com>
closes #3497