Skip to content

Conversation

@wang1212
Copy link
Member

@wang1212 wang1212 commented Sep 8, 2025

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / Document optimization
  • TypeScript definition update
  • Refactoring
  • Performance improvement
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

Problem Description:

  • Duplicate execution of the first callback in SyncWaterfallHook: In SyncWaterfallHook.ts, the first callback function was being executed twice. This happened because the loop started at index 0, while the first callback was already executed before the loop.

  • Last callback not executed in AsyncSeriesWaterfallHook: In AsyncSeriesWaterfallHook.ts, the last callback was never being executed. This was due to an incorrect loop condition: i < this.callbacks.length - 1, which caused the loop to end prematurely.

Fix Details:

changed the loop start index from 0 to 1.

Impact:

These fixes affect all places where waterfall hooks are used, particularly the rendering service hook system, including:

  • dirtycheck hook
  • cull hook
  • pickSync hook
  • pick hook

Now these hooks will correctly execute all registered callback functions as expected.

Testing Verification:

Upon checking existing test cases, these bugs were not previously detected likely because:

  • Many tests only registered a single callback function
  • Tests may not have verified that all callbacks were properly called
  • Existing test cases were not comprehensive enough
  • It's recommended to enhance related test cases to ensure correct execution order and parameter passing for multiple callback functions.

This fix ensures that waterfall hooks behave as expected, where the first callback processes the initial parameters, subsequent callbacks process the previous callback's return value, and the final result from the last callback is returned.

📝 Changelog

Language Changelog
🇺🇸 English fix: fix loop index in SyncWaterfallHook and AsyncSeriesWaterfallHook
🇨🇳 Chinese fix: 修复 SyncWaterfallHook 合 AsyncSeriesWaterfallHook 中的循环索引异常

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

- Fix loop index in SyncWaterfallHook to start from 1 instead of 0 since the first callback is already called
- Apply the same fix to AsyncSeriesWaterfallHook for consistency
- Add comprehensive unit tests for all tapable hook types
@changeset-bot
Copy link

changeset-bot bot commented Sep 8, 2025

🦋 Changeset detected

Latest commit: b96e877

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 47 packages
Name Type
@antv/g-lite Patch
@antv/g-camera-api Patch
@antv/g-canvas Patch
@antv/g-canvaskit Patch
@antv/g-components Patch
@antv/g-dom-mutation-observer-api Patch
@antv/g-gesture Patch
@antv/g-image-exporter Patch
@antv/g-lottie-player Patch
@antv/g-mobile-canvas-element Patch
@antv/g-mobile-canvas Patch
@antv/g-mobile-svg Patch
@antv/g-mobile-webgl Patch
@antv/g-pattern Patch
@antv/g-plugin-3d Patch
@antv/g-plugin-a11y Patch
@antv/g-plugin-annotation Patch
@antv/g-plugin-box2d Patch
@antv/g-plugin-canvas-path-generator Patch
@antv/g-plugin-canvas-picker Patch
@antv/g-plugin-canvas-renderer Patch
@antv/g-plugin-canvaskit-renderer Patch
@antv/g-plugin-control Patch
@antv/g-plugin-css-select Patch
@antv/g-plugin-device-renderer Patch
@antv/g-plugin-dom-interaction Patch
@antv/g-plugin-dragndrop Patch
@antv/g-plugin-gesture Patch
@antv/g-plugin-html-renderer Patch
@antv/g-plugin-image-loader Patch
@antv/g-plugin-matterjs Patch
@antv/g-plugin-mobile-interaction Patch
@antv/g-plugin-physx Patch
@antv/g-plugin-rough-canvas-renderer Patch
@antv/g-plugin-rough-svg-renderer Patch
@antv/g-plugin-svg-picker Patch
@antv/g-plugin-svg-renderer Patch
@antv/g-plugin-yoga Patch
@antv/g-plugin-zdog-canvas-renderer Patch
@antv/g-plugin-zdog-svg-renderer Patch
@antv/g-svg Patch
@antv/g-web-animations-api Patch
@antv/g-web-components Patch
@antv/g-webgl Patch
@antv/g-webgpu Patch
@antv/g Patch
@antv/react-g Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @wang1212, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the tapable utility's waterfall hook implementations. The fix ensures that the sequential processing of callbacks correctly uses the output of the previous callback as the input for the next, resolving an issue where the initial result was not properly propagated. This change improves the reliability of event handling within the system.

Highlights

  • Bug Fix for Waterfall Hooks: Corrected an off-by-one error in the loop iteration for SyncWaterfallHook and AsyncSeriesWaterfallHook classes, ensuring that the result from the first callback is correctly passed as input to subsequent callbacks.
  • New Unit Tests: Introduced a new test file tests/unit/util/tapable.spec.ts with comprehensive unit tests for SyncHook, SyncWaterfallHook, AsyncParallelHook, and AsyncSeriesWaterfallHook to validate their behavior and the bug fix.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a bug in SyncWaterfallHook and AsyncSeriesWaterfallHook where the loop for processing subsequent callbacks had an incorrect starting index. This caused the first callback to be executed twice and the last one to be skipped. The fix adjusts the loop to iterate correctly from the second callback. The addition of unit tests for the tapable utilities is also a great improvement. My review focuses on underlying type-safety issues in both modified hook implementations. While the bug fix is correct, both SyncWaterfallHook and AsyncSeriesWaterfallHook use @ts-ignore to suppress type errors that arise from an incorrect typing of the callbacks array. I've left comments in each file suggesting a refactor of the types to improve code safety and maintainability.

@wang1212 wang1212 merged commit f08291e into release Sep 8, 2025
2 checks passed
@wang1212 wang1212 deleted the fix/tapable branch September 8, 2025 12:58
wang1212 added a commit that referenced this pull request Oct 13, 2025
* feat(benchmark): Add performance test suite and analysis panel (#1987)

* fix: docs dead links (#1984)

* fix: docs dead links

* fix: add /en prefix to english docs

* feat: upgrade chrome extension to manifest v3 and react to v18

- Upgrade manifest version from v2 to v3 with updated permissions format
- Migrate background scripts to service worker
- Update content_security_policy and web_accessible_resources format
- Replace browser_action with action
- Upgrade react and react-dom from v16 to v18 in g-devtool
- Update devtool UI to support React 18 createRoot API
- Maintain backward compatibility with legacy versions
- Update minimum chrome version requirement to 88

* feat: add GitHub workflow for bug report reproduction check

- Add new GitHub Actions workflow 'bug-report-reproduction-check'
- Automatically analyze new bug reports for reproduction steps
- Use Mistral AI to check for complete reproduction information
- Add friendly comment when reproduction details are missing
- Only trigger for issues labeled as 'bug'
- Add necessary permissions for issues and models access

* feat: add benchmark suite for rendering performance comparison

- Add benchmark infrastructure with TestCase and TestRunner base classes
- Implement test cases for basic shapes (circle, rect, path, etc.) across multiple renderers
- Support g-canvas, g-canvas-v4 and zrender rendering engines
- Add UI components for test execution and result visualization
- Include i18n support with Chinese and English translations
- Set up build configuration with Vite and TypeScript

* feat(benchmark): add collapsible insight panel in PerformanceChart

- Add state to track insight panel expansion
- Implement collapsible UI with smooth animations
- Improve styling and layout of insight panel
- Add expand/collapse toggle functionality
- Enhance user experience with better visual feedback

* chore(benchmark): add performance test results for basic shapes

Add benchmark results for basic shapes rendering comparison between different engines including g-canvas and zrender. The results include execution duration and memory usage metrics.

* feat(benchmark): enhance i18n support for failure rate display

- Add new translation key 'highestFailureRate' for displaying failure rate in both English and Chinese
- Refactor failure rate display to use i18n template
- Improve code formatting in PerformanceChart component
- Fix whitespace and indentation issues in TestRunner

* chore: remove other file

* feat: Add native pan and zoom demo (#1994)

* feat: add native pan and zoom demo

Adds a new demo under `__tests__/demos/camera/` that showcases how to implement panning and zooming on the canvas using native DOM events.

This is in response to the user request to add such a demo.

An issue in the execution environment prevented the test suite from being run. A `commitlint` hook blocked all commands, including `pnpm test`. The changes are submitted without test verification due to this environmental constraint.

* fix: use getContextService for container access in nativePanZoom demo

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: wang1212 <mrwang1212@126.com>

* feat: add script to fetch and display npm download stats for monorepo packages

* chore: update test config and TypeScript settings

- Add JSDoc link to jest.unit.config.js
- Fix module name mapper path in jest.unit.config.js
- Expand coverage collection to more packages
- Update coverage reporters
- Move isolatedModules to tsconfig.json

* fix: fix loop index in tapable (#2003)

* fix: fix loop index in SyncWaterfallHook and AsyncSeriesWaterfallHook

- Fix loop index in SyncWaterfallHook to start from 1 instead of 0 since the first callback is already called
- Apply the same fix to AsyncSeriesWaterfallHook for consistency
- Add comprehensive unit tests for all tapable hook types

* chore: fix code style

* chore: fix code lint issue

* chore: add changeset

* Add basic shape benchmark cases for g-canvas-local engine (#2030)

* test: Add basic shape benchmark cases for g-canvas-local engine

* test: Add basic shape benchmark cases for g-canvas-local engine

* Update benchmark/src/benchmarks/g-canvas-local/engine.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* feat(text): add text-decoration support for text elements (#2035)

* feat(text): add text-decoration support for text elements

* docs: update text decoration info

* docs: fix typos

* perf: element event batch triggering (#2005)

* perf: element event batch triggering

* chore: update test snapshot

* chore: use Array.from to convert iterator for compatibility

* chore: add changeset

* Update __tests__/demos/perf/custom-event.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* perf: remove rBush logic from element picking mechanism (#2031)

* perf: remove rBush logic from element picking mechanism

* chore: fix lint error

* chore: add changeset

* chore: update test case

* fix: the element picking range includes the element border

* chore(release): bump version (#2004)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* perf(g-plugin-canvas-renderer): improve wavy text decoration with quadratic curves

* Update __tests__/demos/event/hit-test.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants