Skip to content

fix(gitbook): restore useEffect import and drop the orphaned mounted effect - #3857

Open
ntdatt812 wants to merge 1 commit into
decolua:masterfrom
ntdatt812:fix/language-switcher-useeffect
Open

ntdatt812 wants to merge 1 commit into
decolua:masterfrom
ntdatt812:fix/language-switcher-useeffect

Conversation

@ntdatt812

Copy link
Copy Markdown
Contributor

The docs site has not been deploying. gitbook-pages fails on master at the prerender step:

ReferenceError: useEffect is not defined
Error occurred prerendering page "/ja/integration/claude-code"
Export encountered an error on /[lang]/[...slug]/page, exiting the build.

Why

#1362 removed the mounted state and the mounted && guard on createPortal. That call was right — modal is only built when open is true, open starts false and can only be flipped by a click, so document.body is never reached during SSR. The guard was redundant.

What it missed is that LanguageSwitcher had two effects. It deleted the state, kept the effect that fed it, and rewrote the import to match:

-import { useState, useEffect } from "react";
+import { useState, useLayoutEffect } from "react";
...
-  const [mounted, setMounted] = useState(false);
-  useEffect(() => {
+  useLayoutEffect(() => {
     setMounted(true);
   }, []);

The second useEffect — the body-scroll lock, thirty lines further down — was left untouched and lost its import.

So there are two undefined references, not one:

identifier when it bites
useEffect (line 27) at render → breaks the build
setMounted (line 23) on the client, once the import is restored

Restoring the import alone therefore trades a build failure for a runtime one. The effect has had no state to write since #1362; deleting it finishes that commit rather than reviving something nothing reads.

Verification

Real builds, same tree, gitbook/:

result
master (eb712ca) ✗ ReferenceError: useEffect is not defined, export aborts
with this change ✓ compiled in 7.0s, 103/103 static pages generated

no-undef is not enabled by eslint-config-next/core-web-vitals, which is why lint has stayed green on a file that cannot render. Turning it on for just this file:

variant no-undef
master 2 errors — setMounted, useEffect
import restored only 1 error — setMounted
this PR clean

Nothing else is touched; it is one import and five deleted lines.

…effect

The docs build has been failing at the prerender step with
"ReferenceError: useEffect is not defined", so gitbook-pages has not
deployed.

decolua#1362 removed the `mounted` state and the `mounted &&` guard on
createPortal, which was the right call: `modal` is only built when
`open` is true, `open` starts false and can only be flipped by a click,
so document.body is never touched during SSR. But it left behind the
effect that fed that state and switched the react import from useEffect
to useLayoutEffect to match it -- while a second useEffect, the one that
locks body scroll, was still in the file and lost its import.

That leaves two undefined references: useEffect at render, which is what
breaks the build, and setMounted inside the surviving effect, which
would throw on the client once the import is restored. Deleting the
effect finishes what decolua#1362 started rather than reviving state nothing
reads.

no-undef is not enabled in the repo's eslint config, so lint stays green
on the broken file. Enabling it just for this file reports 2 errors on
master, 1 if only the import is restored, and 0 here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant