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

useFonts can change state on an unmounted component #20621

Open
dancrumb opened this issue Dec 27, 2022 · 2 comments
Open

useFonts can change state on an unmounted component #20621

dancrumb opened this issue Dec 27, 2022 · 2 comments
Assignees

Comments

@dancrumb
Copy link

Summary

The useFont hook uses a useEffect hook to load fonts asynchronously.

Once they are loaded, it calls a useState modifier.

Since this is an async call, attempting to modify the hook state can occur after the containing component has been unmounted, resulting in a warning.

The desired behaviour should be that the hook does not attempt to modify state when it is unmounted.

What platform(s) does this occur on?

Web

Environment

expo-env-info 1.0.5 environment info:
System:
OS: macOS 13.0.1
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
Watchman: 2022.11.28.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
IDEs:
Xcode: 14.2/14C18 - /usr/bin/xcodebuild
npmGlobalPackages:
eas-cli: 2.9.0
expo-cli: 6.0.8
Expo Workflow: managed

Minimal reproducible example

This is a hard issue to reproduce since it's timing based.

This Snack shows the issue in principle:
https://snack.expo.dev/6OBRLWb9h

However, simply by inspection, the failure mode should be clear. There's an async call that sets state on completion - this is a classic React error if done within a component.

@dancrumb dancrumb added the needs validation Issue needs to be validated label Dec 27, 2022
@dancrumb
Copy link
Author

I acknowledge that it's possible that one should not use useFonts in anything but the highest level component, but if that's the case, the docs should probably be updated to emphasize this.

@brentvatne brentvatne added needs review Issue is ready to be reviewed by a maintainer and removed needs validation Issue needs to be validated labels Feb 22, 2023
@brentvatne brentvatne added Issue accepted and removed needs review Issue is ready to be reviewed by a maintainer labels Feb 23, 2023
@expo-bot
Copy link
Collaborator

Thank you for filing this issue!
This comment acknowledges we believe this may be a bug and there’s enough information to investigate it.
However, we can’t promise any sort of timeline for resolution. We prioritize issues based on severity, breadth of impact, and alignment with our roadmap. If you’d like to help move it more quickly, you can continue to investigate it more deeply and/or you can open a pull request that fixes the cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants