mattjennings / sveltekit-blog-template

A SvelteKit blog template
https://sveltekit-blog-template.vercel.app
MIT License
233 stars 35 forks source link

Update @sveltejs/kit #12

Closed ak4zh closed 2 years ago

ak4zh commented 2 years ago

I tried to update with the latest version @sveltejs/kit ^1.0.0-next.357 Everything works fine, I only stumble across one issue after the update.

The issue is the /posts only returns 2 latest posts, even when you paginate you will always get the latest 2 blog post only until you do a browser based hard refresh. The /posts.json endpoint also returns only 2 posts no matter how many blog posts you have. The above issue does not seem to occur in dev mode npm run dev, it only occurs after you build the app npm run build && npm run preview

I want to update the kit because I find the param matcher feature really helpful to split my post to different category like /posts, /projects, /ideas

CaptainCodeman commented 2 years ago

Looks like the limit is set to 2 here:

https://github.com/mattjennings/sveltekit-blog-template/blob/b67076aef13da1efa7a93730c1a3411098cdbc8b/src/routes/index.svelte#L7

mattjennings commented 2 years ago

Hm, strange. I've been holding off updating this template until 1.0 comes out as it seems to be around the corner. This didn't happen prior to updating kit? If you can create a reproduction so I can take a look that would be very helpful.

The recentPosts snippet is only used for the index page and shouldn't affect /posts (maybe there's some weird caching going on?)

ak4zh commented 2 years ago

@mattjennings The issue only arise after you update kit version to 1.0.0-next.357 (I did not tested with lower versions) Downgrading the kit to current locked version removes the issue immediately with no other change in the codebase (except some tiny stuffs like changing %svelte.head% to %sveltekit.head% etc.

Also notice you will not face the issue when you run it in dev mode npm run dev It only appears on production build npm run build && npm run preview

The issue has no relevance with the limit set in recentPosts. I tried to open the endpoint /posts.json without any query params and it still returns only 2 posts always even when you paginate it will always return same latest 2 post for every page and it also allows you to paginate as much as you want, you can go up on page count without any limit, even if you have just 20 posts, you can go to page 100 and still see same 2 post always.

mattjennings commented 2 years ago

@Ak4zh I've updated this template the latest version of kit and made a few changes. Please look over these changes or make a new copy of this repo and move your content over (probably the easiest way).

Here's a summary of the changes:

ak4zh commented 2 years ago

@mattjennings Thanks for the update. I am planning to make a pull request to probably add a search feature and post category. I am also wondering if there is a specific reason you chose to run pagination via a static url instead of query params?

mattjennings commented 2 years ago

I wanted to keep it working with the static adapter. Using query params would have meant SSR or client-side data fetching, and as a result breaking the static export. Now that it's using auto maybe I'll change that, I dunno. I don't want SSR to be a requirement (and therefore requiring vercel/netlify/a node server to deploy).

re: search & post category functionality, I'm probably just going to leave this template as it is features-wise. But I appreciate the idea!

ak4zh commented 2 years ago

The static pagination makes sense now. Thank you for the answers.