SSR for React; adapter differences between React + Vue
See original GitHub issueDiscussed in https://github.com/inertiajs/inertia/discussions/1081
<div type='discussions-op-text'>Originally posted by ZeoKnight February 4, 2022 Having read @aarondfrancis comments here https://github.com/tighten/ziggy/issues/431 and useful blog post https://aaronfrancis.com/2022/using-ziggy-with-inertia-server-side-rendering for dealing with global scope window issues.
How do we approach this in React? the features available within the vue adaptor simply aren’t present in the react adaptor?
#Vue adaptor
import {createInertiaApp} from '@inertiajs/inertia-vue3'
createServer((page) => createInertiaApp({
page,
render: renderToString,
resolve: name => require(`./Pages/${name}`),
setup({app, props, plugin}) {
const Ziggy = {
// Pull the Ziggy config off of the props.
...props.initialPage.props.ziggy,
// Build the location, since there is
// no window.location in Node.
location: new URL(props.initialPage.props.ziggy.url)
}
return createSSRApp({
render: () => h(app, props),
}).use(plugin).mixin({
methods: {
route: (name, params, absolute, config = Ziggy) => route(name, params, absolute, config),
},
})
},
}))
#React Adaptor
import {createInertiaApp} from '@inertiajs/inertia-react'
createServer((page) => createInertiaApp({
page,
render: ReactDOMServer.renderToString,
resolve: name => require(`./Pages/${name}`),
setup: ({ App, props }) => <App {...props} />,
}))
Note the setup method does not have plugins
or uses a helper method createSSRApp
- react setup simply returns the component + props.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:11
Top Results From Across the Web
adapter differences between React + Vue · Discussion #1081 ...
How do we approach this in React? the features available within the vue adaptor simply aren't present in the react adaptor?
Read more >I created the exact same app in React and Vue. Here are the ...
The only difference here is that the React app has three CSS files, whereas the Vue app doesn't have any. The reason for...
Read more >Fundamental Differences Between React and Vue - Medium
Take a look at the following code snippets: Both of them are Hello components, the first is in React and the other is...
Read more >SSR Frameworks: Next.js vs SvelteKit vs Nuxt vs Quasar vs ...
1. Introduction 2. React SSR frameworks 3. Vue.js SSR frameworks
Read more >Server Rendering in JavaScript: Why SSR?
By default you can have Svelte/Vue/React front-ends together with Laravel/Ruby backends. Then other community-based adapters also exist for ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To offer another solution: I followed parts of @aarondfrancis his blog post but swapped out the end for this:
You see, ziggy by default already tries to find a ziggy instance in
globalThis
(see https://github.com/tighten/ziggy/blob/b3ebdd831a9da9dd9839c611f7aff7d82d1bf159/src/js/Router.js#L17). This allows me to use the regular route function from ziggy without having to write a wrapper. Hope it helps someone!@ZeoKnight @aarondfrancis I am not sure if this is the right approach but this worked for me.