You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#2104 introduced throwing an error when page.query was accessed. This makes sense to prevent usage on the client, but now you cannot use it during load which was beneficial for prerendering crawled pages. For example, a page displaying a list of blog posts with pagination using a ?page=X query. As long as those can be crawled, using query is OK here.
Describe the proposed solution
Check if page.query is being accessed on the server before throwing the error
I could use params instead, which is probably better in most scenarios, but in my case I'm using it on my index page and it's more awkward than using a query. I would prefer mywebsite.com/?page=2 over mywebsite.com/2.
Importance
would make my life easier
Additional Information
Here's an example of a template I made that utilized crawled pages with queries (you'll have to set const PAGE_SIZE = 1 in routes/index.svelte to get more than 1 page):
Even on 144 your template was broken in some ways - it was just hidden to you. E.g. if you build the site and visit /?page=2 directly it will still load page 1. That's not what I'd expect as a user. This check pointed out that what you're doing is not valid
Prerendering works by saving a static file with the name of the page. In your case index.html. But we can't save an index.html and index.html?page=2. ? is an invalid character on at least some file systems and your web server wouldn't know to serve a different file based on the query string.
If you really want to use ?page=2 then be aware that it's something that only works on the client-side and use location in onMount instead.
I hadn't realized it only worked on client-side navigation (and obviously that's not what I'd expect as a user either). I appreciate the explanation, as I wasn't sure how it "worked" in the first place, but that makes sense.
Describe the problem
#2104 introduced throwing an error when page.query was accessed. This makes sense to prevent usage on the client, but now you cannot use it during
load
which was beneficial for prerendering crawled pages. For example, a page displaying a list of blog posts with pagination using a?page=X
query. As long as those can be crawled, using query is OK here.Describe the proposed solution
Check if page.query is being accessed on the server before throwing the error
https://github.com/sveltejs/kit/pull/2104/files#diff-7266c49c71803f38dda70345d857f13a7a2494cc649b70af6b689627199f5b79R53-R63
Alternatives considered
I could use params instead, which is probably better in most scenarios, but in my case I'm using it on my index page and it's more awkward than using a query. I would prefer
mywebsite.com/?page=2
overmywebsite.com/2
.Importance
would make my life easier
Additional Information
Here's an example of a template I made that utilized crawled pages with queries (you'll have to set
const PAGE_SIZE = 1
inroutes/index.svelte
to get more than 1 page):https://github.com/mattjennings/sveltekit-blog-template
The build will work with kit 1.0.0-next.144, but break on 145
The text was updated successfully, but these errors were encountered: