Hello, my app currently uses @shopify/app-bridge version 3.7.11 and initiate modal fullscreen via those instances from that package. However, it gets the problem with the X button on the right corner of fullscreen modal. When clicking it, it should fire event Fullscreen.Action.EXIT to my app and I can move on with the logic code after that but not. It does not trigger any event.
I use ClientApplication to subscribe event like this in my code
app.subscribe(Fullscreen.Action.EXIT, onExit);
Could you give me some advice without switching to version 4 because that version modal cannot be integrated well. I get new problems with version 4 modal such as using isolated iframe and css not working, some external packages do not work correctly.
Just confirming this looks tied to the legacy npm App Bridge fullscreen action. That package line is in maintenance mode now, so I wouldn’t recommend relying on a change to the v3 X-button/Fullscreen.Action.EXIT behavior here.
For the current supported fullscreen-style flow, I’d use an s-app-window with a src route and listen for the hide event. That should give you the close lifecycle hook you’re looking for when the merchant exits from the Shopify-controlled top bar.
I definitely get the concern around iframe/CSS/package behavior in newer App Bridge modals. For more complex flows or third-party libraries, the better path is a route-based modal/app-window rather than an HTML-content modal, and then include the CSS/JS needed by that route directly.
If you can reproduce the same missing close event with current App Bridge/CDN APIs, sharing a minimal repro would help us take a closer look. Hope this helps a bit.
I tried the new Shopify modal before but when using “src” attribute and render another page inside that modal, it costs me lot of effort to update code because it requires to communicate between modal iframe and the embed app iframe, which does not happen in old modal.
Hey @brian.ta, thanks for trying that and no worries!
Yeah, that extra iframe-to-iframe communication is one of the tradeoffs with src modals/app windows. Since src modals/app windows load a separate route into their own iframe, they don’t directly share the parent app frame’s JavaScript context. Our supported pattern is to communicate between the modal route and parent app frame with postMessage. There’s a bit more info here:
For the closest replacement to your old Fullscreen.Action.EXIT flow, I’d keep the close lifecycle logic in the parent app frame instead of the modal route:
const appWindow = document.getElementById('my-app-window');
appWindow.addEventListener('hide', () => {
// run your exit / cleanup / refresh logic here
});
Then use postMessage only for data or actions that need to move between the modal route and the parent app. A common pattern is to pass initial state into the route, let the modal route save/update what it needs to, and have the parent refetch or clean up when hide fires.
If your modal content is simple enough and doesn’t need third-party libraries or direct document access, an inline modal may reduce that communication work. For complex flows, though, src / s-app-window is the supported path.
If you’re seeing the current s-app-window hide event not fire when closing from the Shopify-controlled X, a minimal repro would be the best next thing to share so we can take a closer look. Happy to do that if needed for sure!
Hi @Alan_G, I tried to migrate my code to new version of the fullscreen modal but I got a small problem about backward and forward of the browser. When I was in fullscreen and click back/forward browser button, I didn’t receive any event from the modal component to close it. Can you help me for this?
My code just simply uses component from @shopify/app-bridge-react version 4.
Hey @brian.ta - I tested this with @shopify/app-bridge-react 4.2.12 and was able to reproduce what you’re seeing.
Browser Back/Forward changes the app route, but it doesn’t dismiss the fullscreen modal. Since the modal remains open, onHide isn’t fired. Closing it with Shopify’s X does fire onHide as expected.
As a workaround, I’d close the controlled modal when the route changes:
I wouldn’t rely only on popstate, since that wasn’t emitted consistently during my testing.
I definitely get that this isn’t super ideal for a fullscreen flow though. I’m going to flag the browser-history/modal lifecycle behaviour on our end and will loop back if there’s more to share. Hope this helps in the meantime!
Hi @Alan_G, thank you for your reply.
I’ve tried with your workaround suggestion but unfortunately it does not work. I put the useEffect in both iframes (embedded app and fullscreen modal) but I received nothing.
The below image is rendered in embedded app’s iframe. I also added another one in fullscreen modal iframe. Before your reply, I also tried with popstate but received nothing too. That’s kinda weird. But after all, thank you for your support, I’m looking forward to hearing from you.
Hey @brian.ta - thanks for testing that and sharing the screenshot.
I retested the workaround on my end here, and realized that it only works when Back/Forward changes a route owned by the parent embedded app’s React Router. In that case, useLocation().key changes and closing the controlled modal works. I also confirmed that popstate doesn’t fire consistently here, so I do think something is up here.
The src modal is a separate iframe, so it won’t receive the parent app’s location changes. If the browser navigation happens at the Shopify Admin level or unloads the embedded app, the parent’s route effect won’t run either. That would explain why neither iframe logged anything.
Could you confirm:
Is location coming from React Router’s useLocation() rather than window.location?
Which router are you using, and do the app iframe’s pathname/search values change when you click Back or Forward?
I’m still looking into the broader modal/history lifecycle internally on our end and will loop back when I have more to share.
Hi @Alan_G , my “location” I used is come from `useLocation().
My app currently is using “react-router-dom”: “^5.3.3” and when I navigate between pages, the iframe of my app does not change pathname/search values. I just send Shopify protocol event to change the top URL like the image below for future reloading page.
Hey @brian.ta - thanks for confirming those details, that’s really helpful.
I’m still looking into the modal and browser-history behaviour internally on our end here. I’ll keep you in the loop and will follow up once I have more information to share.