Comments (6)
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:
- Client-only is meant to be used with a dynamic import. Without the dynamic import, you are still loading the component's module on the server-side.
- Your ternary condition still renders the
props.children
without guaranteeing that it renders only on the client-side. - Your client-only factory would be the reason why it's triggering an infinite loop. It's just a pattern that you should not do.
from solid-start.
@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.
from solid-start.
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.
from solid-start.
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.
from solid-start.
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.
from solid-start.
Makes sense, thanks for your detailed answer
from solid-start.
Related Issues (20)
- [Bug?] The response ignores multi-valued headers HOT 1
- [Ecosystem CI]: Integration in the vite-ecosystem-ci HOT 1
- [Bug?]: Erroneous 404s when rapidly switching routes HOT 3
- [Feature?]: I would like to be enable to pass a router before ssr, so any microframework (backend) can be bridged HOT 2
- [Bug?]: No route matched for preloading js assets HOT 6
- [Bug?]: createResource() throws "Hydration Mismatch" errors on page load HOT 1
- How to create a SSG site? HOT 6
- [Bug?]: Middleware with returned undici response ignores the content-type if the response body is async. HOT 4
- [Bug?]: Catch-all that starts with number after ellipsis in filename causes hydration errors in nested paths on dev HOT 1
- [Bug?]: Latest Vinxi (>= 0.3.11) causes layout shifts in dev HOT 4
- [Feature?]: Error Handling with solid-router HOT 8
- [Bug?]: Vite server config is being ignored HOT 4
- [Bug?]: Namespaces are completely stripped out of code HOT 4
- [Bug?]: error while importing module, related to `.` in path-name HOT 1
- [Bug?]: createHandler context only called once, renders nonce useless HOT 1
- [Bug?]: Client Only component displayed in app.tsx causes hydration errors HOT 1
- [Bug?]: No value attribute on CSR, but present in SSR HOT 5
- [Bug?]: Typescript error in tsconfig.json for new projects created with pnpm. HOT 1
- Redirect doesn't early exit component when loading from browser address bar HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solid-start.