-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[v.7.0.0] Component one update behind #1219
Comments
Can you please provide a sample project that reproduces the issue, either as a CodeSandbox or a cloneable repo? |
@markerikson I just spend about 30 mins trying to replicate it in a simple project, unfortunately the problem is not present in a simple implementation. I cannot share the project that this issue is occurring in as it is a core product of my company. One thing I noticed when trying to replicate this in a side project is that when updating the state from UI (i.e. a button) it seems to work fine in I wish I could get this replicated in a project I am allowed to share. We'll see if anyone else pops in with this issue and can better provide a replication source. For the time being we will drop back to |
I would really appreciate it if you could try to replicate this further. At a minimum, could you give some examples of where and how you are triggering state updates in relation to that component snippet? This is exactly the kind of feedback I'm looking for to determine whether v7 is ready for final release. If there are issues, I want to resolve them now, but I need more info to be able to dig in myself. |
Hi @luskin I'm trying to help at reproducing this, because I think that I experienced something similar yesterday. One question, though, when you say that:
What do you mean exactly? Do you mean that this only happens with a connected component that doesn't have any other connected components among its ancestors? I mean, are you saying that this problem doesn't happen with connected components that are "nested" with other connected components? Could you please elaborate more on this? Thanks! |
One thing to note that I did not mention previously is that we are using After a user is authenticated (firebase auth) in our
IF we connect our I'll share these two components and they do not expose anything sensitive: CustomerDashboard:
RedirectHandler:
App:
|
@luskin can you provide version details of all packages you are using? You can remove any private packages. |
@josepot To be clearer what I'm saying is that this problem occurs when the component has NO connected parents. Once we connect the parent component the updates are synced back up. In my example code above the problem is solved by adding:
to @navneet-g Sure thing, it's pretty simple so far since we are still in the early phases of the rebuild:
^ we dropped react-redux back down to |
Thanks a lot @luskin for providing all those details. One last question: could you please share the content of your custom hook: The reason why I'm asking is because it seems to me that this hook and the |
@josepot I thought this too and refactored a version that did not pass the props down in this way, however it did not make any difference and so I reverted back to the cleaner (imo) implementation. The issue exists whether or not |
Good news ... I have a repro ... I will upload it to code sandbox or create a repo to share soon. I have not debugged it yet to see what might be happening. |
Here is the repo with repro, the readme has repro steps |
Just to be sure ... I verified the same code base, with react-redux v6 and the issue does not repro, it tells me that the bug is related to react-redux beta or some where in integration :). |
I don't think so, because the render is being triggered. I think that the problem is that |
I can confirm that #1220 fixes the issue locally 🙂 I'm now creating a test-case for the PR. |
Awesome .. from report to fix in 6 hours :) |
The power of teamwork! 😊 |
Just merged the fix and published |
Confirmed fix on my end, we will continue implementation with v7! |
* Update React to latest * Update React peer dependency to 16.8.x * Initial re-implementation of `connectAdvanced` using hooks Matches changes from v7.0.0-alpha.1 * Update tests to match v7-alpha.1 behavior Added rtl.act() calls around dispatches and other component updates Added clarification on expected mapState calls in some places Disabled some no-longer-relevant tests per implementation Made tests run against React 16.8 by default * adding a react hooks test that fails with v7 alpha * wrapping store.dispatch with rlt.act, fixes component renders * reducing hooks test to 2 components * Fix case where wrapper props changed before store update render * Mark ReactDOM as global in UMD builds Matches state as of v7.0.0-alpha.2 * Fix perf problems with out-of-bounds array access Matches state as of v7.0.0-alpha.3 * Add modules to handle importing batchedUpdates * Use appropriate batched update API for subscriptions * Inject unstable_batchedUpdates in default entry point * Provide an alternate entry point for alternate renderers Matches state as of v7.0.0-alpha.4 * Remove batch arg from createListenerCollection (#1205) This prevents a bug with Terser (webpack's default minifier) where the returned batch function isn't defined due to function inlining. Matches state as of v7.0.0-alpha.5 * Remove older React versions from Travis * Add comments to connectAdvanced. Many much comments! * Re-add test for a custom store as a prop * Fix null pointer exception when store is given as a prop We were trying to read contextValue.subscription, even if that value was null. Reworked logic to handle cases where the store came in as a prop. * Ensure wrapper props are passed correctly when forwarding refs * Add a test to verify subscription passthrough with store-as-prop * add non-batched tests (#1208) * Force SSR tests to mimic a Node environment * Restructure connect tests to group by category for easier reading Yeah, this kills the blame history. Sorry. But it's a lot easier to figure out what the tests are used for now. * Clean up dead code in Provider tests * Add tests to verify errors are thrown for bad mapState functions * Fix edge cases around saved wrapper props and error handling Changed to useLayoutEffect to ensure that the lastWrapperProps ref is written to synchronously when a render is committed. However, because React warns about this in SSR, added a check to fall back to plain useEffect under Node so we don't print warnings. Also added logic to ensure that if an error is thrown during a mapState function, but the component is unmounted before it can render, that the error will still be thrown. This shouldn't happen given our top-down subscriptions, but this will help surface the problem in our tests if we ever break the top-down behavior. * Formatting * Add a test to verify no errors are printed in SSR usage * Ignore .idea/ * 7.0.0-beta.0 * Updated outdated SSR-test (dispatch in ancestors) (#1213) * Added test for injecting dynamic reducers on client and server (#1211) * Remove WebStorm gitignore This goes in a global gitignore file, not a project. * [FIX]: #1219 Save references before update (#1220) * Re-ignore .idea/ * 7.0.0-beta.1 * Update the codecov config to be more forgiving. * add test to verify that mapStateToProps is always called with latest store state (#1215)
* Update React to latest * Update React peer dependency to 16.8.x * Initial re-implementation of `connectAdvanced` using hooks Matches changes from v7.0.0-alpha.1 * Update tests to match v7-alpha.1 behavior Added rtl.act() calls around dispatches and other component updates Added clarification on expected mapState calls in some places Disabled some no-longer-relevant tests per implementation Made tests run against React 16.8 by default * adding a react hooks test that fails with v7 alpha * wrapping store.dispatch with rlt.act, fixes component renders * reducing hooks test to 2 components * Fix case where wrapper props changed before store update render * Mark ReactDOM as global in UMD builds Matches state as of v7.0.0-alpha.2 * Fix perf problems with out-of-bounds array access Matches state as of v7.0.0-alpha.3 * Add modules to handle importing batchedUpdates * Use appropriate batched update API for subscriptions * Inject unstable_batchedUpdates in default entry point * Provide an alternate entry point for alternate renderers Matches state as of v7.0.0-alpha.4 * Remove batch arg from createListenerCollection (reduxjs#1205) This prevents a bug with Terser (webpack's default minifier) where the returned batch function isn't defined due to function inlining. Matches state as of v7.0.0-alpha.5 * Remove older React versions from Travis * Add comments to connectAdvanced. Many much comments! * Re-add test for a custom store as a prop * Fix null pointer exception when store is given as a prop We were trying to read contextValue.subscription, even if that value was null. Reworked logic to handle cases where the store came in as a prop. * Ensure wrapper props are passed correctly when forwarding refs * Add a test to verify subscription passthrough with store-as-prop * add non-batched tests (reduxjs#1208) * Force SSR tests to mimic a Node environment * Restructure connect tests to group by category for easier reading Yeah, this kills the blame history. Sorry. But it's a lot easier to figure out what the tests are used for now. * Clean up dead code in Provider tests * Add tests to verify errors are thrown for bad mapState functions * Fix edge cases around saved wrapper props and error handling Changed to useLayoutEffect to ensure that the lastWrapperProps ref is written to synchronously when a render is committed. However, because React warns about this in SSR, added a check to fall back to plain useEffect under Node so we don't print warnings. Also added logic to ensure that if an error is thrown during a mapState function, but the component is unmounted before it can render, that the error will still be thrown. This shouldn't happen given our top-down subscriptions, but this will help surface the problem in our tests if we ever break the top-down behavior. * Formatting * Add a test to verify no errors are printed in SSR usage * Ignore .idea/ * 7.0.0-beta.0 * Updated outdated SSR-test (dispatch in ancestors) (reduxjs#1213) * Added test for injecting dynamic reducers on client and server (reduxjs#1211) * Remove WebStorm gitignore This goes in a global gitignore file, not a project. * [FIX]: reduxjs#1219 Save references before update (reduxjs#1220) * Re-ignore .idea/ * 7.0.0-beta.1 * Update the codecov config to be more forgiving. * add test to verify that mapStateToProps is always called with latest store state (reduxjs#1215)
What is the current behavior?
After upgrading to
v7.0.0-beta.0
our child components are one update behind the state unless we connect the parent component as well.Here is a simple test component:
Here is the output using react-redux
6.0.1
:here is the output using react-redux
7.0.0-beta.0
As you can see
mapStateToProps
requires the state to be modified a second time before updating the component to the previous state. It seems as though possibly the comparison check is not firing off?Things I have tried:
mapStateToProps
-ing the user object, THIS DID WORKWhat is the expected behavior?
Redux should do an equality check and notice that the state is different and update the component props accordingly.
React
16.8.5
React-Redux:
7.0.0-beta.0
The text was updated successfully, but these errors were encountered: