Skip to content

RE1-T114 Fix tf is not defined error by disabling esbuild minification#336

Merged
ucswift merged 1 commit into
masterfrom
develop
Apr 21, 2026
Merged

RE1-T114 Fix tf is not defined error by disabling esbuild minification#336
ucswift merged 1 commit into
masterfrom
develop

Conversation

@ucswift
Copy link
Copy Markdown
Member

@ucswift ucswift commented Apr 21, 2026

  • Add minify: false to vite.config.ts to prevent esbuild from renaming React variables, which caused a naming collision where React's Component constructor was renamed to 'tf' - the same name already used for Symbol.for('react.portal') in React's production bundle.
  • Upgrade Dockerfile Node.js from 18.x (EOL) to 20.x LTS.

Summary by CodeRabbit

  • Chores
    • Updated Node.js runtime to version 20.x for improved compatibility and performance.
    • Adjusted build configuration settings.

- Add minify: false to vite.config.ts to prevent esbuild from renaming
  React variables, which caused a naming collision where React's Component
  constructor was renamed to 'tf' - the same name already used for
  Symbol.for('react.portal') in React's production bundle.
- Upgrade Dockerfile Node.js from 18.x (EOL) to 20.x LTS.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

📝 Walkthrough

Walkthrough

The pull request updates two configuration files: the Vite build configuration to disable minification and modify chunk naming patterns, and the Dockerfile to upgrade Node.js from version 18.x to 20.x.

Changes

Cohort / File(s) Summary
Build Configuration
Web/Resgrid.Web/Areas/User/Apps/vite.config.ts
Disabled output minification and updated emitted JS chunk naming pattern from chunks/[name]-[hash].js to chunks/[name]-[hash].min.js.
Docker Configuration
Web/Resgrid.Web/Dockerfile
Upgraded Node.js installation from version 18.x to 20.x via NodeSource setup script.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the primary change: disabling minification in vite.config.ts to fix a naming collision error, which aligns with the main objective described in the PR description.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch develop

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.

Copy link
Copy Markdown
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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
Web/Resgrid.Web/Dockerfile (1)

20-20: Node 20.x upgrade looks good; minor cleanup available.

Upgrading from EOL Node 18 to Node 20 LTS is appropriate and compatible with @types/node@^20.16.11 and Vite 5 in package.json. Two small nits on this line:

  • There is a stray double space in the URL (setup_20.x | bash -). Harmless to the shell, but worth tidying.
  • Piping the NodeSource setup script directly into bash is the legacy flow. NodeSource now recommends the keyring + apt source approach, which is more auditable and cache-friendly for Docker layers. Optional, not blocking.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Web/Resgrid.Web/Dockerfile` at line 20, The RUN line "RUN curl -sL
https://deb.nodesource.com/setup_20.x  | bash -" has a stray double space and
uses the legacy curl|bash install; fix by removing the extra space in the URL
and replace the piped installer with NodeSource's recommended keyring + apt
source flow: download and install the NodeSource GPG keyring into
/usr/share/keyrings, add the deb source entry for Node 20 to apt sources
referencing that keyring, run apt-get update, then apt-get install -y nodejs
(update the Dockerfile step that currently contains the RUN curl... | bash - to
use this keyring+apt approach for better layer caching and auditability).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Web/Resgrid.Web/Areas/User/Apps/vite.config.ts`:
- Line 34: The chunk filename template in vite.config.ts currently hardcodes the
".min.js" suffix (chunkFileNames: 'chunks/[name]-[hash].min.js') which is
misleading when build.minify is false; update the Vite config to generate chunk
names without the .min.js suffix or make the suffix conditional based on the
build.minify setting so filenames reflect whether files are actually
minified—modify the chunkFileNames template (and any related
rollupOptions/output config) to use 'chunks/[name]-[hash].js' or an expression
that appends '.min' only when build.minify is true.
- Line 20: Add an inline comment above the minify: false setting in
vite.config.ts explaining this is a temporary workaround for esbuild identifier
mangling that breaks React production bundles and reference the tracker/PR
(e.g., RE1-T114); then either revert to enabling minification with esbuild: {
keepNames: true } on the build config or switch to using Terser with
terserOptions: { mangle: { keep_classnames: true, keep_fnames: true } } as a
targeted fix—do not leave minify: false undocumented so the workaround isn't
forgotten.

---

Nitpick comments:
In `@Web/Resgrid.Web/Dockerfile`:
- Line 20: The RUN line "RUN curl -sL https://deb.nodesource.com/setup_20.x  |
bash -" has a stray double space and uses the legacy curl|bash install; fix by
removing the extra space in the URL and replace the piped installer with
NodeSource's recommended keyring + apt source flow: download and install the
NodeSource GPG keyring into /usr/share/keyrings, add the deb source entry for
Node 20 to apt sources referencing that keyring, run apt-get update, then
apt-get install -y nodejs (update the Dockerfile step that currently contains
the RUN curl... | bash - to use this keyring+apt approach for better layer
caching and auditability).
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a9c9a98b-380c-4519-ba8f-2e8d4e0e18e8

📥 Commits

Reviewing files that changed from the base of the PR and between fb45e77 and 738387e.

📒 Files selected for processing (2)
  • Web/Resgrid.Web/Areas/User/Apps/vite.config.ts
  • Web/Resgrid.Web/Dockerfile

target: 'es2022',
outDir: 'dist/core',
emptyOutDir: true,
minify: false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

Vite 5 build.minify esbuild keepNames option to prevent identifier mangling

💡 Result:

In Vite 5 with build.minify set to 'esbuild' (the default), you can prevent esbuild from mangling identifiers including function/class names by configuring the top-level esbuild option in vite.config.js with keepNames: true. This passes esbuild options to both transform and minify phases. Example configuration: import { defineConfig } from 'vite' export default defineConfig({ esbuild: { keepNames: true }, build: { minify: 'esbuild' } }) Note that keepNames preserves all names, which may increase bundle size. For finer control (e.g., specific names), switch to Terser: build: { minify: 'terser', terserOptions: { mangle: { reserved: ['specificFunctionName'] } } } This works because Vite merges user-provided esbuild options into the minification step when using esbuild as minifier, as confirmed in Vite source code and community reports. There have been historical issues with keepNames in transform phases conflicting with tree-shaking, but user config overrides apply to minify. As of 2026, issue #13727 notes a fix in recent Vite versions.

Citations:


🏁 Script executed:

cat -n Web/Resgrid.Web/Areas/User/Apps/vite.config.ts

Repository: Resgrid/Core

Length of output: 1667


🏁 Script executed:

# Search for RE1-T114 references
rg "RE1-T114" --type ts --type js --type md --type txt

Repository: Resgrid/Core

Length of output: 38


🏁 Script executed:

# Search for any comments about minify or minification
rg "minify|minification" Web/Resgrid.Web/Areas/User/Apps/vite.config.ts -C 3

Repository: Resgrid/Core

Length of output: 242


🏁 Script executed:

# Search for related issues or TODOs in the config
rg "tf is not defined|Symbol.for|react.portal" -C 3

Repository: Resgrid/Core

Length of output: 50370


Add an explanatory comment clarifying why minification is disabled and link to the issue tracker.

Disabling minification globally ships much larger bundles — the root cause is esbuild's identifier mangling colliding with React's production bundle, but the current workaround significantly impacts performance (often 2–4× larger with slower parsing). Consider a more targeted fix instead:

  • Keep minification enabled with esbuild: { keepNames: true } to preserve identifier names without disabling compression entirely, or
  • Switch to Terser with terserOptions: { mangle: { keep_classnames: true, keep_fnames: true } }

At minimum, add an inline comment explaining why minify: false is set and reference the issue/PR (e.g., RE1-T114) so this temporary workaround doesn't get overlooked and can be re-enabled once upstream is fixed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Web/Resgrid.Web/Areas/User/Apps/vite.config.ts` at line 20, Add an inline
comment above the minify: false setting in vite.config.ts explaining this is a
temporary workaround for esbuild identifier mangling that breaks React
production bundles and reference the tracker/PR (e.g., RE1-T114); then either
revert to enabling minification with esbuild: { keepNames: true } on the build
config or switch to using Terser with terserOptions: { mangle: {
keep_classnames: true, keep_fnames: true } } as a targeted fix—do not leave
minify: false undocumented so the workaround isn't forgotten.

output: {
entryFileNames: 'react-elements.js',
chunkFileNames: 'chunks/[name]-[hash].js',
chunkFileNames: 'chunks/[name]-[hash].min.js',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

.min.js suffix is misleading now that minification is disabled.

With build.minify: false, chunks emitted as chunks/[name]-[hash].min.js are not actually minified. This will confuse anyone debugging asset sizes or cache headers, and some CDN/compression rules key off .min.js.

Proposed fix
-          chunkFileNames: 'chunks/[name]-[hash].min.js',
+          chunkFileNames: 'chunks/[name]-[hash].js',
📝 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.

Suggested change
chunkFileNames: 'chunks/[name]-[hash].min.js',
chunkFileNames: 'chunks/[name]-[hash].js',
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Web/Resgrid.Web/Areas/User/Apps/vite.config.ts` at line 34, The chunk
filename template in vite.config.ts currently hardcodes the ".min.js" suffix
(chunkFileNames: 'chunks/[name]-[hash].min.js') which is misleading when
build.minify is false; update the Vite config to generate chunk names without
the .min.js suffix or make the suffix conditional based on the build.minify
setting so filenames reflect whether files are actually minified—modify the
chunkFileNames template (and any related rollupOptions/output config) to use
'chunks/[name]-[hash].js' or an expression that appends '.min' only when
build.minify is true.

@ucswift
Copy link
Copy Markdown
Member Author

ucswift commented Apr 21, 2026

Approve

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

This PR is approved.

@ucswift ucswift merged commit 39c7d6b into master Apr 21, 2026
19 checks passed
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