Visible delay when typing in a text input
Hi, I'm trying to use Qwik for the search on my site. It's the only interactive part on the site and so far has been done with a normal script tag in Astro:
So I replaced the search with Qwik but when I do a production build and use it, there is a visible delay on the first search. It seems that the component is only fully downloaded once you trigger the event listener, which leads to a bad UX.
Here's how I setup the event listener:
<input
type="text"
class="outline-none w-full px-2 py-2 xl:py-4 rounded-r xl:rounded-r-2xl"
placeholder="Search"
bind:value={searchString}
/>
Unfortunately I haven't found out how to initialise everything on page load so that the first search is snappy as well. (Also idk why it downloads around 5 files, upon inspection it seems to be the hooks etc)
Anyway here's a link to try, just search for is on the site: https://deploy-preview-20--visionary-rugelach-7f4621.netlify.app/ and you should see that it takes quite some time to render the result, afterwards its fine.
Any help is appreciated.
Hey @tmkn! First off, awesome project you got there 😄 .
So I replaced the search with Qwik but when I do a production build and use it, there is a visible delay on the first search. It seems that the component is only fully downloaded once you trigger the event listener, which leads to a bad UX.
Yeah so I don't want to jump the gun here as it could be an implementation issue, but on first glance my understanding is there is a slight delay on first interaction without speculative module fetching. This is something currently in Qwik City, but because Astro is the meta-framework here it's functionality we'd have to add.
https://qwik.builder.io/docs/advanced/speculative-module-fetching/#speculative-module-fetching
Which I definitely think is a major priority adding this functionality to the integration if that's the case. Will reach out to the core team and get back with you on that.
In the meantime, I would actually take your component and try it out in Qwik City to see if that's the case, as Qwik components are usually instantly interactive. This is because they do not hydrate.
Happy to look into some of the implementation details as well, I do think that Qwik fits extremely well in the context of Astro, as all it needs is the HTML. We purposefully want to delay the execution of code rather than page load, as it is supposed to be prefetched on a separated thread.
Hey, thanks :)
Yeah, according to the FAQ the files should have been prefetched: https://qwik.builder.io/docs/faq/#isnt-requesting-js-on-user-interaction-slow
I guess its not enabled/bug in the current Astro integration and not a general technical limitation. I think Qwik pairs nicely with Astro when you want to add some interactivity to your SSG site, so I hope this can be made work ✌️
Hey, thanks :)
Yeah, according to the FAQ the files should have been prefetched: https://qwik.builder.io/docs/faq/#isnt-requesting-js-on-user-interaction-slow
I guess its not enabled/bug in the current Astro integration and not a general technical limitation. I think Qwik pairs nicely with Astro when you want to add some interactivity to your SSG site, so I hope this can be made work ✌️
Yeah it's definitely possible, and it looks like quite a big priority. Will make sure it's added in the Astro integration as soon as we get the opportunity👍 . I'm still unsure if this is something we can move into Qwik core or not, or if we need to add it on the Astro side. Waiting on a response there.
Qwik is great for any sort of interactivity really, including SSR. The resumability aspect is awesome with speculative module fetching and Qwik insights. Another thing we probably need to support with Astro.
Hey @tmkn! Update, the core team confirmed it is speculative module fetching. I will try to move this into Qwik core so that it can be used in the Astro integration.
Everything @thejackshelton said 👍
Some more light:
Currently, SW (service worker for prefetching) is tied with QwikCity. This is an issue since the same problem arises if you have MFE (Micro Front End) and you want to prefetch multiple MFE into one SW.
Fixing MFE is actually next on my list, and doing so will require moving the SW from QwikCity to Qwik. Once that happens, it should be straightforward to integrate it with Astro.
In the meantime, you can cheat a bit. If you add useVisibleTask$() to your component, it will cause eager code execution, which will force at least some of the code to load eagerly.
Hey @tmkn! Happy to announce that speculative module fetching is now in the integration!! This means your interactions should be instantly interactive, even on slow 3g.
Thanks for the work 👏
However, it seems that at least in my case it's not yet working.
Not sure if I need to do anything else but I updated @builder.io/qwik to 1.3.5 and @qwikdev/astro to 4.0.0.
Now, when I start a debug or production build, I get exceptions like:
it throws here:
As you can see the
qc variable is undefined (coming from document.currentScript.closest('[q\\:container]')).
It seems that when the script runs, there is no q:container element yet. (There are, once the page is loaded though)
So it seems like there's a race condition going on? Or I'm missing a setting.
You can see it live here. Repo is here.
Thanks!
The above is erroring because of this:
Notice that <script qwik-prefetch-bundle-graph> is NOT a child of <div q:container> Not sure how the script got there, but it needs to be move inside of the container, and then it should work.
@tmkn try 0.4.1
tried 0.4.1. While it doesn't throw any more it doesn't seem to prefetch, it still loads the files upon keypress.
Looks like it doesn't load q-bundle-graph-.... it populates window.qwikPrefetchSW though
tried
0.4.1. While it doesn't throw any more it doesn't seem to prefetch, it still loads the files upon keypress. Looks like it doesn't loadq-bundle-graph-.... it populateswindow.qwikPrefetchSWthough
Try 0.4.2, also if you could show the latest demo version.
@mhevery what was the command to "prefetch the whole world" we discussed this week?
hmm still doesn't seem to preload, preview link is the same as before: https://deploy-preview-20--visionary-rugelach-7f4621.netlify.app/
hmm still doesn't seem to preload, preview link is the same as before: https://deploy-preview-20--visionary-rugelach-7f4621.netlify.app/
Seems to be prefetching correctly / instantaneous for me. Keep in mind, this is "bundle prefetching" not the native browser prefetching.
@mhevery wasn't there also a command to "prefetch the world" in the browser just in case?
Seems to be prefetching correctly / instantaneous for me. Keep in mind, this is "bundle prefetching" not the native browser prefetching.
Yes it seems to prefetch on a subsequent reload. if you clear the cache and reload, the files will be loaded upon first interaction, after that on a reload they will be prefetched again.
not sure if it is planned to also preload on the first load but it would be nice. anyhow, the ux is already much improved!
Ah I do see the error on first load now, tried it with a different browser
qwik-prefetch-service-worker.js:1 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'match')
at qwik-prefetch-service-worker.js:1:659
at qwik-prefetch-service-worker.js:1:779
at Array.map (<anonymous>)
at t (qwik-prefetch-service-worker.js:1:400)
at e (qwik-prefetch-service-worker.js:1:143)
at qwik-prefetch-service-worker.js:1:2201
at async qwik-prefetch-service-worker.js:1:2140
Maybe @mhevery's latest change in qwik core will fix this? https://github.com/BuilderIO/qwik/commit/fb7f8855d3bcf4b33f5edfc301929cf36da6eab2
Seems to be prefetching correctly / instantaneous for me. Keep in mind, this is "bundle prefetching" not the native browser prefetching.
Yes it seems to prefetch on a subsequent reload. if you clear the cache and reload, the files will be loaded upon first interaction, after that on a reload they will be prefetched again.
not sure if it is planned to also preload on the first load but it would be nice. anyhow, the ux is already much improved!
Do a hard refresh with ctrl + F5
Then
Try Qwik 1.4 and see if you still get the console error on first view
Hey @tmkn closing this issue, tested a netlify deploy and didn't seem to get this error on first load with Qwik 1.4
If you have any more problems specific to the delay, happy to open this issue back up, or you can create a new one.