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

Updating a parcel with new props recreates its rootComponent and looses all internal state #134

Closed
gabbaxx opened this issue Dec 1, 2021 · 3 comments

Comments

@gabbaxx
Copy link

gabbaxx commented Dec 1, 2021

Problem
When the props of a parcel are updated (using the update lifecycle function) the entire react tree inside the parcel is recreated from scratch. This means that all internal state is reset.

It seems that the problem is introduced by the fix for the parcels props not updating in #126 (v4.4)

Reproduction steps
Below is a little codesandbox that demonstrates the issue by having two independent counters. One that is incremented in the containing react app plus a second counter that is incremented inside the parcel.
In v4.1 both counters continue to increment as expected.
In v4.2-4.3 the container's counter isn't injected properly into the parcel
In v.4.4 and later the parcel-internal counter is reset to its start value whenever the parcel props are updated

https://codesandbox.io/s/updated-parcel-props-remounts-root-component-jnle3?file=/index.html

The problem exists for both react version 17 and 18.

@nilzona
Copy link

nilzona commented Dec 22, 2021

Hey @joeldenning. Don't know if you or another maintainer of this repo had time to look at this. But to me this looks like a pretty serious issue. If I understood the api's correctly a component rendering a Parcel that is using single-spa-react to wrap the life-cycle methods should be able to modify the Parcel's Props without re-rendering the whole React tree, re-setting the state etc etc. As @gabbaxx pointed out it worked that way in version <= 4.1

@joeldenning
Copy link
Member

This is fixed in #138. If in a week or so I haven't merged and published, it's because I didn't get a code review and forgot about it, so feel free to ping me.

@joeldenning
Copy link
Member

Fix released in https://github.com/single-spa/single-spa-react/releases/tag/v4.6.1

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

No branches or pull requests

3 participants