LegendApp / legend-state

Legend-State is a super fast and powerful state library that enables fine-grained reactivity and easy automatic persistence
https://legendapp.com/open-source/state/
MIT License
2.96k stars 83 forks source link

Bug: React 19 - Removed Export #312

Open andrewpeters9 opened 4 months ago

andrewpeters9 commented 4 months ago

A secret internal export has been removed from React 19. Importing it causes builds to fail.

https://github.com/LegendApp/legend-state/blob/faa7595016d7859cba87f01ec3ae2995b88d650d/src/config/enableReactTracking.ts#L13

I haven't tested it, but this should fix things, i think.

import React from 'react';
// ...
// @ts-expect-error Internals
const dispatcher = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentDispatcher.current;
najihmld commented 1 month ago

build failed after upgrade next.js to v15

enableReactTracking({ auto: true })

jmeistrich commented 1 month ago

Sorry I haven't looked into this yet! The enableReactTracking feature depends on a hack using that secret internal import, which is why it's not recommended for production. I may be able to find a different hack to make 19 work, but since this method is an unreliable hack it really shouldn't be used anyway. I'll update the docs to discourage usage and mention it doesn't work in 19.

And then I'll see if I can find a new hack for 19. For now I'd suggest not using this method and using the observer pattern instead.