The flow:
-
User is on my app’s homepage
-
User clicks a link that opens the Theme Editor in a new tab (to enable an app embed)
-
User enables the embed and returns to my app tab
-
I want to automatically refresh the embed status without requiring a page refresh
What I’ve tried:
useEffect(() => {
const handleVisibilityChange = () => {
if (document.visibilityState === 'visible') {
// Check embed status via GraphQL
checkEmbedStatus()
}
}
document.addEventListener('visibilitychange', handleVisibilityChange)
return () => {
document.removeEventListener('visibilitychange', handleVisibilityChange)
}
}, [checkEmbedStatus])
The problem:
The visibilitychange event doesn’t seem to fire reliably when the app runs inside the Shopify Admin iframe. I’ve also tried window.addEventListener('focus', ...) but that doesn’t work either.
Questions:
-
Is there a recommended way to detect tab/focus changes in embedded Shopify apps?
-
Does App Bridge provide any hooks or events for this use case?
-
Is polling the only reliable solution, or is there a better pattern?
Tech stack: Remix, React, Shopify App Bridge