Skip to content

fix: onUpdate prefix event name faild to save#1778

Open
chilingling wants to merge 1 commit intoopentiny:developfrom
chilingling:fix/eventNameValidate
Open

fix: onUpdate prefix event name faild to save#1778
chilingling wants to merge 1 commit intoopentiny:developfrom
chilingling:fix/eventNameValidate

Conversation

@chilingling
Copy link
Member

@chilingling chilingling commented Feb 27, 2026

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

【问题描述】
onUpdate:xxx 的事件名无法保存。
image

【问题分析】
保存的时候,仅校验了普通的事件名,没有兼容 onUpdate:xxx 的事件名,导致无法保存。

【修复方案】
校验的时候,兼容 onUpdate:xxx 的事件名

自验证:
image

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Refactor

    • Standardized event validation using centralized patterns for improved consistency in event naming and validation logic.
  • Bug Fixes

    • Enhanced validation for update events to ensure proper property binding requirements are met.

@github-actions github-actions bot added the bug Something isn't working label Feb 27, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

Walkthrough

A new regular expression constant for validating update event names is exported from the verification module, and the BlockEventForm component is refactored to use centralized regex patterns for event name validation instead of inline checks.

Changes

Cohort / File(s) Summary
Verification constant
packages/common/js/verification.ts
Added new exported constant REGEXP_UPDATE_EVENT_NAME with regex pattern /^onUpdate:[a-zA-Z_$][\w$]*$/ for validating update event naming conventions.
Event validation refactoring
packages/plugins/block/src/BlockEventForm.vue
Imported and applied REGEXP_UPDATE_EVENT_NAME and REGEXP_EVENT_NAME constants to replace inline regex checks in validation logic; updated changeEventName method to compute validity based on event type and only rename when name differs and is valid.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A pattern emerged from the shadows bright,
Consolidated constants shining in the light,
Event names dance in validation's sight,
Update or normal, all checked just right,
Refactored and clean, our code takes flight! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: onUpdate prefix event name faild to save' directly relates to the main change: adding REGEXP_UPDATE_EVENT_NAME to validate and enable saving of onUpdate-prefixed event names.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

🧹 Nitpick comments (1)
packages/plugins/block/src/BlockEventForm.vue (1)

140-147: Consider extracting shared validation logic to reduce duplication.

The update-event validation (REGEXP_UPDATE_EVENT_NAME.test() && propertys.value.some(...)) is duplicated between the form validator (lines 114-117) and changeEventName. If validation criteria change, both locations must be updated.

♻️ Suggested refactor to extract validation helper
+    const isValidUpdateEventName = (name: string) =>
+      REGEXP_UPDATE_EVENT_NAME.test(name) &&
+      propertys.value.some((item: any) => item.property === name.replace('onUpdate:', ''))
+
     const rules = {
       eventName: [
         {
           validator: (_rule: any /* IFormInnerRule */, value: string, callback: (e?: Error) => void) => {
             if (isUpdateEvent.value) {
-              const matched = REGEXP_UPDATE_EVENT_NAME.test(value)
-              const propertyMatched = propertys.value.some((item) => item.property === value.replace('onUpdate:', ''))
-              return matched && propertyMatched
+              return isValidUpdateEventName(value)
                 ? callback()
                 : callback(new Error(`${value} 需要有对应的 ${value.replace('onUpdate:', '')} 在属性中定义`))
             }
     const changeEventName = () => {
       const isEventNameValid = isUpdateEvent.value
-        ? REGEXP_UPDATE_EVENT_NAME.test(formData.eventName) &&
-          propertys.value.some((item: any) => item.property === formData.eventName.replace('onUpdate:', ''))
+        ? isValidUpdateEventName(formData.eventName)
         : verifyEventName(formData.eventName)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/plugins/block/src/BlockEventForm.vue` around lines 140 - 147, The
update-event validation logic (REGEXP_UPDATE_EVENT_NAME.test(...) &&
propertys.value.some(...)) is duplicated between the form validator and the
changeEventName block; extract that into a single helper (e.g.,
isUpdateEventNameValid(eventName) or validateEventNameForUpdate) that uses
REGEXP_UPDATE_EVENT_NAME and propertys.value to check the stripped name, then
replace the duplicated checks in the form validation and in the changeEventName
flow (where isEventNameValid is computed and used before calling
renameBlockEventName/getEditEventName) to call the new helper, keeping
verifyEventName for non-update cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/plugins/block/src/BlockEventForm.vue`:
- Around line 140-147: The update-event validation logic
(REGEXP_UPDATE_EVENT_NAME.test(...) && propertys.value.some(...)) is duplicated
between the form validator and the changeEventName block; extract that into a
single helper (e.g., isUpdateEventNameValid(eventName) or
validateEventNameForUpdate) that uses REGEXP_UPDATE_EVENT_NAME and
propertys.value to check the stripped name, then replace the duplicated checks
in the form validation and in the changeEventName flow (where isEventNameValid
is computed and used before calling renameBlockEventName/getEditEventName) to
call the new helper, keeping verifyEventName for non-update cases.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8caa5aa and a6e6376.

📒 Files selected for processing (2)
  • packages/common/js/verification.ts
  • packages/plugins/block/src/BlockEventForm.vue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant