-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[馃悶] SPA resume (probably) needs to be fixed for upcoming v2 changes #5983
Comments
Thanks Jordan! Question: how about always including the spa context, would that also solve it? Is it that huge? |
I don't think this is possible, the When I first designed the SPA resume and scroll restore it was clear to meet the demands for all cases, it had to exist kind of outside Qwik & Qwik City such that it will hook in to With that said, this can be fixed very easily by simply including a new attribute with a magic string on the Link component and selecting on that. This wouldn't require any other changes I think. But perhaps maybe someone can find a better way to expand functionality to work for all cases of |
Hmm I'm afraid I don't understand. Apart from the contexts' data that Link uses, what needs to be shipped to the client to enable SPA? |
The If this isn't present then it falls back to simply reloading the page with To make it more clear, this resume is included on every single Qwik City page even MPA. Except it's just a tiny couple-line shim, the actual script is gated behind a When a user refreshes a page that was arrived at through SPA, or re-opens browser, etc. the navigate context is lost. This whole contraption is designed to track and restore scroll positions no matter what the user does or how badly things get messed up and it has to do it without impacting MPA; it always just works and it's nearly free. Hope that explains everything. And like I said above, there's a couple line solution to fix this problem and maintain current limitation (dependence on Link), I updated the issue to explain. |
partially fixed #6022 |
Which component is affected?
Qwik City (routing)
Describe the bug
Explanation
SPA resume (popstate after refresh/reload) needed to exist outside of Qwik in order to keep it simple and not pull in anything that is not already being used on a page.
For this reason, when a popstate occurs on a page where SPA context was lost, it only directs the page back into the
useNavigate
pipeline when an already-existinguseNavigate
context exists on the page, and falls back tolocation.href
refreshing.This functionality solves all cases:
useNavigate
ctx will be restored into the SPA pipeline.useNavigate
, but does not contain either, and a refresh occurs. It isn't possible to differentiate this page from a purely MPA during SSR, nouseNavigate
ctx can be included.Problem
The simple and quick way of hooking back into the
useNavigate
ctx was to:Link
, specifically ana
element with the attributeq:key="AD_1"
.q:nbs
(Nav BootStrap) would be attached.href
attr and instead call:nav(location.href, { type: 'popstate' })
click()
and is pushed through the loader normally, resuming the app, everything just works.This was simple even though it only works if the official Link component is present, and I didn't understand internals enough to decipher and jiu-jitsu a hand-crafted way to directly detect and hook any case of
useNavigate
ctx on the page from theqwik/json
in the time available. (that would've needed adapting to v2 as well)With the upcoming Qwik v2 changes as they appear in this blog post: https://www.builder.io/blog/qwik-2-coming-soon. It appears the current method of detecting a Link described above might not work anymore. Specifically because it relies on a
q:key
attribute on thea
element. Can someone confirm this?Solution(s)
If this does turn out to be an issue, some possible solutions:
Link
component'sa
element with a magic string and use that to select a Link on the page.useNavigate
, even with justnav()
or custom Links, and somehow hook into this directly. This would remove dependence on the officialLink
component.Unfortunately I do not currently have the time it would require to setup a dev environment on v2 and investigate and adjust this behavior. Hopefully the few minutes it took to explain this issue in detail is helpful to someone in solving this.
For reference, here are the current parts of the code that are described above:
https://github.com/BuilderIO/qwik/blob/157f7b01df22448638f7cc55546a051aa4eea5f0/packages/qwik-city/runtime/src/spa-init.ts#L74-L78
https://github.com/BuilderIO/qwik/blob/157f7b01df22448638f7cc55546a051aa4eea5f0/packages/qwik-city/runtime/src/link-component.tsx#L70-L72
Reproduction
N/A
Steps to reproduce
No response
System Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: