Repository navigation
perf: weekly react best practices audit fixes #3518
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
Changes from all commits
cb18139
479877d
2a71d2c
2373c5a
43fc8ed
d2b9d9b
b9d9d05
2f1fa3b
4070a1b
6f1adaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| "use client"; | ||
| import { buttonVariants } from "fumadocs-ui/components/ui/button"; | ||
| import { MessageCircleIcon } from "lucide-react"; | ||
| import dynamic from "next/dynamic"; | ||
| import { useCallback, useEffect, useEffectEvent, useState } from "react"; | ||
|
|
||
| import { cn } from "@/lib/cn"; | ||
|
|
||
| // The panel module pulls in @ai-sdk/react, its transport and the remark/shiki | ||
| // markdown pipeline. Loading it on demand keeps all of that out of the initial | ||
| // bundle of every docs page; the trigger below stays server-rendered so the | ||
| // button never pops in after hydration. | ||
| const AISearchPanel = dynamic(() => import("./search"), { | ||
| loading: () => null, | ||
| }); | ||
|
Comment on lines
+13
to
+15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Remove the disallowed dynamic import. Line 13 invokes Proposed policy-compliant change-import dynamic from "next/dynamic";
+import AISearchPanel from "./search";
...
-const AISearchPanel = dynamic(() => import("./search"), {
- loading: () => null,
-});🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| export function AskAI() { | ||
| const [open, setOpen] = useState(false); | ||
| // Once opened, the panel stays mounted so the conversation survives closing | ||
| // and reopening — the chat state lives inside the lazily loaded module. | ||
| const [hasOpened, setHasOpened] = useState(false); | ||
|
|
||
| const toggle = useCallback((next: boolean) => { | ||
| if (next) { | ||
| setHasOpened(true); | ||
| } | ||
| setOpen(next); | ||
| }, []); | ||
|
|
||
| const onKeyPress = useEffectEvent((e: KeyboardEvent) => { | ||
| if (e.key === "Escape" && open) { | ||
| toggle(false); | ||
| e.preventDefault(); | ||
| } | ||
|
|
||
| if (e.key === "/" && (e.metaKey || e.ctrlKey) && !open) { | ||
| toggle(true); | ||
| e.preventDefault(); | ||
| } | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| window.addEventListener("keydown", onKeyPress); | ||
| return () => window.removeEventListener("keydown", onKeyPress); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <> | ||
| {hasOpened && <AISearchPanel open={open} setOpen={toggle} />} | ||
| <button | ||
| type="button" | ||
| data-state={open ? "open" : "closed"} | ||
| className={cn( | ||
| buttonVariants({ | ||
| color: "secondary", | ||
| className: "text-fd-muted-foreground rounded-2xl", | ||
| }), | ||
| "fixed bottom-4 gap-3 w-24 inset-e-[calc(--spacing(4)+var(--removed-body-scroll-bar-size,0px))] shadow-lg z-20 transition-[translate,opacity]", | ||
| open && "translate-y-10 opacity-0", | ||
| )} | ||
| onClick={() => toggle(!open)} | ||
| > | ||
| <MessageCircleIcon className="size-4.5" /> | ||
| Ask AI | ||
| </button> | ||
| </> | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Resolve the shared dynamic-import policy violation.
Both changed files use dynamic imports despite the repository rule that forbids them.
apps/code/src/components/profile/ProfileView.tsx#L30-L38: restore the top-levelProfileTokensChartimport, or approve a documented exception.apps/code/src/lib/utils/markdown.tsx#L1-L7: restore the top-levelSyntaxHighlightedPreimport, or approve a documented exception.Verify the changed files with:
As per coding guidelines: use top-level
importstatements and never use dynamic imports.📍 Affects 2 files
apps/code/src/components/profile/ProfileView.tsx#L30-L38(this comment)apps/code/src/lib/utils/markdown.tsx#L1-L7🤖 Prompt for AI Agents