-
Notifications
You must be signed in to change notification settings - Fork 40
Throws exception when navigating to a page via browser address bar #51
Comments
Are you using SSR? Errors on the server side are often harder to track down, because the console output is worse than in the browser. You could try to turn it off and check if you get an error in the browser console on page load. |
I am. I'll try disabling it and see if that resolves it. |
Yep that seems to resolve the issue. No errors at all in the console when running without SSR. What would be my next step in debugging why I'm not getting a response body with SSR turned on? |
Wow, so check this out. I opened And under the try {
$response = $this->httpClient->request(
'POST',
$this->interia->getSsrUrl(),
[
'headers' => [
'Content-Type: application/json',
'Accept: application/json',
],
'body' => json_encode($page),
]
);
// to see the array of the response
dd($response->toArray());
} catch (Exception $e) {
return null;
} And with this dump in place... all the pages load and render correctly. What the heck??? Could this be something to do with using the Inertia > 1.0 version? No need to actually return a |
@secondmanveran Does your node server output any errors? Inertia v1 shouldn't be the problem, because I'm using it as well. You should also see the dump output if you put the dd() at this location, except if you turned off SSR. You could also try to use ts-node-dev in development, if you don't already use it, and see if it gives you more output.
The problem could also be in your ssr entrypoint, if you can't reproduce the problem without SSR. Here is my version without all the extra vue plugins createServer((page) =>
createInertiaApp({
page,
render: renderToString,
resolve: (name) => {
const pageInternal = require(`@/pages/${name}`).default;
pageInternal.layout = pageInternal.layout || DefaultLayout;
return pageInternal;
},
setup({ el, app, props, plugin }) {
const vueApp = createSSRApp({ render: () => h(app, props) })
.use(plugin);
return vueApp;
},
})
); |
@secondmanveran Are you using Vite? I never used it and symfony and would wish that the symfony team would officially support it. Styles are also my biggest pain point with SSR, because I can't get the SSR server to output the css chunks from single file components. And it also tries to load it's own generated main.css file, instead of of a shared one with the client code. A workaround to at least load the css entrypoint in SSR are these few lines in the SSR webpack encore config. Encore.setOutputPath("public/build-ssr/")
.setPublicPath(process.env.DEV_ENV === "DEV_SERVER" ? "https://localhost:9038/build" : "/build")
.setManifestKeyPrefix("build/") This will generate asset links with /build instead of /build-ssr. The environment variable check helps with the encore dev server. Port 9038 is the port in my project, encore usually uses 9000. I start my ssr watcher with this script in the package json, to prepend the env var: {
"scripts": {
"watch:ssr": "encore dev --watch -c ./webpack.ssr.config.js",
"dev-server:ssr": "DEV_ENV=DEV_SERVER encore dev --watch -c ./webpack.ssr.config.js",
"build:ssr": "NODE_ENV=production encore production --progress -c ./webpack.ssr.config.js"
}
} The result is ok, but not great, because it only helps a little. I need the ssr part for SEO reasons in production for my main project and hide most of the ui, until the client rendered the ui with additional css chunks loaded through the webpack runtime. It does work well with tailwind though in another project of mine, because I only have a single css file anyway. |
Yes I tried to use Encore just so I could keep in line with the current "Symfony way" and it wouldn't compile Inertia > 1, so I went back to Vite, which is what I normally use. I can't stand webpack, it's just so bloated and time consuming. ES modules are the way. I don't ever use SFC css normally so let me try getting rid of this default Symfony start page and we'll see where we are then. |
Yeah I give up. I'll just stick with Laravel. |
When using the
Link
component pages navigate correctly but when you input a page via the address bar I get the following exception:It looks like it's dying at:
Any ideas what's up, or any additional info you need?
The text was updated successfully, but these errors were encountered: