Skip to content

Commit

Permalink
check for import.meta.env.SSR instead of import.meta.env.DEV to know… (
Browse files Browse the repository at this point in the history
…#409)

* check for !import.meta.env.SSR instead of import.meta.env.DEV to know if CSR should hydrateRoot or createRoot

* inverse the check

* add return statement

* Fix React TS error
  • Loading branch information
YassineBenh authored Sep 11, 2024
1 parent 666ea22 commit 2bdef9f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Console/InstallsInertiaStacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@ protected function configureReactHydrateRootForSsr($path)
root.render(<App {...props} />);
EOT,
<<<'EOT'
if (import.meta.env.DEV) {
createRoot(el).render(<App {...props} />);
return
if (import.meta.env.SSR) {
hydrateRoot(el, <App {...props} />);
return;
}
hydrateRoot(el, <App {...props} />);
createRoot(el).render(<App {...props} />);
EOT,
$path
);
Expand Down
1 change: 1 addition & 0 deletions stubs/inertia-react-ts/resources/js/ssr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ createServer((page) =>
title: (title) => `${title} - ${appName}`,
resolve: (name) => resolvePageComponent(`./Pages/${name}.tsx`, import.meta.glob('./Pages/**/*.tsx')),
setup: ({ App, props }) => {
// @ts-expect-error
global.route<RouteName> = (name, params, absolute) =>
route(name, params as any, absolute, {
// @ts-expect-error
Expand Down

0 comments on commit 2bdef9f

Please sign in to comment.