Skip to content

Expose registered components during SSR compilation #4854

Closed
@AlbertMarashi

Description

@AlbertMarashi

Is your feature request related to a problem? Please describe.
@Rich-Harris https://twitter.com/PromatiaGov/status/1262183956004220928

Svelte needs to expose which components the SSR compiler has come across during SSR Rendering. This will let the server-side renderer know which components have been registered, so the page can preload the necessary components on the client-side;

eg:

const { html, css, head, registeredComponents } = App.render()

Registered components may just be a new Set() with the unique ID of the component (perhaps a file path) - vue-loader uses some sort of module identifier that is the same across client & server-side I think.

This can allow Svelte routers and code-split svelte apps to enable faster loading speeds, as the necessary client-side scripts can be preloaded. The svelte-loader and rollup loader can make use of these, by matching the module's ID to a client-manifest. This would mean that svelte-loader would also need to be updated I believe.

vue-loader exposes a _registeredComponents, which is used by the server-side renderer and matched with the client manifest to find which async files should be preloaded on the website:

console.log(context._registeredComponents) // prints below

image

client-manifest
The number value of each module ID links to a specific output script
image

client manifest generator plugin
image

Not sure what would be the best way to go across this

Describe the solution you'd like
Not sure

Describe alternatives you've considered
Have tried to do route-level matching, but it's hard.

How important is this feature to you?
Pretty important feature for SSR, could be used by Sapper as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions