Skip to content

Server and client pages in the same app #33

Closed Pinned Answered by derrickreimer
andresgutgon asked this question in Q&A
Discussion options

You must be logged in to vote

Great question @andresgutgon! The way I handle selectively applying SSR in my apps is to assign an ssr page prop (in addition to the ssr: true option passed to render_inertia), so that my createInertiaApp setup function can key off of that when applicable.

conn
|> assign_prop(:ssr, true)
|> render_inertia("MyPage", ssr: true)
createInertiaApp({
  resolve: async (name) => {
    return await import(`./pages/${name}.jsx`);
  },
  setup({ App, el, props }) {
    if (props.initialPage.props.ssr) {
      hydrateRoot(el, <App {...props} />);
    } else {
      createRoot(el).render(<App {...props} />);
    }
  },
});

Your ssr.jsx (or ssr.tsx) file can stay the same.

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@andresgutgon
Comment options

@derrickreimer
Comment options

@andresgutgon
Comment options

@andresgutgon
Comment options

Answer selected by derrickreimer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #32 on February 23, 2025 21:39.