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

Bug: React fash refresh crashes with element reference in machine context #4645

Open
jaykay-p opened this issue Dec 29, 2023 · 2 comments
Open
Labels

Comments

@jaykay-p
Copy link

XState version

XState version 5

Description

Encountered a crash in react during fast refresh when a DOM element reference exists in the context. This issue is demonstrated in the following video, where a console log change triggers a reload:

Screen.Recording.2023-12-29.at.8.22.21.PM.mov

However, changing the element reference to null and then triggering a reload avoids the crash, as shown here:

Screen.Recording.2023-12-29.at.8.23.30.PM.mov

Expected result

refresh seamlessly without crashing

Actual result

crashes to an error page in nextjs

Reproduction

https://stackblitz.com/edit/github-nvyntj?file=src%2FelementMachine.ts,src%2FApp.tsx

Additional context

No response

@jaykay-p jaykay-p added the bug label Dec 29, 2023
@jaykay-p jaykay-p changed the title Bug: React fash refresh crashes when there element reference in machine context Bug: React fash refresh crashes with element reference in machine context Dec 29, 2023
@Andarist
Copy link
Member

The problem lies in this call:

snapshot: (actorRef.getPersistedSnapshot as any)({
__unsafeAllowInlineActors: true
})

DOM elements are circular and our persistContext recurses indefinitely there. This is a general problem - not related specifically to Fast Refresh.

I'll analyze this situation in more depth to figure out what we should do about it in both scenarios (plain getPersistedSnapshot call and the same call performed as part of Fast Refresh).

@ksaldana1
Copy link

I ran into this issue today where I had StateMachine definitions in context. It wasn't necessary for those to exist in context so was easy to remove, but in case someone else runs into fast refresh blowing up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants