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

componentWillUnmount causing setState to be set to () => {} in Next.js #1316

Closed
cohenrobinson opened this issue Apr 13, 2024 · 3 comments
Closed
Assignees

Comments

@cohenrobinson
Copy link

Hello!

I just migrated from using the standard CRA installation to now using React + Next.js. Unsure if the following is a bug with Next.js (14.1.4) or uniforms (4.0.0-alpha.5)

After migrating, all uniforms AutoForms I implemented would now not have the AutoField state updated, even though they were previously working.

I implemented a very straightforward AutoForm per the docs just to see if it was an issue with my custom implementation, but that too failed.

After a bit of digging, the componentWillUnmount was causing the setState to be set to () => {}, despite the component being mounted subsequently.

I removed the this.setState = () => { }; line and was able to verify this now works as expected and the field state is being updated.

componentWillUnmount() {
        this.mounted = false;
        if (this.delayId) {
            clearTimeout(this.delayId);
        }
        // There are at least 4 places where we'd need to check, whether or not we
        // actually perform `setState` after the component gets unmounted. Instead,
        // we override it to hide the React warning. Also because React no longer
        // will raise it in the newer versions.
        // https://github.com/facebook/react/pull/22114
        // https://github.com/vazco/uniforms/issues/1152
        this.setState = () => { };
    }

I suspect this must be with the way Next.js deals with state and mounting of components. However, I can't find anything to suggest it's the Next.js installation that's causing the issue (not directly at least).

cohenrobinson added a commit to cohenrobinson/uniforms that referenced this issue Apr 13, 2024
@github-project-automation github-project-automation bot moved this to Needs triage in Open Source Apr 17, 2024
@kestarumper
Copy link
Member

kestarumper commented Apr 19, 2024

Hi @cohenrobinson,
there is a similar issue #1194 (comment).
Could you have a look at it and tell me if it helps in any way?
Try disabling strict mode.

@kestarumper kestarumper self-assigned this Apr 19, 2024
@kestarumper kestarumper moved this from Needs triage to In progress in Open Source Apr 19, 2024
@kestarumper kestarumper moved this from In progress to Review in Open Source Apr 26, 2024
@kestarumper
Copy link
Member

Related: #1324

@kestarumper
Copy link
Member

Closing due to no response.
It will be fixed in #1324.

@github-project-automation github-project-automation bot moved this from Review to Closed in Open Source May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants