Skip to content

[codex] fix duplicated pre-render event listeners#4596

Merged
xuefei1313 merged 1 commit into
developfrom
fix/dedupe-remade-user-events
Jun 16, 2026
Merged

[codex] fix duplicated pre-render event listeners#4596
xuefei1313 merged 1 commit into
developfrom
fix/dedupe-remade-user-events

Conversation

@xuefei1313

Copy link
Copy Markdown
Contributor

🤔 This is a ...

  • New feature
  • Bug fix
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Refactoring
  • Update dependency
  • Code style optimization
  • Test Case
  • Branch merge
  • Release
  • Site / documentation update
  • Demo update
  • Workflow
  • Other (about what?)

🔗 Related issue link

N/A

🔗 Related PR link

N/A

🐞 Bugserver case id

N/A

💡 Background and solution

When a VChart instance is created with an empty initial spec and a user registers a chart/model-level event before calling updateSpec, the type change causes the reMake path to run before any chart/model has been initialized.

The user callback is already registered in the event dispatcher at that point. The old reMake logic always replayed _userEvents, so the same callback was inserted into the event bubble queue twice and one click could trigger the handler twice.

This change only replays _userEvents when a prior chart instance existed and its release path could have cleared dispatcher handlers. It preserves the existing replay behavior for real remakes while avoiding duplicate registration for pre-render/updateSpec initialization.

A regression test covers the reported sequence:

const vc = new VChart({ type: '' }, options);
vc.on('click', { source: 'chart', level: 'model' }, cb);
vc.updateSpecSync(barSpec);

📝 Changelog

Language Changelog
🇺🇸 English Fix duplicate chart/model event callbacks when events are registered before updateSpec initializes the chart.
🇨🇳 Chinese 修复在 updateSpec 初始化图表前注册 chart/model 事件时,回调被重复触发的问题。

☑️ Self-Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

🚀 Summary

  • Added a regression test for pre-updateSpec user event registration.
  • Skipped _userEvents replay when reMake runs without a prior chart instance.

🔍 Walkthrough

  • packages/vchart/src/core/vchart.ts: gate user event replay on whether a previous chart existed before reMake release.
  • packages/vchart/__tests__/unit/core/vchart.test.ts: verify a model-level click callback registered before updateSpecSync only fires once.

✅ Validation

  • npm test -- __tests__/unit/core/vchart.test.ts --runInBand
  • npm test -- __tests__/unit/event/event.test.ts --runInBand
  • npm run compile
  • npx eslint src/core/vchart.ts __tests__/unit/core/vchart.test.ts (0 errors; existing warnings)
  • pre-push rush test --only tag:package (47 vchart suites / 136 tests passed; existing MaxListenersExceededWarning shown)

When updateSpec changes an empty initial spec into a real chart type,
VChart enters the reMake path before any chart/model has been
initialized. User callbacks registered before updateSpec are already in
the dispatcher, so replaying _userEvents adds the same callback to the
bubble queue a second time.

Keep replay behavior for real remakes where an existing chart release can
clear dispatcher state, but skip replay when there was no prior chart to
release.

Constraint: updateSpec can reMake before any chart/model exists
Rejected: Bubble-level dedupe | same callback can use distinct event queries
Confidence: high
Scope-risk: narrow
Directive: Replay _userEvents only after releasing a prior chart
Tested: npm test -- __tests__/unit/core/vchart.test.ts --runInBand
Tested: npm test -- __tests__/unit/event/event.test.ts --runInBand
Tested: npm run compile
Tested: eslint changed files (0 errors; existing warnings)
Not-tested: full repository test suite
@xuefei1313 xuefei1313 marked this pull request as ready for review June 16, 2026 09:25
@xuefei1313 xuefei1313 merged commit 0f4ba96 into develop Jun 16, 2026
8 of 10 checks passed
@xuefei1313 xuefei1313 deleted the fix/dedupe-remade-user-events branch June 16, 2026 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants