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?]: bun create solid error on windows 11 HOT 1
- [Bug?]: Server functions that throw or return redirects when called in an action do not redirect HOT 10
- [Bug?]: Vite field in the app config has wrong types HOT 1
- [Bug?]: server function that contain await prisma function will throws error HOT 3
- [Bug?]: dup signIn import from @solid-mediaket/auth -> build error HOT 5
- [Bug?]: `Button type attribute has not been set.` in templates
- [Bug?]: createResource fails if using SSR and an exception is thrown in the wrapped function HOT 3
- [ssr]: Spreading `readOnly: false` on input applies `readonly` HOT 2
- [Bug?]: Middleware returning Response is not working properly
- [Bug?]: SolidStart aws_lambda preset unable to serve JS and CSS artifacts when deployed to AWS Lambda HOT 1
- [Bug?]: Client bundle including imports from "use server" functions HOT 2
- [Bug?]: 404 page doesn't work in cloudflare pages HOT 3
- [Feature?]: Allow `init` of projects with both `vitest` and `tailwindcss` HOT 1
- [Bug?]: Deno downloading error - npm package 'uWebSockets.js' does not exist
- [Bug]: `bun create solid@latest` doesn't work HOT 1
- [Bug?]: Session "spreads" the userId string into session.data HOT 3
- [Bug?]: `📜 Docs / 📜 Deploy Docs (push) Failing after 38s`
- have one source of truth for docs checks
- [Bug?]: throwing redirect in route load function is not handled
- [Bug?]: Broken starter
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.