Closed BierDav closed 7 months ago
There's some bad patterns here, but mainly I'd just recommend using this component:
import { createSignal, onMount, Show } from 'solid-js';
function ClientOnly(props) {
const [flag, setFlag] = createSignal(false);
onMount(() => setFlag(true));
return <Show when={flag()}>{props.children}</Show>;
}
(or just install solid-use
and use solid-use/client-only
)
But to explain why your usage is wrong:
props.children
without guaranteeing that it renders only on the client-side.@lxsmnsyc Thanks for your help makes sense, maybe we should add something like a ClientOnlyBoundary in future, to make this clear. Unfortunately the current solid start documenation is quite bad when it comes to advanced requirements.
The reason clientOnly
was implemented first was because of the fact that there are libraries that provides a client-only side-effect, which triggers errors when imported on the server. clientOnly
forces the user to import these dynamically to prevent the modules from being loaded immediately.
Ok, I see, but that doesn't mean, that a ClientOnlyBoundary
component wouldn't be useful. I think that such small util functions that directly work together with the solid start engine
(I would call it) should be provided by solid-start
for convenience. And this would be a nice addition.
Understanding this issue, I think this is no action. As @lxsmnsyc responded clientOnly is for dynamic imports. ClientBoundary is interesting but it is also another thing. When it is an official component we have to explain when to use one over the other. It's one of those cases where while it could be made into another component, it could be done more specifically for the situation in a number of ways and it is minimal code. I see solid-use has a prebuilt of it so it is readily available. Which makes me more inclined to defer any action on this until it is clear where the responsibility for this should lie.
Makes sense, thanks for your detailed answer
Duplicates
Latest version
Current behavior 😯
Recently I updated from an old solidjs version to the latest also the new router. And noticed that the
clientOnly
method which was experimental back than doesn't work when wrappingprops.children
. This is my code:Helper:
Usage:
With the old
<Outlet/>
router, everything worked fine, but unfortunatey this implementation causes an endless loop on the browser after hydration which makes it unusable.Expected behavior 🤔
A way to make
props.children
client only that doesn't cause and endless loop in the browser which completely freezes the tab.Steps to reproduce 🕹
Steps:
You may experience it yourself in this neight little sample project. But don't be supprised that your tab freezes and you might have to force close it. I warned you 😉 https://stackblitz.com/~/github.com/BierDav/solid-start-ssr-bug
Context 🔦
I need the client only, because when the token that is stored in the request cookie is expired only the client can refresh it, and it wouldn't make sense to wait for all the unauthorized responses I would get when evaluating the ssr.
Your environment 🌎