Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved Hydration Issue #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export default function RootLayout({
}) {
return (
<html lang="en">
<GoogleAnalytics gaId="G-X3SVRNR6WN" />
<head>
<GoogleAnalytics gaId="G-X3SVRNR6WN" />
<IconLink />
</head>
<body className={GeistSans.className}>
Expand Down
9 changes: 7 additions & 2 deletions app/providers.tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave an explanation about how this solves the issue? I suggest we avoid delayed rendering of the providers and their children, this can affect the server side build of the project and may cause performance issues.

Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
"use client";
import { ChakraProvider } from "@chakra-ui/react";
import { theme } from "./styles/theme";
import { useEffect } from "react";
import { useEffect,useState } from "react";

export function Providers({ children }: { children: React.ReactNode }) {
// useEffect(() => {
// if (window.innerWidth < 768 && !window.location.href.includes("/mobile")) {
// window.location.href = "/mobile";
// }
// }, []);
const [isHydrated, setIsHydrated] = useState(false);

useEffect(() => {
setIsHydrated(true);
}, []);

return <ChakraProvider theme={theme}>{children}</ChakraProvider>;
return isHydrated?<ChakraProvider theme={theme}>{children}</ChakraProvider>:null;
}
9 changes: 6 additions & 3 deletions lib/server-functions.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes relevant to the issue? if yes please leave an explanation about what you did.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import typescript from "typescript";
import { contentManager } from "./contentManager";

import { CodeFileExports, Metadata } from "./types";
import path from "path";

export function parseLessonFolder(fullFilePath: string, codePath: string) {
const file = fs.readFileSync(fullFilePath, "utf-8");
const absolutePath=path.join(process.cwd(),fullFilePath)
const file = fs.readFileSync(absolutePath, "utf-8");

const { content, data } = matter(file);
const Page = () => CustomMDX({ source: content });
Expand All @@ -25,10 +27,11 @@ function transpileTypeScriptToJavaScript(tsCode: string) {
}

export function getCodeFileExports(fullFilePath: string) {
const fileContent = fs.readFileSync(fullFilePath, "utf-8");
const absolutePath=path.join(process.cwd(),fullFilePath)
const file = fs.readFileSync(absolutePath, "utf-8");
const dynmicFunction = new Function(
"module",
transpileTypeScriptToJavaScript(fileContent),
transpileTypeScriptToJavaScript(file),
);
const moduleExports: {} | CodeFileExports = {};
dynmicFunction(moduleExports);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"type": "module",
"scripts": {
"next-dev": "next dev",
"next-dev": "next dev --turbo",
"content-watch": "nodemon --ext ts,mdx --watch ./content --ignore ./content/outline.json --exec \"tsx ./scripts/generateOutline.ts\"",
"dev": "concurrently \"pnpm run next-dev\" \"pnpm run content-watch\"",
"build": "tsx ./scripts/generateOutline.ts && next build",
Expand Down