Skip to content
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: Do not run reducer on non-optimistic fetches #302

Merged
merged 1 commit into from
Mar 21, 2020

Conversation

ntucker
Copy link
Collaborator

@ntucker ntucker commented Mar 21, 2020

Fixes #300 .

Motivation

Even though the state does not update, React will warn about the reducer running from render (triggered from useRetrieve()). Although React should short-circuit and not actually re-render, it doesn't harm for us to short-circuit even earlier - after all it will run less code!

Solution

Intercept all fetch dispatches in the NetworkManager that cannot cause state updates. (No optimistic response)

@github-actions
Copy link
Contributor

github-actions bot commented Mar 21, 2020

Size Change: +141 B (0%)

Total Size: 29.4 kB

Filename Size Change
packages/rest-hooks/dist/index.cjs.js 16.2 kB +133 B (0%)
packages/rest-hooks/dist/index.umd.min.js 6.74 kB +8 B (0%)
ℹ️ View Unchanged
Filename Size Change
packages/legacy/dist/index.cjs.js 424 B 0 B
packages/legacy/dist/index.umd.min.js 376 B 0 B
packages/normalizr/dist/normalizr.es.min.js 2.17 kB 0 B
packages/test/dist/index.cjs.js 1.84 kB 0 B
packages/use-enhanced-reducer/dist/index.cjs.js 1.08 kB 0 B
packages/use-enhanced-reducer/dist/index.umd.min.js 593 B 0 B

compressed-size-action

@@ -20,9 +20,7 @@ export default function useError<
if (!meta.error) {
// this means we probably deleted the entity found in this result
const err: any = new Error(
`Resource not found in cache ${
params ? fetchShape.getFetchKey(params) : ''
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was actually not needed - as params is already discriminated above.

@ntucker ntucker merged commit 86cc80b into master Mar 21, 2020
@ntucker ntucker deleted the fix/update-in-render branch March 21, 2020 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Various warnings in React 16.13.1
1 participant