Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prerender during build rather than adapt #4112

Closed
Rich-Harris opened this issue Feb 24, 2022 · 4 comments · Fixed by #4192
Closed

Prerender during build rather than adapt #4112

Rich-Harris opened this issue Feb 24, 2022 · 4 comments · Fixed by #4192
Milestone

Comments

@Rich-Harris
Copy link
Member

Describe the problem

Currently, prerendering happens inside adapters. This creates various minor problems:

  • svelte-kit preview doesn't use prerendered pages — loss of fidelity, and slow performance that's unreflective of production build
  • adapters have to be careful to prerender before generating manifests
  • prerendering doesn't happen if you haven't configured an adapter, or you're doing svelte-kit build locally with adapter-auto (unless you prefix it like VERCEL=1 npm run build)

Describe the proposed solution

I think prerendering should happen during build, before the adapter runs.

The fly in the ointment is adapter-static, which needs to specify that all pages should be prerendered (not just those explicitly marked as capable of being prerendered) unless a fallback is specified. A config.kit.prerender.all or config.kit.prerender.default option could stand in for that, and could also mean 'prerender everything without export const prerender = false. Together with a builder.prerenderFallback method, we could solve the adapter-static problem in a way that gives everyone a bit more flexibility. (Would probably need to make adapter-static aware of the all/default option via the builder so that it can instruct people to update their config accordingly.)

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

@Rich-Harris Rich-Harris mentioned this issue Feb 24, 2022
5 tasks
@benmccann
Copy link
Member

Another thing that has been an issue is that the service workers are currently generated before prerendering and so they can't include prerendered content. We might be able to fix that as well if prerendering happened during build

@Rich-Harris
Copy link
Member Author

Ah yeah, excellent point. That's a decisive advantage

@benmccann benmccann added this to the 1.0 milestone Feb 25, 2022
@kdheepak
Copy link

(I'm going to tag on a couple more issues here as comments that I might might be related.)

Sometimes I get an error during npm run build. This doesn't happen all the time, but happens occasionally and the frequency of occurrence is higher when I delete the .svelte-kit folder and run npm run build. This error occurs when

  • I have same .png content in multiple files that were linked as .png assets, and
  • these assets are around 40kb linked from one of my routes,

What I think is happening is that the "build" stage inlines it to a "data:..." image but the "adapt" stage doesn't know that (???), and npm run build fails. I'm using the static adapter. I haven't been able to consistently reproduce this which is why I haven't opened an issue for this.

@Rich-Harris
Copy link
Member Author

Related: #3792, which would be fixed by config.kit.prerender.default (or all, or whatever it gets bikeshedded to)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants