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

When SQLite is being used, useEffect hooks with async on reloads fail to fire. #13578

Closed
trajano opened this issue Jul 11, 2021 · 3 comments
Closed
Labels
needs validation Issue needs to be validated stale

Comments

@trajano
Copy link
Contributor

trajano commented Jul 11, 2021

Summary

It appears a combination of SQLite (transactions maybe?) and useEffect with async causes useEffect methods to stop firing on a reload. Note on SDK 40 it doesn't happen always, but SDK 42 happens always on the first reload

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android
iOS

SDK Version (managed workflow only)

42

Environment

Expo CLI 4.7.3 environment info:
System:
OS: Windows 10 10.0.19043
Binaries:
Node: 12.18.0 - ~\scoop\apps\nvm\current\nodejs\nodejs\node.EXE
Yarn: 1.22.10 - ~\scoop\apps\nvm\current\nodejs\nodejs\yarn.CMD
npm: 6.14.4 - ~\scoop\apps\nvm\current\nodejs\nodejs\npm.CMD
IDEs:
Android Studio: Version 4.2.0.0 AI-202.7660.26.42.7486908
npmPackages:
expo: ~42.0.1 => 42.0.1
react: 16.13.1 => 16.13.1
react-dom: 16.13.1 => 16.13.1
react-native: https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz => 0.63.2
react-native-web: ~0.13.12 => 0.13.18
Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

https://github.com/trajano/sqllite-mvce/tree/t2

@trajano trajano added the needs validation Issue needs to be validated label Jul 11, 2021
@trajano
Copy link
Contributor Author

trajano commented Jul 11, 2021

Found the reason why t2 wasn't working. It wasn't because of SQLite but an uncleared and incomplete setTimeout. There really should be an error message or cleanup logic for this one. But it may be a react-native issue. Since it's primarily on sdk42 and also they added their own typings for setTimeout and clearTimeout which clash with previous versions that allowed for ...

const timeoutRef = useRef<ReturnType>();

now we need

const timeoutRef = useRef();

and add a cast

useEffect(() => {
mountedRef.current = true;
if (immediate) {
wrappedAsyncFunction();
} else {
timeoutRef.current = setTimeout(
wrappedAsyncFunction,
interval
) as unknown as number;
}
return () => {
clearTimeout(timeoutRef.current);
mountedRef.current = false;
};
}, [asyncFunction, onSuccess]);

@github-actions
Copy link
Contributor

This issue is stale because it has been open for 60 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

@github-actions github-actions bot added the stale label Jan 20, 2022
@github-actions
Copy link
Contributor

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs validation Issue needs to be validated stale
Projects
None yet
Development

No branches or pull requests

1 participant