Skip to content

fix(classic): initialize chart canvas browser env#5789

Closed
QuentinHsu wants to merge 1 commit into
mainfrom
fix/classic-vchart-canvas-env
Closed

fix(classic): initialize chart canvas browser env#5789
QuentinHsu wants to merge 1 commit into
mainfrom
fix/classic-vchart-canvas-env

Conversation

@QuentinHsu

@QuentinHsu QuentinHsu commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

修复 classic 前端打开 /console 时 VChart/VRender 报 createCanvas 未定义的问题。变更在应用入口提前注册 VChart 的 browser 环境,并将 classic 的 VisActor 相关依赖解析固定到同一套运行时,避免 @visactor/vchart@visactor/vrender-* 混用不同版本实例。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 Issues 与 PRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

  • git diff --cached --check 通过
  • web/classic: bun run build 通过
  • 手动验证 http://localhost:5174/console 正常渲染,不再触发 createCanvas ErrorBoundary

Summary by CodeRabbit

  • New Features
    • Improved support for chart rendering in the classic web app by initializing the charting environment on startup.
    • Updated dependency resolution so chart-related packages are loaded from the intended locations, helping ensure charts work reliably in the browser.

- register the VChart browser rendering environment before the classic app boots to avoid missing createCanvas during dashboard chart initialization.
- pin classic VisActor dependency resolution to prevent mixed VChart and VRender runtime versions.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a new vchart.js initialization module that registers the VChart browser environment on load. This module is imported in index.jsx to run its side effects at app startup. The rsbuild config is extended with path constants and resolve.alias entries to resolve @visactor/* packages from local directories.

Changes

VChart Browser Environment Initialization

Layer / File(s) Summary
VChart browser env module and app entry import
web/classic/src/lib/vchart.js, web/classic/src/index.jsx
New vchart.js calls registerBrowserEnv() and sets vglobal to browser mode on load; index.jsx imports it to trigger these side effects at startup.
rsbuild @visactor path aliases
web/classic/rsbuild.config.ts
Adds two directory path constants and extends resolve.alias to map @visactor/vchart, vrender-core, vrender-kits, and vutils to local filesystem paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit hops through the browser land,
With registerBrowserEnv() close at hand,
The VChart wakes and finds its home,
No more in unknown paths to roam,
Aliases set, the bundles align — 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: initializing the classic chart canvas browser environment early.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 fix/classic-vchart-canvas-env

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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 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/classic/rsbuild.config.ts`:
- Around line 13-17: The Visactor alias setup is hard-coded to nested
node_modules paths, which can break in hoisted or deduped installs. Update the
rsbuild config near the visactorDir and reactVChartVisactorDir definitions to
resolve each package root from its package.json instead of assuming
`@visactor/react-vchart/node_modules/`@visactor exists. Keep the aliases in the
same config block, but use package-based resolution so the paths remain stable
across install layouts.
🪄 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: dedae02f-6c0a-4d09-aee9-fa8ab0756293

📥 Commits

Reviewing files that changed from the base of the PR and between 2d5a041 and 8b6d87e.

📒 Files selected for processing (3)
  • web/classic/rsbuild.config.ts
  • web/classic/src/index.jsx
  • web/classic/src/lib/vchart.js

Comment on lines +13 to +17
const visactorDir = path.resolve(__dirname, './node_modules/@visactor')
const reactVChartVisactorDir = path.resolve(
__dirname,
'./node_modules/@visactor/react-vchart/node_modules/@visactor',
)

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Avoid hard-coding Visactor paths under node_modules. These aliases depend on @visactor/react-vchart/node_modules/@visactor existing exactly as written, which can break on hoisted or deduped installs. Resolve the package roots from their package.json files instead.

🤖 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/classic/rsbuild.config.ts` around lines 13 - 17, The Visactor alias setup
is hard-coded to nested node_modules paths, which can break in hoisted or
deduped installs. Update the rsbuild config near the visactorDir and
reactVChartVisactorDir definitions to resolve each package root from its
package.json instead of assuming `@visactor/react-vchart/node_modules/`@visactor
exists. Keep the aliases in the same config block, but use package-based
resolution so the paths remain stable across install layouts.

@QuentinHsu QuentinHsu closed this Jun 28, 2026
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