Skip to content

Prerendering overhaul #6356

Closed
Closed
@Rich-Harris

Description

@Rich-Harris

Describe the problem

There's a few improvements that need to happen to prerendering that, while separate, are probably best tackled in one go. The broader context for this is #6197, in which it will be possible to set export const prerender in a layout — e.g. the root layout — such that it will be inherited by all pages within.

  • Instead of being a boolean, prerender should be an enum so that we can distinguish between pages that can be prerendered from those that must be prerendered. The latter can safely be excluded from the SSR manifest, whereas presently we can only exclude prerendered pages without dynamic parameters
  • +server.js files should be able to declare their prerenderability (or otherwise) as well. +server.js files with POST etc cannot be prerendered.
  • Throw an error (or warn?) if using adapter-static with invalid routes #4287

Describe the proposed solution

Must-prerender pages could be declared with

export const prerender = 'always';

I'm not sure what a great name is for the current prerender = true (i.e. can-prerender). One suggestion was this...

export const prerender = 'maybe';

...though I would be interested in alternative suggestions. (This isn't something you'd use often — only in cases where, for example, you want to prerender your 1,000 most popular blog posts or whatever and let the long tail be SSR'd, though #661 would be a better solution in the longer term.)

Since +server.js files are standalone — i.e. they don't have a +layout to inherit from — the naive approach would be to make it necessary to declare the setting for every file individually, which is a pain. Instead, I think +server.js files should inherit their prerenderability from the pages that request them during prerendering (i.e. if an endpoint is only fetched by a must-prerender page, it can be excluded; if it is fetched by a can-prerender page or isn't fetched at all, it must be included). If necessary, it can be made explicit with export const prerender = value.

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions