Open mkromann opened 1 year ago
Hey @mkromann 👋
Good catch and thanks for opening an issue. Sorry this isn't working as expected.
It would be nice to do something here, and I would like to, because performance is super important. I'm going to chat with the Remix team, and the Shopify apps team to see what we can do here and we'll get back to you.
I also want to share some context on why this is difficult.
Last time I looked:
<link rel="prefetch"/>
to prefetch stuff.The problem there is that authenticate.admin(request)
from shopify.server
relies on either a URL param or a session token header to authenticate the request because cookies won't work in the iFrame. URL params may expire (and we have no ways to set a fresh one), and we have no way to set an authorization header.
Some possibilities here:
AppProvider
from @shopify/shopify-app-remix
. It would look for <link rel="prefetch"/>
and perform a fetch request instead, which would warm the browsers cache.<Link/>
component to @shopify/shopify-app-remix
. It would take the same API as Remix's <Link/>
component but would handle prefetching itself, ensuring there is a session token param. Just to set expectations we have some missing API's and bugs we need to get to first, so it might be a while, but I do want to do something here.
Thanks for the answer @byrichardpowell. It's definitely something that have me considering foregoing embedding our internal apps.
I am not deep into how this could be resolved but will the proposed Middleware help here? Guess not, as it affords to modify to incoming request. https://github.com/remix-run/remix/discussions/7642
Hey @mkromann
Totally understand wanting to provide the best experience possible, that's awesome, thank you 🙏
For context, I think non embedded apps come with their own UX tradeoffs like forgoing App Bridge components and the Shopify navigation. We'll look into the preloading issue though.
Just curious if there's any rough timeline on supporting this? Thank you!
Maybe we can add a component to @shopify/shopify-app-remix. It would take the same API as Remix's component but would handle prefetching itself, ensuring there is a session token param.
Any pointers to how one can generate the session token to do this themselves?
any updates on this issue?
+1
Issue summary
It seems like Remix's prefetch functionality isn't working. Prefetched routes are not authenticated, and results in the user being redirect to the auth page when clicked. See the logs below.
@shopify/shopify-app-remix
version: 2.0.1Expected behavior
I expect to be taken to the prefetched route. And to work as detailed by Remix here: https://remix.run/docs/en/main/components/link#prefetch
Actual behavior
The user is redirected to the auth/login route.
Steps to reproduce the problem
prefetch='intent/render/viewport'
on aLink
orNavLink
.Link
/NavLink
.