Closed shilangyu closed 6 months ago
This is not a bug with this library, it's just how sveltekit works.
I understand that, but could this library just return null just like it does during ssr? Is this a fundamental limitation of sveltekit that cannot be overcome?
Perhaps this should've been a feature request rather than a bug report.
I understand that, but could this library just return null just like it does during ssr? Is this a fundamental limitation of sveltekit that cannot be overcome?
Perhaps this should've been a feature request rather than a bug report.
The fact is that this library heavily relies on the page store which is what is throwing that error. So you can't actually access the search Paramus anyway. I'll try to look into your repro to see if there's a specific use case we can try to support but it seems very difficult.
Can you talk me more about your use case?
My usecase is simply that I am using prerendering with hydration (which I would expect to behave similarly to just ssr+hydration). I host my page as static files rather than behind a server.
If it's hard to support then nevermind, I will try to workaround it externally, however I have been unsuccessful at that so far. I thought that internally for the lib it's just about slapping an if (browser)
somewhere.
My usecase is simply that I am using prerendering with hydration (which I would expect to behave similarly to just ssr+hydration). I host my page as static files rather than behind a server.
If it's hard to support then nevermind, I will try to workaround it externally, however I have been unsuccessful at that so far. I thought that internally for the lib it's just about slapping an
if (browser)
somewhere.
The if(browser)
it's already there but the problem is the store that the library relies on throws an error in prerendering. I could maybe catch that error and return null but that doesn't change the fact that you will still get null when launching the application so i don't know if it's worth?
I experimented a bit and adding an extra conditions seems to do the trick. Before accessing .searchParams
I check the building
flag. If its true I fallback to null. The reactivity is still there and the initial value for the query param is correctly populated. I can send a PR if you want, but I do not want to impose if that doesn't align with the wants of this project.
Uh this is actually quite interesting... wasn't aware of the building flag....will experiment and update this issue
Ok this actually works...let me check when building was introduced to make sure it's not a breaking change and i'll push the changes.
Describe the bug
When
queryParam
is used on a page that has enabled sveltekit prerendering, the build crashes. This in theory is understandable because obviously there are no query parameters during build. However, I would expect the behavior to be the same as in during SSR: I get null and wait for hydration.Reproduction
Minimal reproduction repo: https://github.com/shilangyu/sveltekit-search-params-prerender
Run
npm run build
to see the problem.Logs