[codex] fix duplicated pre-render event listeners#4596
Merged
Conversation
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
skie1997
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 This is a ...
🔗 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 thereMakepath 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
_userEventswhen 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:
📝 Changelog
updateSpecinitializes the chart.updateSpec初始化图表前注册 chart/model 事件时,回调被重复触发的问题。☑️ Self-Check before Merge
🚀 Summary
_userEventsreplay whenreMakeruns 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 beforeupdateSpecSynconly fires once.✅ Validation
npm test -- __tests__/unit/core/vchart.test.ts --runInBandnpm test -- __tests__/unit/event/event.test.ts --runInBandnpm run compilenpx eslint src/core/vchart.ts __tests__/unit/core/vchart.test.ts(0 errors; existing warnings)rush test --only tag:package(47 vchart suites / 136 tests passed; existing MaxListenersExceededWarning shown)