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: safely import legacy act for Next #80

Merged
merged 2 commits into from
May 3, 2024

Conversation

matiasperz
Copy link
Contributor

@matiasperz matiasperz commented May 1, 2024

I faced this error using nextjs on react 18. Adding the optional chaining operator seems to fix it.

"next": "14.2.3",
"react": "18.3.1",

image

@matiasperz matiasperz changed the title Fix "unstable_act" error May 1, 2024
export const act: Act = (React as any).unstable_act
export const act: Act = (React as any)?.unstable_act
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this would actually work for your version. Can you try this instead?

export const act: Act = (React as any)?.unstable_act ?? (React as any)?.act

The method is called like await act(async () => {}) which forces React to recursively flush work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your suggestion worked too + looks more correct. I know nothing about React internals 😅

@matiasperz matiasperz closed this May 1, 2024
@matiasperz matiasperz reopened this May 3, 2024
@CodyJasonBennett CodyJasonBennett merged commit 9956023 into pmndrs:main May 3, 2024
1 check passed
@CodyJasonBennett CodyJasonBennett changed the title Fix unstable_act error May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants