There’s an edge case that seems to be failing on Shopify’s end, where the app embed activation link ends up opening a draft theme instead of the live one. Here’s how to reproduce the problem:
Open the app’s theme app embed activation in a new tab: window.open(https://admin.shopify.com/store/{shopName}/themes/current/editor?context=apps&activateAppId={extensionId}/{extensionBlock}, ‘_blank’);
Close the theme tab without activating the extension
Publish a new theme as the live theme
Open the app’s theme app embed activation exactly as before
Result: Shopify will open the activation for the previous live theme that’s now in Draft, instead of the new one.
Maybe I’m doing something wrong or is this a bug on Shopify’s end? Any insight is appreaciated!
@Liam-Shopify@KyleG-Shopify@Alan_G Any possibility of someone at Shopify to look into this? The link gets stuck redirecting to the draft theme. Even if it’s an edge case, this is most probably affecting all apps using the app embed activation link.
Hey @Pridentt thanks for your patience on this. Just out of curiosity and to narrow down what might be happening, is this behaviour still occurring if you open the activation with a standard link in the same tab instead of with window.open, and also try in an incognito window to rule out session state?
Hey @Alan_G, thank you for your attention here, it’s really appreciated
My tests seem to indicate that indeed, the issue is related to the admin session state:
If I open the link with window.open(link, "_blank")
→ Opens incorrect Draft theme
If I open the link with an anchor tag <a target="_top" href="...">link</a> (i use “_top” because my app is embedded)
→ Opens incorrect Draft theme
If I manually copy the link and paste it in a new tab
→ Opens incorrect Draft theme
If I manually copy the link and paste it in another browser with the same account logged in
→ Opens correct Active theme
Regarding the rest of your questions:
I didn’t notice that I wasn’t using the deep link format shown in the current documentation (https://<myshopifyDomain>/admin/themes/current/editor?context=apps&template=${template}&activateAppId={api_key}/{handle}). Unfortunately I tried using it and the result was the same.
I open the the activation deep link in a new tab because this is a step in the onboarding flow in my app, and using the same tab to open the theme editor has a major potential to make users leave the process.
The deep link is generated in my app by simply replacing the values in the format that I’m currently using.
I’m assuming that the more definitive solution to this is to get the current live theme id and use it in the format that you suggested for the deep link (.../themes/{liveThemeId}/ instead of .../themes/current/...), but I haven’t tried it yet, I’ll give it a shot between today and tomorrow and let you know how it goes. Still, this would mean that the normal .../themes/current/... deep link is not working properly though.
Hey @Alan_G, I tried using the the liveThemeId as you suggested (https://admin.shopify.com/store/{shop}/themes/{liveThemeId}/editor?context=apps&activateAppId={extensionId}/{extensionBlock}) and it worked!
So finally, the solution goes like this:
In my app, I fetch the live theme id from the Admin API each time the user focuses the page, to make sure I have the updated main theme id.
I generate the deep link with the format mentioned above, making sure to use this /themes/{liveThemeId}/, instead of the format mentioned in the docs: .../themes/current/...
This result in the deep link always opening the current live theme
IMHO I think this still counts as a bug, because the .../themes/current/... deep link, which is the one recommended in the documentation, is not working properly due to the admin session state.
I hope this helps! I’ll mark this one as the solution as it solves my initial problem, thanks!
Thanks for trying that @Pridentt - glad the workaround works for now. I’ll look into this a bit more deeply for you internally and loop back here to share more info when I can.
Hey @Pridentt - sorry for the long delay here. We’ve identified that your initial report on this was a bug on our end and are working on a fix. I’ll let you know once the fix is live
Hi @Pridentt - just following up on this. We did push a fix for this a little while back, just following up some older threads. Let me know if we can help out further!