I have a new Rails project using esbuild with React. The setup is pretty standard:
<div
id="user_edit_page"
data-controller="user-edit-page"
>
</div>
And then a:
import { Controller } from "@hotwired/stimulus"
import React from "react";
import { createRoot } from "react-dom/client";
import UserEditPage from "../components/UserEditPage";
// Connects to data-controller="user-edit-page"
export default class extends Controller {
connect() {
const app = document.getElementById("user_edit_page");
createRoot(app).render(<UserEditPage />)
}
}
When I navigate between pages there is a really annoying flicker. It feels that Rails is serving a cached response, then re-initializes the React component, which then re-renders.
I'm assuming I can disable turbolinks and have this go away, but I was wondering if there's a nice Rails way to have things working as intended.