Do not minify preview builds, and fix HMR reload warning#3036
Conversation
WalkthroughTwo files are modified to enhance React root initialization and build configuration. In Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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 |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge The changes in this PR are development workflow improvements:
Both changes are straightforward fixes with no security, runtime, or logic issues. Files Reviewed (2 files)
|
Deploying waveterm with
|
| Latest commit: |
95e031f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b6e1a176.waveterm.pages.dev |
| Branch Preview URL: | https://sawka-fix-preview-hmr-warnin.waveterm.pages.dev |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
frontend/preview/preview.tsx (1)
168-174: LGTM! Correctly fixes HMR duplicate root warning.The cached root pattern prevents React from warning about creating multiple roots on the same container during hot module replacement.
An alternative approach using a module-level variable would avoid the
anycast:♻️ Optional: Module-level caching
+import type { Root } from "react-dom/client"; + +let cachedRoot: Root | null = null; + function initPreview() { installPreviewElectronApi(); // ... initialization code ... loadFonts(); const container = document.getElementById("main")!; - let root = (container as any).__reactRoot; - if (!root) { - root = createRoot(container); - (container as any).__reactRoot = root; + if (!cachedRoot) { + cachedRoot = createRoot(container); } - root.render(<PreviewRoot />); + cachedRoot.render(<PreviewRoot />); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/preview/preview.tsx` around lines 168 - 174, Current code uses (container as any).__reactRoot to cache the React root and avoid HMR duplicate-root warnings; replace that runtime-unsafe cast with a module-level cache: add a top-level variable (e.g., cachedRoot) typed to the React root type, check/assign cachedRoot instead of (container as any).__reactRoot when creating the root via createRoot(container), and call cachedRoot.render(<PreviewRoot />) so you remove the any cast while preserving the HMR-safe cached-root behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@frontend/preview/preview.tsx`:
- Around line 168-174: Current code uses (container as any).__reactRoot to cache
the React root and avoid HMR duplicate-root warnings; replace that
runtime-unsafe cast with a module-level cache: add a top-level variable (e.g.,
cachedRoot) typed to the React root type, check/assign cachedRoot instead of
(container as any).__reactRoot when creating the root via createRoot(container),
and call cachedRoot.render(<PreviewRoot />) so you remove the any cast while
preserving the HMR-safe cached-root behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fed67681-4f90-46d8-98d2-bb41cf6659a9
📒 Files selected for processing (2)
frontend/preview/preview.tsxfrontend/preview/vite.config.ts
No description provided.