Skip to content

Conversation

@jyqwq
Copy link
Contributor

@jyqwq jyqwq commented Jan 12, 2026

…oad success or error messages

因为antd Upload已被重新封装,导致onChange事件存在冲突,会出现警告信息,通过切换为 handleChange 事件解决此警告。

image

Type of change

Please delete options that are not relevant.

  • [ ✅ ] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • [ ✅ ] If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • [ ✅ ] Run the tests with pnpm test.
  • [ ✅ ] Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • [ ✅ ] My code follows the style guidelines of this project
  • [ ✅ ] I have performed a self-review of my own code
  • [ ✅ ] I have commented my code, particularly in hard-to-understand areas
  • [ ✅ ] I have made corresponding changes to the documentation
  • [ ✅ ] My changes generate no new warnings
  • [ ✅ ] I have added tests that prove my fix is effective or that my feature works
  • [ ✅ ] New and existing unit tests pass locally with my changes
  • [ ✅ ] Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features

    • Upload components now call user-provided change handlers before updating internal state.
    • Form examples include configurable handling that shows localized success or error messages for uploads.
  • Bug Fixes

    • Errors thrown by user handlers are caught and logged so they no longer interrupt internal upload state synchronization.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Jan 12, 2026

⚠️ No Changeset found

Latest commit: d410fb1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 12, 2026

📝 Walkthrough

Walkthrough

Forward Upload change events to optional external handlers (attrs.handleChange and attrs.onHandleChange) in two adapter implementations; update example Upload config to display success/error messages based on file.status.

Changes

Cohort / File(s) Summary
Upload Adapter Handlers
apps/web-antd/src/adapter/component/index.ts, playground/src/adapter/component/index.ts
handleChange was changed from async to synchronous and now invokes attrs.handleChange and attrs.onHandleChange inside a try/catch before updating fileList and emitting update:modelValue. Errors from user handlers are caught and logged.
Upload Component Example
playground/src/views/examples/form/basic.vue
Added a handleChange({ file }) handler that shows a success message when file.status === 'done' and an error message when file.status === 'error'.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • anncwb
  • vince292007
  • mynetfan
  • jinmao88

Poem

🐰 I hopped through code with tiny paws and cheer,
I wrapped your handlers so errors won't steer,
I call your hooks, then quietly mend,
Success and error messages—hoppy end! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly relates to the main change: fixing the antd Upload onChange event conflict by switching to handleChange.
Description check ✅ Passed The description includes the problem statement, type of change selection, and checklist completion, but lacks detailed technical explanation of the fix.
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

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
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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web-antd/src/adapter/component/index.ts (1)

290-343: Filter out handleChange and onHandleChange from attrs before spreading to Upload, and guard external handler calls.

With inheritAttrs defaulting to true, spreading ...attrs forwards these custom properties to the ant-design-vue Upload component, which doesn't recognize them. This surfaces extraneous attribute warnings. Additionally, if an external handler throws, it will currently break your fileList sync since the state update happens after the handler calls.

Proposed fix
-      const handleChange = async (event: UploadChangeParam) => {
-        // 行内写法 handleChange: (event) => {}
-        attrs.handleChange?.(event);
-        // template写法 @handle-change="(event) => {}"
-        attrs.onHandleChange?.(event);
+      const handleChange = (event: UploadChangeParam) => {
+        // 行内写法 handleChange: (event) => {}
+        // template写法 @handle-change="(event) => {}"
+        try {
+          attrs.handleChange?.(event);
+          attrs.onHandleChange?.(event);
+        } catch (e) {
+          // Avoid breaking internal v-model sync on user handler errors
+          console.error(e);
+        }
         fileList.value = event.fileList.filter(
           (file) => file.status !== 'removed',
         );
         emit(
           'update:modelValue',
           event.fileList?.length ? fileList.value : undefined,
         );
       };
@@
-      return () =>
+      return () => {
+        const { handleChange: _hc, onHandleChange: _ohc, ...uploadAttrs } =
+          attrs as any;
+        return (
         h(
           Upload,
           {
             ...props,
-            ...attrs,
+            ...uploadAttrs,
             fileList: fileList.value,
             beforeUpload: handleBeforeUpload,
             onChange: handleChange,
             onPreview: handlePreview,
           },
           renderUploadButton(),
-        );
+        )
+        );
+      };
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a51b8c and 1478b91.

📒 Files selected for processing (2)
  • apps/web-antd/src/adapter/component/index.ts
  • playground/src/adapter/component/index.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Check (windows-latest)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Check (ubuntu-latest)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: post-update (ubuntu-latest)
🔇 Additional comments (1)
playground/src/adapter/component/index.ts (1)

299-352: Filter handleChange and onHandleChange out of forwarded attrs to prevent duplicate listener warnings.

Currently, these handlers are both called directly and passed to the Upload component via ...attrs, which can trigger "extraneous attrs" warnings depending on how Upload is defined. Destructure attrs to exclude these properties before spreading, and wrap handler invocations in try-catch for safety:

Proposed fix
-      const handleChange = async (event: UploadChangeParam) => {
-        attrs.handleChange?.(event);
-        attrs.onHandleChange?.(event);
+      const handleChange = (event: UploadChangeParam) => {
+        try {
+          attrs.handleChange?.(event);
+          attrs.onHandleChange?.(event);
+        } catch (e) {
+          console.error(e);
+        }
         fileList.value = event.fileList.filter(
           (file) => file.status !== 'removed',
         );
         emit(
           'update:modelValue',
           event.fileList?.length ? fileList.value : undefined,
         );
       };
+
-      return () =>
+      return () => {
+        const { handleChange: _hc, onHandleChange: _ohc, ...uploadAttrs } = attrs;
+        return (
         h(
           Upload,
           {
             ...props,
-            ...attrs,
+            ...uploadAttrs,
             fileList: fileList.value,
             beforeUpload: handleBeforeUpload,
             onChange: handleChange,
             onPreview: handlePreview,
           },
           renderUploadButton(),
-        );
+        )
+        );
+      };

Copy link
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: 0

🧹 Nitpick comments (1)
playground/src/adapter/component/index.ts (1)

299-316: LGTM — mirrors the pattern in apps/web-antd adapter.

The implementation correctly isolates user handler errors. Since this logic is duplicated verbatim in apps/web-antd/src/adapter/component/index.ts, you could consider extracting the handleChange helper to a shared utility to reduce duplication across adapters. This is optional and can be deferred if maintaining separate adapters is intentional.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1478b91 and d410fb1.

📒 Files selected for processing (2)
  • apps/web-antd/src/adapter/component/index.ts
  • playground/src/adapter/component/index.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: post-update (ubuntu-latest)
  • GitHub Check: Check (windows-latest)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Check (ubuntu-latest)
  • GitHub Check: Lint (windows-latest)
🔇 Additional comments (1)
apps/web-antd/src/adapter/component/index.ts (1)

290-307: LGTM — correctly isolates user handler errors from internal state sync.

The try-catch ensures user-provided handlers don't break v-model synchronization. One minor note: if a user handler is async and throws, the rejection occurs outside this synchronous try-catch and won't be caught. This is acceptable since the subsequent state update still executes unaffected, but consider documenting this behavior for consumers.

@jinmao88 jinmao88 merged commit 174c4ae into vbenjs:main Jan 14, 2026
10 of 14 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.

2 participants