"use server" and "use client" directives #10953
Replies: 1 comment
-
It would be awesome to get 'use client' and 'use server' for components aswell just like in NextJs with server components. I have had alot of situations where I want a component rendered client side only and I had a really hard time implementing it myself with the current way SvelteKit works. I know I can use like if(browser) ... and onMount etc but this is not ideal as Sveltekit will still attempt to render it on the server and also during prerendering. Also having components that run both on the server AND the client can be a bit unnecessary. In NextJs all components are static and server only unless you provide any client side logic like onClick or useState or provide a marker like 'use client'. SvelteKit would be soo much more effective having this feature aswell especially with Svelte 5 coming up. |
Beta Was this translation helpful? Give feedback.
-
can we add diretives on js/ts files like "use server" or "use client" or both to prevent them being imported on client/server. I know there's .server.js approach or putting files inside
server
directory, but i think using such directive on the top of the file would be better on some cases. like: i don't want to make function1.server.js, function2.server.js ( adding .server on every file ) , and also i can import function3.js (say it contains client side logic) to server code for now, so adding such directive might make it easier.Beta Was this translation helpful? Give feedback.
All reactions