react
react copied to clipboard
Bug: startTransition is causing TypeError when used directly from react
React version: 18.3.1
Steps To Reproduce
Getting this error message
TypeError: Cannot read property 'add' of undefined
- Run the code example https://snack.expo.dev/@raajnadar/swr-error-in-expo-sdk-52
- Run android or ios, the web version works without the error
- Click the "Call the API button" button inside the mobile app
- Check the logs tab, when switched to axios there is no issue
- This happens with
swrbecause it uses startTransition internally
Link to code example:
Import like this
export const startTransition: (scope: TransitionFunction) => void =
IS_REACT_LEGACY
? cb => {
cb()
}
: React.startTransition
And use like this
startTransition(() =>
setState({ data, isMutating: false, error: undefined })
)
Code from this repository https://github.com/vercel/swr/blob/1585a3e37d90ad0df8097b099db38f1afb43c95d/src/mutation/state.ts#L5-L10
The current behavior
Getting this error when startTransition used from React directly
TypeError: Cannot read property 'add' of undefined
On Expo snack the error says
Error: "Cannot read property 'add' of undefined" in TypeError: Cannot read property 'add' of undefined << at requestUpdateLane (/data/user/0/host.exp.exponent/files/.expo-internal/5cb1b0c52b8fcab94364327c83b808ee:18892:43) << at dispatchSetState (/data/user/0/host.exp.exponent/files/.expo-internal/5cb1b0c52b8fcab94364327c83b808ee:16726:33) << at anonymous (swr.mutation:12:14616)
The expected behavior
There is no TypeError,
When I tried using the startTransition from the useTransition hook the problem got solved
This looks like it's also using react-native? Does it repro with react-dom instead of react-native?
I'd inline all the relevant code of swr first. Otherwise it isn't clear for use if the issue is with 3rd party libraries or React itself
With React native web the issue is not visible, we can use the same snack demo to confirm it.
How can I or someone else figure out the issue? I gave my findings here in the issue ticket.
Some devs in an SWR ticket said this should not be an issue from SWR because the latest release was 6 months ago and the same code & SWR version works on expo SDK 51 without change in SWR itself.
Will the problem arise from the React Native core?
I can confirm this issue is not with web apps using react-dom, I will report to react native core
https://stackblitz.com/edit/vitejs-vite-u1tsbe?file=package.json
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!