-
Notifications
You must be signed in to change notification settings - Fork 515
Description
@inertiajs/react Version
1.3.0
Backend stack (optional)
No response
Describe the problem
Hello,
I've encountered a critical SSR crash that seems to be a bug within createInertiaApp. After extensive debugging, we've isolated the issue to the createInertiaApp function call itself.
Environment:
@inertiajs/react: 1.3.0
react: 18.2.0
react-dom: 18.2.0
laravel-vite-plugin: 1.0.0
vite: 5.2.0
node: v20.19.3
Problem: The node process for the SSR server crashes immediately after the setup function within createInertiaApp completes. The crash is uncatchable with a try...catch block.
Key Findings:
A direct render using ReactDOMServer.renderToString on a simple component works perfectly.
Bypassing createInertiaApp and rendering a component directly inside the createServer callback also works without crashing the server.
The crash occurs even when passing a manually constructed, minimal page object to createInertiaApp, ruling out any issues with the data from Laravel.
Minimal ssr.jsx to Reproduce the Crash:
javascript
import ReactDOMServer from 'react-dom/server';
import { createInertiaApp } from '@inertiajs/react';
import createServer from '@inertiajs/react/server';
import { jsx } from 'react/jsx-runtime';
function HomeSimple() {
return jsx('div', { children: 'Hello World' });
}
createServer(async (page) => {
console.log([SSR] Received request for component: ${page.component}
);
try {
const minimalPage = {
component: page.component,
props: { errors: page.props.errors || {} },
url: page.url,
version: page.version,
};
console.log('[SSR] Attempting to render with createInertiaApp...');
return await createInertiaApp({
page: minimalPage,
render: ReactDOMServer.renderToString,
resolve: () => HomeSimple,
setup: ({ App, props }) => {
console.log('[SSR] Setup complete.');
return jsx(App, { ...props });
},
});
} catch (error) {
console.error('[SSR CRITICAL ERROR]:', error);
throw error;
}
});
This seems to be a low-level incompatibility within the Inertia SSR helper. Disabling SSR is the only current workaround.
Thank you for your work on this great library.
Steps to reproduce
import ReactDOMServer from 'react-dom/server';
import { createInertiaApp } from '@inertiajs/react';
import createServer from '@inertiajs/react/server';
import { jsx } from 'react/jsx-runtime';
function HomeSimple() {
return jsx('div', { children: 'Hello World' });
}
createServer(async (page) => {
console.log([SSR] Received request for component: ${page.component}
);
try {
const minimalPage = {
component: page.component,
props: { errors: page.props.errors || {} },
url: page.url,
version: page.version,
};
console.log('[SSR] Attempting to render with createInertiaApp...');
return await createInertiaApp({
page: minimalPage,
render: ReactDOMServer.renderToString,
resolve: () => HomeSimple,
setup: ({ App, props }) => {
console.log('[SSR] Setup complete.');
return jsx(App, { ...props });
},
});
} catch (error) {
console.error('[SSR CRITICAL ERROR]:', error);
throw error;
}
});