vikejs / vike-react

🔨 React integration for Vike
https://vike.dev/vike-react
MIT License
94 stars 15 forks source link

StrictMode Config #109

Closed enri90 closed 3 months ago

enri90 commented 4 months ago

Do you think it makes sense for you to implement react StrictMode in the config? It would help me avoid situations

https://nextjs.org/docs/pages/api-reference/next-config-js/reactStrictMode

export default {
  Head,
  ssr: false,
  reactStrictMode: false,
  extends: [vikeReact, vikeReactQuery],
  passToClient: ['routeParams'],
} satisfies Config;

or

function Wrapper({ children }: { children: React.ReactNode }) {
  return (
    <React.StrictMode>
      {children}
    </React.StrictMode>
  )
}

or

export default defineConfig(async () => ({
  plugins: [
    react(),
    vike({ prerender: true ,reactStrictMode: false }),

Thx

brillout commented 4 months ago

Yes, vike-react should probably add the scrict wrapper and enable it by default. In the meantime an easy workaround is to use <Wrapper>.

Nickhoyer commented 3 months ago

Right now React.StrictMode is added by default in onRenderHtml.tsx. React.StrictMode runs useEffects twice even with an empty array, which can cause bugs for some users. Just want to give my vote that this gets fixed, I think it's fine that it's on by default, but should definitely be toggleable

brillout commented 3 months ago

I agree, I’ll release that later today/tomorrow.

brillout commented 3 months ago

Released in 0.4.9.