[BUG REPORT] Theme app embed activation: redirects to draft theme instead of live theme when it's changed

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:

  1. 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’);
  2. Close the theme tab without activating the extension
  3. Publish a new theme as the live theme
  4. 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!

Anyone knows anything about this bug? :smiling_face_with_tear:

Any help is appreciated

@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.

Any help is appreciated.

Hey @Pridentt :waving_hand: 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?

If you can try opening an explicit theme link using the live theme’s ID, for example https://admin.shopify.com/store/{shop}/themes/{liveThemeId}/editor?context=apps&activateAppId={extensionId}/{extensionBlock} and then after it loads, please copy the final URL you land on so we can see which theme_id it resolves to. Could you also let me know your workflow for opening the activation link, including why you open it in a new tab and how the link is being generated in your app? Is this happening with the standard deep-linking?

Happy to dig into this further for sure. Thanks again for waiting on a response too, it’s appreciated :slight_smile:

Hey @Alan_G, thank you for your attention here, it’s really appreciated :folded_hands:

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 :cross_mark:

  • 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 :cross_mark:

  • If I manually copy the link and paste it in a new tab
    → Opens incorrect Draft theme :cross_mark:

  • If I manually copy the link and paste it in another browser with the same account logged in
    → Opens correct Active theme :white_check_mark:

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!

1 Like

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.

1 Like

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 :slight_smile:

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!

1 Like

Thank you for the fix @Alan_G! :tada:

1 Like