-
Notifications
You must be signed in to change notification settings - Fork 371
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
Suggest an official way to use libraries *only* on the client #796
Comments
So Example: |
There is a here is a example that i used to get the monaco editor working https://stackblitz.com/edit/solid-ssr-vite-bkw6w8?file=package.json,src%2Froutes%2Findex.tsx%3AL10 |
I tried it now: const AgGridSolid = lazy(() => {
if (isServer) {
throw "THIS SHOULD NEVER RUN ON THE SERVER";
} else {
return import("ag-grid-solid");
}
}); The server bundle build still fails with the same error:
Am I using it in a way that is incompatible with tree-shaking? 🤔 Or does it just not work? |
Tried that now: const AgGridSolid = unstable_clientOnly(() => {
return import("ag-grid-solid");
}); Server build still fails with the exact same error, unfortunately 🤔 But as you linked a tracking issue, I assume it's not supposed to work yet.
|
The dynamic import may be messing with the tree-shaking. Rollup has open issues regarding this problem. The workaround is to create a façade module. |
@Hubro i forgot to add im my previous comment you also need to add ag-grid-solid to your ssr external ssr: {
external: ['ag-grid-solid'],
}, if that doesn't work instead of importing if that still doesn't work please create a example on stackblitz or other sites.
It is working as im using it myself atm for monaco the tracking is to ensure that it works on all adapters. |
That works! That's awesome 🙂 If I don't use a facade module, the entirety of ag-grid is added to my
I know I can just ignore this, but I don't like getting in the habit of ignoring warnings. Is there any way to get rid of this warning? AgGridSolid.tsx: import AgGridSolid from "ag-grid-solid";
export default AgGridSolid; |
the best way to do this would be to turn that facade module into a component and use it there. |
@Hubro You're going to want to do this anyway.
So it's a way to use client-only components rather than a way to control client side imports (which would leave you with additional work). |
There's two ways right now to solve this but the safest way would be to use |
Yeah this is an area still under design because of things like this. Ideal the dependency graph could be isolated this way. |
This is fixed in the new Solid Beta. In setting up for SolidStarts next Beta Phase built on Nitro and Vinxi we are closing all PRs/Issues that will not be merged due to the system changing. If you feel your issue was closed by mistake. Feel free to re-open it after updating/testing against 0.4.x release. Thank you for your patience. See #1139 for more details. |
Some libraries are designed and compiled to run in the browser and can't work with SSR.
Most of the time (I think) it's sufficient to simply disable that library on the server and just render a spinner instead. Sure, you won't get the benefits of SSR for that specific library, but the rest of your application still gets to reap the benefits of smooth routing, data loading and sweet, sweet streaming rendering.
I'm struggling with this issue with ag-grid. I want to use solid-start for the seamless data loading and streaming rendering. However, on one specific subpage, I want to use ag-grid to display some data. It's more than adequate for me to have this page display a loading spinner until the data and the ag-grid library is loaded.
However, I can't figure out how to completely divorce the ag-grid library from the server side. When I build my project, the server side bundle crashes during build because of ag-grid, even though I lazy load the library.
I'm guessing this is a common enough use case that there should be an official, recommended procedure for including client-only libraries that are not included in the server bundle.
This would be great as a subpage of the docs, perhaps titled "Client-only libraries" or "Disable SSR for specific libraries".
The text was updated successfully, but these errors were encountered: