Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SolidStart client side only rendering

Is there any way to render a component on the client side only in Solid Start.

Just like in next js we can use dynamic to get ssr false. Is there any alternative for that in SolidJS?

I tried to import module in createEffect.

like image 357
Jay Pokale Avatar asked Apr 12 '26 08:04

Jay Pokale


2 Answers

There is an experimental API unstable_clientOnly exported from solid-start:

On the server it will render null or will render the fallback if you pass it any. This can help avoid layout shifts.

https://github.com/solidjs/solid-start/issues/320

It uses isServer from solid-js/web internally:

This indicates that the code is being run as the server or browser bundle. As the underlying runtimes export this as a constant boolean it allows bundlers to eliminate the code and their used imports from the respective bundles.

https://www.solidjs.com/docs/latest/api#isserver

like image 50
snnsnn Avatar answered Apr 20 '26 11:04

snnsnn


Just found clientOnly https://docs.solidjs.com/solid-start/reference/client/client-only

Wrapping components in clientOnly will cause them render only in the client. This can useful for components that interact directly with the DOM, such as jQuery, since they can not render on the server. It works similar to lazy but will only render after hydration and will never load on the server.

It's preferred than lazy because lazy still causes the server to import it

like image 45
Jakku Sakura Avatar answered Apr 20 '26 11:04

Jakku Sakura



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!