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 react-spring error caused by augmented function contexts #3165

Merged
merged 1 commit into from
May 25, 2021

Conversation

developit
Copy link
Member

React-spring provides its own custom context wrapper, which effectively does Object.assign(function SpringContext, createContext(defaultValue)). This breaks preact/hooks because it causes the hook state for useContext() to have a .__c property that contains a function. We mangle both _cleanup and _context to __c, which collides. Normally this is not an issue because createContext() returns an Object.

React-spring provides its own [custom context wrapper](https://github.com/pmndrs/react-spring/blob/d5d8271656f3f3c464a47ad9d39941250ce588b6/packages/core/src/SpringContext.tsx#L33), which effectively does `Object.assign(function SpringContext, createContext(defaultValue))`. This breaks `preact/hooks` because it causes the hook state for `useContext()` to have a `.__c` property that contains a `function`. We mangle both `_cleanup` and `_context` to `__c`, which collides. Normally this is not an issue because `createContext()` returns an Object.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.622% when pulling 997a892 on compat-fix-weird-function-context into ef5e614 on master.

@Inviz
Copy link

Inviz commented May 25, 2021

Uh it was a headscratcher. Also reported previously by somebody else pmndrs/react-spring#1508

developit added a commit to preactjs/preact-devtools that referenced this pull request May 25, 2021
This updates the `useContext()` hook state property (`_context`) to reflect it being renamed to `c` in preactjs/preact#3165.
@marvinhagemeister marvinhagemeister merged commit 014750e into master May 25, 2021
@marvinhagemeister marvinhagemeister deleted the compat-fix-weird-function-context branch May 25, 2021 15:51
marvinhagemeister added a commit to preactjs/preact-devtools that referenced this pull request May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants