sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.45k stars 1.89k forks source link

Refresh SSG prerender without Vite Build #5761

Open cetra3 opened 2 years ago

cetra3 commented 2 years ago

Describe the problem

Right now it's not possible to run SSG without always building/bundling both the app & ssr bundle for production.

If no changes have been made to the frontend source, there's no current way to say "just update the prerendered set of pages".

In other words, if only the backend changes, then we shouldn't have to rebundle everything just to regenerate these pages.

Describe the proposed solution

A way to simply rerun the prerendering step independent of the bundling step, since bundling takes a long time.

I think this is independent of incremental build, since we want to "build" again, but not waste effort bundling if we don't have to.

Alternatives considered

I've looked at https://github.com/sveltejs/kit/issues/2369 but this still will go through the entire bundle/build.

Importance

would make my life easier

Additional Information

I have a website that periodically refreshes pages when content changes (only updates a few times a month). I'd like it so I don't have to waste too much time when changes are made to rerender these pages, since the backend will update much more often than the frontend source.

Rich-Harris commented 2 years ago

For some apps we could probably get away with having (say) a svelte-kit prerender command that does what you suggest. But it wouldn't be a general solution, because in many cases that would invalidate the service worker and the output of the adapter, so we'd have to design a way to get at those as well, and before you know it you're looking at some fairly invasive design changes.

It feels like the real solution here is some form of incremental static regeneration (#661).

cetra3 commented 2 years ago

OK, I'm assuming it's quite hard to just run that one function since it's coupled tightly with the vite workflow?

If that's the case I agree, ISR seems the way forward. However: I'd like it possible to only periodically run the command without having a node server active all the time!

Rich-Harris commented 2 years ago

Where does your built app currently live? I think the basic workflow would be webhook-based; if the build is local, I'm wondering if triggering the webhook locally while running vite preview could work.

Though now that I think it through, the service worker will still be invalid, and its caches would need to be purged, and in some cases the adapter would need to re-run... hmm. Will be an interesting challenge to solve.

benmccann commented 2 years ago

in many cases that would invalidate the service worker and the output of the adapter, so we'd have to design a way to get at those as well, and before you know it you're looking at some fairly invasive design changes

One idea that wouldn't be too much work would be to make prerendering, service worker, and adapter each be their own Vite plugin. Then users could define two Vite config files: one with all the plugins and one with just those plugins.

Users could also potentially provide their own versions of those plugins. E.g. implement their own prerendering algorithm, replace the service worker plugin with vite-plugin-pwa, etc.