fixing stale state causing new init method to not run (#300)

This commit is contained in:
Blake Kaufman
2025-12-06 18:10:19 -05:00
committed by GitHub
parent 5f95eff905
commit 1c624aa91b
+7 -3
View File
@@ -175,6 +175,7 @@ export const WebViewProvider = ({ children }) => {
const isInitialRender = useRef(true);
const currentWalletMnemoincRef = useRef(currentWalletMnemoinc);
const didRunInit = useRef(null);
const isWebviewReadyRef = useRef(null);
const didGetToHomepageRef = useRef(didGetToHomepage);
const [changeSparkConnectionState, setChangeSparkConnectionState] = useState({
state: null,
@@ -185,6 +186,10 @@ export const WebViewProvider = ({ children }) => {
currentWalletMnemoincRef.current = currentWalletMnemoinc;
}, [currentWalletMnemoinc]);
useEffect(() => {
isWebviewReadyRef.current = isWebViewReady;
}, [isWebViewReady]);
// reset webview when app is stale in background
useEffect(() => {
if (isInitialRender.current) {
@@ -659,12 +664,12 @@ export const WebViewProvider = ({ children }) => {
return;
}
if (!webViewRef.current || !isWebViewReady) {
if (!webViewRef.current || !isWebviewReadyRef.current) {
console.log(
'WebView not ready or internet is not connected, queueing message:',
action,
webViewRef.current,
isWebViewReady,
isWebviewReadyRef.current,
);
if (!isDuplicate(queuedRequests.current, action, args)) {
queuedRequests.current.push({
@@ -857,7 +862,6 @@ export const WebViewProvider = ({ children }) => {
});
},
[
isWebViewReady,
encryptMessage,
resetWebViewState,
getNextSequence,