RFC: Client assets metadata API for SSR #20913
Replies: 1 comment 1 reply
-
|
We are currently reworking the CSS asset handling in SolidStart and are thinking about implementing a similar import parameter solution for the asset map retrieval. Awesome work on your part with this RFC, the provided examples and the vite-plugin-fullstack project! Unmounting of stale CSS on clientside navOne topic that we are still debating is route CSS unmounting on client-side navigation - SolidStart currently does it, making the implementation more complex, but more user friendly. Afaik lots of frameworks don't do it and neither does vite. I wonder what's the general stance of vite core developers on this? Should meta frameworks unmount stale route CSS on clientside nav, or just let it stay and force users to write proper non-global route css? If the stance is that meta frameworks should do the unmounts, I think that it might be worth it, to discuss implementing a generic unmount handling API next to this RFC (or part of it), or to document best practices in one of the Vite guides. Assets of lazy loaded componentsI am the maintainer of the Solid Lazy Plus library, which provides a import { getManifest } from "solid-start:get-manifest";
// This works in dev & prod
const assets = await manifest.getAssets(id);In this case, the id is a runtime variable, which makes me wonder if/how this would work with your import parameter based API? Like below? const assets = await import(`${id}?assets`);Either way, I think the use case of a dynamic id should definitely be considered in this RFC. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This proposal introduces a new API that enables server code to access client runtime assets metadata required for server-side rendering in a framework agnostic way. This feature is currently prototyped in the package
@hiogawa/vite-plugin-fullstackwith examples listed below.Motivation
The new API addresses two critical challenges that every SSR framework must solve:
Currently, meta-frameworks implement their own solutions for these problems. This proposal aims to provide a unified primitive that frameworks can adopt, reducing complexity and lowering the barrier for new custom frameworks to integrate SSR with Vite.
This proposal also aims to initiate discussion around common SSR asset handling patterns, with the hope of finding more robust and future-proof solutions through community feedback.
Proposed API
?assetsQuery ImportThe plugin provides a new query import
?assetsto access assets information of the module. There are three variations of the import:The default export of the
?assetsmodule has the following type:The goal of this API is to cover the following use cases in SSR applications:
examples/islandexamples/react-routerandexamples/vue-routerfor detailed integrationsexamples/islandRuntime Helpers
The plugin provides a utility function
mergeAssetsto combine multiple assets objects into a single deduplicated assets object.Configuration
The API is enabled by adding the plugin and minimal build configuration:
TypeScript Support
TypeScript support for
?assetsimports can be enabled by adding the following to yourtsconfig.json:{ "compilerOptions": { "types": ["@hiogawa/vite-plugin-fullstack/types"] } }Examples
How It Works
For a detailed explanation of the plugin's internal architecture and implementation, see HOW_IT_WORKS.md.
Known limitations
?assets=clientdoesn't providecssduring dev.?assets=clientprovides only theentryfield during dev. It's currently assumed that CSS files needed for SSR are the CSS files imported on the server module graph.Other issues and ideas
See the issue tracker in https://github.com/hi-ogawa/vite-plugins/issues?q=is%3Aissue%20state%3Aopen%20fullstack
Request for Feedback
Feedback is greatly appreciated! I'm particularly interested in hearing from framework authors who have likely implemented their own solutions. Key questions include:
Beta Was this translation helpful? Give feedback.
All reactions