vuejs / repl

Vue SFC REPL as a Vue 3 component
https://repl-vuejs.vercel.app
MIT License
930 stars 172 forks source link

feat(preview): allow inject customCode in SSR render and provide context constant SSR_CLIENT for conditional execution of custom code #180

Closed pdanpdan closed 8 months ago

pdanpdan commented 11 months ago

Allow code to be imported and used in the SSR render (now it can only be added on client side). In order to provide context about execution mode we provide SSR_CLIENT context constant:

SSR_CLIENT: true only if the code is executed client side on client takeover

SSR_CLIENT: false => SPA mode(pure client) SSR_CLIENT: true => SSR mode on client side

vercel[bot] commented 11 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
repl ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2024 10:21am
yyx990803 commented 10 months ago

This would break previous customCode usage that assumes it runs on client only. Maybe it's better to add a separate option for SSR custom code?

pdanpdan commented 10 months ago

Sure, no problem - customCodeSSR.{importCode, useCode} is ok? If I change the option name to have specific entries for SSR I would drop the SERVER context constant

from:

SSR_SERVER: true only if the code is executed in SSR mode on server
SSR_CLIENT: true only if the code is executed client side on client takeover

SSR_SERVER: false + SSR_CLIENT: false => SPA mode (pure client)
SSR_SERVER: true => SSR mode on server side
SSR_CLIENT: true => SSR mode on client side

to

SSR_CLIENT: true only if the code is executed client side on client takeover

SSR_CLIENT: false => SPA mode (pure client)
SSR_CLIENT: true => SSR mode on client side