Repository navigation
Feat: Rewrite wiki template with reui - #16797
Conversation
📝 WalkthroughWalkthroughThe PR adds reusable stepper components and integrates them into compilation-template creation. It also makes npm hook installation resilient, changes form validation timing, removes one translation entry, and updates Python proxy targets. ChangesCompilation template stepper
Web tooling and runtime configuration
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant TemplateStepper
participant CreateNextCompilationTemplate
participant StepContent
User->>TemplateStepper: select an available step
TemplateStepper->>CreateNextCompilationTemplate: call onStepChange
CreateNextCompilationTemplate->>CreateNextCompilationTemplate: accept earlier step
CreateNextCompilationTemplate->>TemplateStepper: update activeStep
TemplateStepper->>StepContent: render active content
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
web/scripts/prepare.js (1)
27-30: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider
execFileSyncwith an argument array instead of string-basedexecSync.Static analysis flags this as a dynamic command passed to
execSync. WhilelefthookBinis derived deterministically from__dirname(not user-controlled), usingexecFileSync/spawnSyncwith an argument array is the recommended Node.js pattern and would satisfy the linter warnings. Note: on Windows you'd needshell: true(orspawnSyncwithshell: isWindows) to correctly invoke.cmdfiles.♻️ Optional refactor
import { execSync } from 'node:child_process'; +import { execFileSync } from 'node:child_process';- execSync(`"${lefthookBin}" install`, { - cwd: repoRoot, - stdio: 'inherit', - }); + execFileSync(lefthookBin, ['install'], { + cwd: repoRoot, + stdio: 'inherit', + shell: isWindows, + });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@web/scripts/prepare.js` around lines 27 - 30, Replace string-based execSync in the lefthook installation logic with execFileSync or spawnSync, passing lefthookBin and arguments separately; configure Windows execution with shell: true or an equivalent isWindows-based option so .cmd files continue to work.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/src/components/reui/stepper.tsx`:
- Around line 93-103: Trigger nodes are not removed when StepperTrigger
components unmount, and registerTrigger cannot remove a node when passed null.
Add an unregisterTrigger function to the Stepper context interface and
implementation that removes a specific HTMLButtonElement, expose it through
contextValue and dependencies, destructure it in StepperTrigger, and update the
registration effect to capture btnRef.current and return cleanup that
unregisters the captured node.
- Around line 148-155: Add indicators to the dependency array of the useMemo
containing the stepper context value, alongside currentStep and the other
dependencies, so changing indicators props updates StepperIndicator content.
---
Nitpick comments:
In `@web/scripts/prepare.js`:
- Around line 27-30: Replace string-based execSync in the lefthook installation
logic with execFileSync or spawnSync, passing lefthookBin and arguments
separately; configure Windows execution with shell: true or an equivalent
isWindows-based option so .cmd files continue to work.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ec952bc3-9303-456b-b5e1-a35f7787dd19
📒 Files selected for processing (8)
web/package.jsonweb/scripts/prepare.jsweb/src/components/reui/stepper.tsxweb/src/locales/en.tsweb/src/pages/user-setting/compilation-templates/create-next/components/template-stepper.tsxweb/src/pages/user-setting/compilation-templates/create-next/index.tsxweb/src/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-form.tsweb/vite.config.ts
💤 Files with no reviewable changes (1)
- web/src/locales/en.ts
| const registerTrigger = useCallback((node: HTMLButtonElement | null) => { | ||
| setTriggerNodes((prev) => { | ||
| if (node && !prev.includes(node)) { | ||
| return [...prev, node]; | ||
| } else if (!node && prev.includes(node!)) { | ||
| return prev.filter((n) => n !== node); | ||
| } else { | ||
| return prev; | ||
| } | ||
| }); | ||
| }, []); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win
Trigger nodes are never cleaned up on unmount — keyboard navigation breaks when steps are conditionally removed.
StepperTrigger registers its DOM node via useEffect (line 251-255) but has no cleanup function. When a step is unmounted (e.g., the blueprints step disappears because isArtifacts flips to false), the stale button element remains in triggerNodes. This causes focusNext/focusPrev to attempt focusing detached DOM nodes and corrupts myIdx calculations.
Additionally, registerTrigger's removal path (line 97) is broken: when node is null, it checks prev.includes(null) which is always false for an array of HTMLButtonElement objects, so the filter branch never executes.
The fix requires both adding an unregisterTrigger function and calling it in the effect cleanup. The node must be captured in the effect closure because React nulls btnRef.current before cleanup runs.
🔧 Proposed fix: add unregisterTrigger and effect cleanup
Add unregisterTrigger to the context interface:
interface StepperContextValue {
activeStep: number;
setActiveStep: (step: number) => void;
stepsCount: number;
orientation: StepperOrientation;
registerTrigger: (node: HTMLButtonElement | null) => void;
+ unregisterTrigger: (node: HTMLButtonElement) => void;
triggerNodes: HTMLButtonElement[];
focusNext: (currentIdx: number) => void;
focusPrev: (currentIdx: number) => void;
focusFirst: () => void;
focusLast: () => void;
indicators: StepIndicators;
}Add the function in Stepper and wire it into the context:
const registerTrigger = useCallback((node: HTMLButtonElement | null) => {
setTriggerNodes((prev) => {
if (node && !prev.includes(node)) {
return [...prev, node];
} else if (!node && prev.includes(node!)) {
return prev.filter((n) => n !== node);
} else {
return prev;
}
});
}, []);
+
+ const unregisterTrigger = useCallback((node: HTMLButtonElement) => {
+ setTriggerNodes((prev) => prev.filter((n) => n !== node));
+ }, []);Add it to contextValue and its deps:
orientation,
registerTrigger,
+ unregisterTrigger,
focusNext,
focusPrev,
focusFirst,
focusLast,
triggerNodes,
indicators,
}),
[
currentStep,
handleSetActiveStep,
children,
orientation,
registerTrigger,
+ unregisterTrigger,
triggerNodes,
],Destructure it in StepperTrigger:
const {
setActiveStep,
activeStep,
registerTrigger,
+ unregisterTrigger,
triggerNodes,
focusNext,
focusPrev,
focusFirst,
focusLast,
} = stepperCtx;Add cleanup to the useEffect:
useEffect(() => {
- if (btnRef.current) {
- registerTrigger(btnRef.current);
+ const node = btnRef.current;
+ if (node) {
+ registerTrigger(node);
}
+ return () => {
+ if (node) {
+ unregisterTrigger(node);
+ }
+ };
}, [btnRef.current]);Also applies to: 250-255
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/components/reui/stepper.tsx` around lines 93 - 103, Trigger nodes are
not removed when StepperTrigger components unmount, and registerTrigger cannot
remove a node when passed null. Add an unregisterTrigger function to the Stepper
context interface and implementation that removes a specific HTMLButtonElement,
expose it through contextValue and dependencies, destructure it in
StepperTrigger, and update the registration effect to capture btnRef.current and
return cleanup that unregisters the captured node.
| [ | ||
| currentStep, | ||
| handleSetActiveStep, | ||
| children, | ||
| orientation, | ||
| registerTrigger, | ||
| triggerNodes, | ||
| ], |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
indicators is missing from the useMemo dependency array.
indicators is used in the memoized context value (line 146) but absent from the deps array (lines 148-155). If a parent passes changing indicators props, StepperIndicator will render stale content. The file-level eslint-disable react-hooks/exhaustive-deps at line 1 suppresses the warning that would have caught this.
🔧 Proposed fix
[
currentStep,
handleSetActiveStep,
children,
orientation,
registerTrigger,
triggerNodes,
+ indicators,
],📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| [ | |
| currentStep, | |
| handleSetActiveStep, | |
| children, | |
| orientation, | |
| registerTrigger, | |
| triggerNodes, | |
| ], | |
| [ | |
| currentStep, | |
| handleSetActiveStep, | |
| children, | |
| orientation, | |
| registerTrigger, | |
| triggerNodes, | |
| indicators, | |
| ], |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/components/reui/stepper.tsx` around lines 148 - 155, Add indicators
to the dependency array of the useMemo containing the stepper context value,
alongside currentStep and the other dependencies, so changing indicators props
updates StepperIndicator content.
Summary
Feat: Rewrite wiki template with reui