Shopify / shopify-app-bridge

https://shopify.dev/docs/api/app-bridge
85 stars 9 forks source link

getSessionToken() hangs after redirecting to app URL #179

Closed ascherkus closed 1 year ago

ascherkus commented 1 year ago

Describe the bug

After our app is gets loaded when redirecting to the app URL (e.g., a 302 to https://foo.myshopify.com/admin/apps/my-app after, say, handling the approve charge callback), App Bridge initializes but calling getSessionToken() hangs.

The promise never completes nor is rejected. As far as I can tell, there are no exceptions, errors, or logs emitted.

To Reproduce

Steps to reproduce the behaviour:

  1. Have app mobile optimization enabled
  2. Load app and call getSessionToken() to confirm it works
  3. Create a Recurring Application Charge with a callback to your backend
  4. After approving the charge and receiving the callback, issue a 302 redirect to https://foo.myshopify.com/admin/apps/my-app to get Shopify app to load app again
  5. Call getSessionToken() as in step (2)

Expected behaviour

App Bridge loads and getSessionToken() completes as expected.

Contextual information

We see the following:

# Initial embedded load -- we return a 200 and load our Single Page App
GET /settings?embedded=1&hmac=...

# User selects a plan and we generate a Shopify charge URL and do a client-side redirect
 this.props.app.dispatch(
        Redirect.toRemote({
          url: shopifyChargeUrl,
        })
      );

# After approving, our backend's charge handler gets called and we return a 302
# back to our app at https://foo.myshopify.com/admin/apps/my-app
GET /charge?etc...

# Client loads the full app again -- the request looks identical to first time around
# but now App Bridge getSessionToken() hangs
GET /settings?embedded=1&hmac=...

Packages and versions

List the relevant packages youโ€™re using, and their versions. For example:

Platform

PaulLiamAG commented 1 year ago

Hey,

I just wanted to say, I'm also running into this issue with an app in production. also debugged the issue locally, and came to the same conclusion around getSessionToken never resolving or rejecting. I have tried using a lower version of the package but still getting the issue.

Any known workaround would be helpful as currently our app does not load.

PaulLiamAG commented 1 year ago

Hey @henrytao-me, any update on this,

While debugging locally, it seems no actions get dispatched when I, for example, clicked a button to show a Toast, initializing app bridge did not throw any errors, but the action did not show up when debugging via the Console app on mac (If I remember correctly they did in the past, and others triggered by POS app do)

henrytao-me commented 1 year ago

Hi @ascherkus and @PaulLiamAG, I was able to reproduce the issue only once but I know which code could cause the issue. I will push a fix soon. Thanks for reporting the issue ๐Ÿ™‡

henrytao-me commented 1 year ago

@ascherkus: can you confirm which Shopify app having this issue? Is this Shopify Mobile or Shopify POS?

henrytao-me commented 1 year ago

@ascherkus Can you share your appId (or apiClientId) that I can test the fix? We can chat in partners slack if you don't want to share the id here. ๐Ÿ™‡

henrytao-me commented 1 year ago

Confirmed: the fix should be available in Shopify Mobile 9.100.0 which will be released next week ๐Ÿ™‡. I close this for now. Feel free to reopen if needed.