Skip to content

Improve compile performance for ssr #121

@dominikg

Description

@dominikg

Describe the problem

Components are compiled twice for ssr.

  1. with generate: "ssr" for the serverside render
  2. with generate: "dom" for the clientside bundle

The current implementation runs preprocess for each step separately ​which is wastful, especially for more demanding preprocessors like postcss or mdsvex.

Also components that are never compiled for ssr still get compiled with hydratable: true. Even though they are clientside only.

Describe the proposed solution

To avoid duplicate preprocessing, compile both variants in parallel during transform with ssr: true and cache + reuse the compiled dom variant in subsequent transform with ssr: false

Only set hydratable: true in this parallel compilation, components that are only transformed with ssr: false can be compiled with hydratable: false to reduce output size.

Possible issue:
the special svelte/ssr resolve mechanism could break the dom output if it was compiled during the transform with ssr: true

If that is indeed the case, the preprocess result could be cached instead and used as an indicator that the client variant needs to be compiled with hydratable: true

Alternatives considered

stick with the current implementation. This plugin has had issues with aggressive caching for ssr before and caching was completely removed to avoid it.

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions