@gadgetinc/react-shopify-app-bridge
Advanced tools
Comparing version
@@ -75,2 +75,3 @@ "use strict"; | ||
const hasFetchedOrInstalledShop = (0, react_2.useRef)(false); | ||
const hasStartedFetchingOrInstallingShop = (0, react_2.useRef)(false); | ||
const [{ data: fetchOrInstallShopData, fetching: fetchingOrInstallingShop, error: fetchingOrInstallingShopError }, fetchOrInstallShop] = (0, react_1.useMutation)(FetchOrInstallShopMutation); | ||
@@ -83,2 +84,9 @@ if (fetchOrInstallShopData) { | ||
} | ||
// we want to show the loading state until we've started fetching or installing the shop | ||
// or the mutation to fetch or install the shop has completed | ||
(0, react_2.useEffect)(() => { | ||
if (fetchingOrInstallingShop) { | ||
hasStartedFetchingOrInstallingShop.current = true; | ||
} | ||
}, [fetchingOrInstallingShop]); | ||
// always run one fetch to the gadget backend on boot to discover if this app is installed | ||
@@ -91,6 +99,7 @@ (0, react_2.useEffect)(() => { | ||
hasFetchedOrInstalledShop.current = true; | ||
console.debug("[gadget-rsab] fetching or installing shop"); | ||
console.debug("[gadget-rsab] getting sessionToken to fetch or install shop"); | ||
appBridge | ||
.idToken() | ||
.then((idToken) => { | ||
console.debug("[gadget-rsab] fetching or installing shop"); | ||
fetchOrInstallShop({ shopifySessionToken: idToken }).catch((err) => { | ||
@@ -120,3 +129,3 @@ console.error({ err }, "[gadget-rsab] error fetching or installing shop"); | ||
}, [gadgetAppUrl, isRootFrameRequest, originalQueryParams, redirectToOauth]); | ||
const loading = (forceRedirect || redirectToOauth || fetchingOrInstallingShop) && !isRootFrameRequest; | ||
const loading = forceRedirect || redirectToOauth || fetchingOrInstallingShop || !hasStartedFetchingOrInstallingShop.current; | ||
(0, react_2.useEffect)(() => { | ||
@@ -199,2 +208,3 @@ const context = { | ||
host, | ||
location, | ||
coalescedType, | ||
@@ -201,0 +211,0 @@ isReady, |
@@ -71,2 +71,3 @@ import { Provider as GadgetUrqlProvider, useMutation } from "@gadgetinc/react"; | ||
const hasFetchedOrInstalledShop = useRef(false); | ||
const hasStartedFetchingOrInstallingShop = useRef(false); | ||
const [{ data: fetchOrInstallShopData, fetching: fetchingOrInstallingShop, error: fetchingOrInstallingShopError }, fetchOrInstallShop] = useMutation(FetchOrInstallShopMutation); | ||
@@ -79,2 +80,9 @@ if (fetchOrInstallShopData) { | ||
} | ||
// we want to show the loading state until we've started fetching or installing the shop | ||
// or the mutation to fetch or install the shop has completed | ||
useEffect(() => { | ||
if (fetchingOrInstallingShop) { | ||
hasStartedFetchingOrInstallingShop.current = true; | ||
} | ||
}, [fetchingOrInstallingShop]); | ||
// always run one fetch to the gadget backend on boot to discover if this app is installed | ||
@@ -87,6 +95,7 @@ useEffect(() => { | ||
hasFetchedOrInstalledShop.current = true; | ||
console.debug("[gadget-rsab] fetching or installing shop"); | ||
console.debug("[gadget-rsab] getting sessionToken to fetch or install shop"); | ||
appBridge | ||
.idToken() | ||
.then((idToken) => { | ||
console.debug("[gadget-rsab] fetching or installing shop"); | ||
fetchOrInstallShop({ shopifySessionToken: idToken }).catch((err) => { | ||
@@ -116,3 +125,3 @@ console.error({ err }, "[gadget-rsab] error fetching or installing shop"); | ||
}, [gadgetAppUrl, isRootFrameRequest, originalQueryParams, redirectToOauth]); | ||
const loading = (forceRedirect || redirectToOauth || fetchingOrInstallingShop) && !isRootFrameRequest; | ||
const loading = forceRedirect || redirectToOauth || fetchingOrInstallingShop || !hasStartedFetchingOrInstallingShop.current; | ||
useEffect(() => { | ||
@@ -195,2 +204,3 @@ const context = { | ||
host, | ||
location, | ||
coalescedType, | ||
@@ -197,0 +207,0 @@ isReady, |
{ | ||
"name": "@gadgetinc/react-shopify-app-bridge", | ||
"version": "0.15.1", | ||
"version": "0.15.2", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "README.md", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
85137
3.23%572
3.62%