Open skorphil opened 7 months ago
Tried to remove fetching from root component. It is not fixing a problem. Might be it is caused by slower loading of layout
This is due to pre-rendering mechanisms. It can be avoided by disabling nextjs SSR:
const RecordForm = dynamic(
() => import("CLIENT component with chakraUI components"),
{
ssr: false,
}
);
But what are conventions?
I compared first contentful paint timings | SSR | Time |
---|---|---|
false | ~1250ms | |
true | ~350ms |
Drawbacks of prerendering: input fields will be reset after app loading is fully finished. So need some skeleton maybe. Another issue - white theme pre-rendered by default if the browser in light mode. How to switch it?
Increased speed of loading chackra theme (with ssr enabled) by adding theme script to layout.jsx at the beginning of a body https://chakra-ui.com/docs/styled-system/color-mode#adding-the-colormodescript
import { ColorModeScript } from "@chakra-ui/react";
import theme from "./ChakraTheme";
<body>
<ColorModeScript initialColorMode={theme.config.initialColorMode} />
but still there is 100-200ms blinking at the start of reloading process
https://github.com/skorphil/piggy-tracker-form/assets/6762009/23c40efb-5907-4799-982c-fc059a2e48cf
https://github.com/skorphil/piggy-tracker-form/assets/6762009/00589568-dad9-46b7-bd26-d14daeba4dea
Kinda fixed it by editing app/globals.css
, but there might be some way to immediately load correct theme avoiding altering CSS after loading is finished
Probably the problem is because server component which returns that client component is fetching data and prevent theme from loading correctly