App extension admin links - incorrect order id(s) received

Our app adds admin link extensions to the order details page and the order action drop-down list. The links are supposed to include the order id of the viewed or selected order as a query param. They link presented is correct, but when clicking it the order id received is frequently pointing to the previously selected order rather than the current.

Example:
I select order 1000 and click the app extension link. Query param ids[]=1000 is usually received, but sometimes it’s not there at all.

If I then go back to the order list and click the extension link for order 2000, the query param received is ids[]=1000 where ids[]=2000 was expected.

Going back to the order list and clicking the extension link for order 1000 again, the query param received is now ids[]=2000 where ids[]=1000 was expected.

This pattern repeats itself. The value of the id parameter is frequently one step behind, although not always. I am able to reproduce the issue regardless of the app the extension admin link points to.

Result after clicking:

Hi Cdwinsnes,

The issue you’re experiencing seems to be related to asynchronous data handling. It’s likely that the order ID is being fetched and set asynchronously, and the link is being generated before the new ID is fully fetched and set, hence the previously fetched ID is being used.

Here’s a general approach to investigating and potentially solving this issue:

  1. Check how you’re fetching and setting the order ID. Ensure that the ID is being updated correctly before the link is generated.

  2. If you’re fetching the order ID asynchronously (like using AJAX or Fetch API), you might be running into race conditions. This means your code doesn’t wait for the order ID to be fetched before generating the link. In this case, you should ensure the link is generated only after the fetch operation is completed. This can be achieved by using async/await or Promises.

  3. If you’re using some kind of management or caching, the old value might be getting used instead of the new one. Make sure that the correct value is being updated in your or cache.

  4. If the link generation is tied to a click event or some other event, it’s possible that the event is being triggered before the order ID is fully fetched. In this case, you should ensure that the fetch operation is completed before the event is triggered.

Try the above approaches for troubleshooting and let us know if you’re still running into issues. Hope this helps!

I have no control of these links as they are generated and set by Shopify outside my app boundary. This is can be reproduced regardless of the app the admin link points to. It’s the values passed to my app that is the problem, not the handling of the value within the app.

I’m therefore certain this is a bug in Shopify itself. I’ve also come across other reported issues where the same is experienced:

https://github.com/Shopify/shopify_app/issues/1731

Thanks for the reply Cdwinsnes - this does indeed look like a bug, I’ll connect with our team on this. It might be best to keep an eye on this github issue for an update: https://github.com/Shopify/shopify_app/issues/1731