Skip to content

Do not minify preview builds, and fix HMR reload warning#3036

Merged
sawka merged 2 commits intomainfrom
sawka/fix-preview-hmr-warning
Mar 11, 2026
Merged

Do not minify preview builds, and fix HMR reload warning#3036
sawka merged 2 commits intomainfrom
sawka/fix-preview-hmr-warning

Conversation

@sawka
Copy link
Member

@sawka sawka commented Mar 11, 2026

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

Walkthrough

Two files are modified to enhance React root initialization and build configuration. In preview.tsx, the initialization logic is updated to cache and reuse React roots on the container element, checking for an existing root before creation. In vite.config.ts, a build configuration block is added to disable minification during the build process. Together, these changes affect root lifecycle management and build output behavior across 9 total lines of modification.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No description was provided by the author, making it impossible to evaluate whether it relates to the changeset. Add a pull request description explaining the motivation for disabling minification and how the HMR reload warning is addressed.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies two main changes: disabling minification for preview builds and fixing an HMR reload warning, matching the actual code modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sawka/fix-preview-hmr-warning

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Mar 11, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The changes in this PR are development workflow improvements:

  1. frontend/preview/preview.tsx - Implements React hot module replacement (HMR) support by checking for an existing React root before creating a new one, preventing the "Rendered more hooks than during the previous render" warning during development.

  2. frontend/preview/vite.config.ts - Disables code minification in the preview build, making debugging easier in browser dev tools.

Both changes are straightforward fixes with no security, runtime, or logic issues.

Files Reviewed (2 files)
  • frontend/preview/preview.tsx - No issues
  • frontend/preview/vite.config.ts - No issues

@cloudflare-workers-and-pages
Copy link

Deploying waveterm with  Cloudflare Pages  Cloudflare Pages

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

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 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 any cast:

♻️ 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

📥 Commits

Reviewing files that changed from the base of the PR and between ecccad6 and 95e031f.

📒 Files selected for processing (2)
  • frontend/preview/preview.tsx
  • frontend/preview/vite.config.ts

@sawka sawka merged commit 60cdf05 into main Mar 11, 2026
8 checks passed
@sawka sawka deleted the sawka/fix-preview-hmr-warning branch March 11, 2026 23:02
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