Skip to content

React StrictMode breaks Inertia Head functionality. #2253

Open
@hailwood

Description

@hailwood

Version:

  • @inertiajs/react version: 2.0.3

Describe the problem:

When using react in <StrictMode>...</StrictMode>, the inertia <Head> component does not work correctly.

E.g. on a simple setup where we are rendering one page with a few useEffects and a single <Head title="Profile Update" /> we are doing a console.log of the passed in title parameter to the title callback of createInertiaApp.

The logs are

Image

So a few rerenders, but we ultimately end up with the title set correctly, and this is what we expect as the inertia head manager first sets it to an empty string, and the the <Head call sets it to our actual value.

However as soon as we enable <StrictMode> mode our logs look like this

Image

Resulting in us ultimately having an empty title parameter.

Steps to reproduce:

In the setup method of createInertiaApp wrap <App /> in <StrictMode> I.e.

setup({ el, App, props }) {
  const root = createRoot(el);
  root.render(
    <StrictMode>
      <App {...props} />
    </StrictMode>
  );
},

Then use the <Head title="Whatever" /> component in a layout or page.

Metadata

Metadata

Assignees

No one assigned

    Labels

    reactRelated to the react adapter

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions