8000 Bug: startTransition is causing TypeError when used directly from react · Issue #31622 · facebook/react · GitHub
[go: up one dir, main page]

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: startTransition is causing TypeError when used directly from react #31622

Closed
raajnadar opened this issue Nov 23, 2024 · 5 comments
Closed
Labels
Resolution: Needs More Information Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@raajnadar
Copy link
raajnadar commented Nov 23, 2024

React version: 18.3.1

Steps To Reproduce

Getting this error message

TypeError: Cannot read property 'add' of undefined

  1. Run the code example https://snack.expo.dev/@raajnadar/swr-error-in-expo-sdk-52
  2. Run android or ios, the web version works without the error
  3. Click the "Call the API button" button inside the mobile app
  4. Check the logs tab, when switched to axios there is no issue
  5. This happens with swr because 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

@raajnadar raajnadar added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Nov 23, 2024
@eps1lon
Copy link
Collaborator
eps1lon commented Nov 24, 2024

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

@raajnadar
Copy link
Author

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?

@raajnadar
Copy link
Author

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

Copy link

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!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Feb 28, 2025
Copy link
github-actions bot commented Mar 7, 2025

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!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Needs More Information Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

2 participants
0