Mostly, you're using StrictMode in your React part. Which invoking the component twice to detect side effects.
Jul 3, 2024
7
Level 1
Render pages 2 times
Help me understand what I'm missing. Laravel, Inetria, React
app.jsx
import './bootstrap';
import '../scss/app.scss';
import { create Inertia App } from '@inertiajs/react'
import { hydrate Root } from 'react-dom/client'
create Inertia App({
resolve: name => {
const pages = import.meta.glob('./Pages/**/*.jsx', { eager: true })
return pages[`./Pages/${name}.jsx`]
},
setup({ el, App, props }) {
hydrate Root(el, <App {...props} />)
},
})
ssr.jsx
import ReactDOMServer from 'react-dom/server';
import { createInertiaApp } from '@inertiajs/react';
import createServer from '@inertiajs/react/server';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { route } from 'ziggy-js';
createServer((page) =>
createInertiaApp({
page,
render: ReactDOMServer.renderToString,
resolve: (name) => resolvePageComponent(`./Pages/${name}.jsx`, import.meta.glob('./Pages/**/*.jsx')),
setup: ({ App, props }) => {
global.route = (name, params, absolute) =>
route(name, params, absolute, {
...page.props.ziggy,
location: new URL(page.props.ziggy.url),
});
return <App {...props} />;
},
})
);
Pages/Index.jsx
import { Head } from '@inertiajs/react';
export default function StartApp() {
console.log('StartApp') // <------ O_o
return (
<>
<Head title="Welcome" />
<b>TEST WORK</b>
</>
);
}
When I go to the page in the console, I get console.log output 2 times Is it related to SSR or am I loading pages incorrectly?
Thank you.
Please or to participate in this conversation.