statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
27.23k stars 1.26k forks source link

Bug: Maximum call stack exceeded on hot reload when assigning element to context #4985

Open jjenzz opened 4 months ago

jjenzz commented 4 months ago

XState version

XState version 5

Description

in a NextJS 14 app router project, i'm assigning an element to context on mount. if i make changes to my code that trigger a hot reload, i get the following errors:

CleanShot 2024-07-16 at 17 09 56

i can only replicate this when assigning an HTMLElement. assigning a string works fine.

Steps to reproduce

https://github.com/user-attachments/assets/4019fa36-40fc-4b8f-ab81-eab98f9f9543

Expected result

hot reload would succeed without errors

Actual result

maximum call stack exceeded

Reproduction

https://stackblitz.com/edit/stackblitz-starters-hocxhz?description=The%20React%20framework%20for%20production&file=app%2Ftest.tsx,app%2Fpage.tsx&title=Next.js%20Starter

Additional context

No response

Andarist commented 4 months ago

I believe this is a duplicate of: https://github.com/statelyai/xstate/issues/4645

davidkpiano commented 4 months ago

Thanks for the repro! Seems like the issue is with the persistContext(…) function getting into a cycle. Will investigate.