Skip to content

fix: copy pop-up modal logic displays abnormally#1365

Merged
chilingling merged 10 commits intoopentiny:release/v2.5.xfrom
SonyLeo:fix/compareValues
May 12, 2025
Merged

fix: copy pop-up modal logic displays abnormally#1365
chilingling merged 10 commits intoopentiny:release/v2.5.xfrom
SonyLeo:fix/compareValues

Conversation

@SonyLeo
Copy link
Contributor

@SonyLeo SonyLeo commented May 7, 2025

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

【备注】
#1361 为 前置 PR: 解决页面复制路由更新问题

【问题描述】
点击复制页面,弹出"您即将复制的页面有更改未保存,是否确定跳过更改直接复制?",但复制页面并没有更改未保存

【问题分析】
点击 复制页面 后,会执行下述步骤:

  1. 调用 copyPage() 对当前页面的信息进行保存和更新;
  2. 调用 isCurrentDataSame()datadataCopy 进行对比;
  3. 根据 isCurrentDataSame() 的返回值决定是否展示 “更改未保存” 弹窗;

【结论】

第二步对比错误,导致弹窗总是出现,由下述原因导致:

  1. 使用 java 后台时,接口的相应信息中返回的属性值包含空数组;
  2. 点击 复制页面后,页面内容更新时,当前配置页面的数据 pageSettingState.currentPageData 未更新,
    isCurrentDataSame() 中没有对 page_content 中的 children 信息进行对比

【解决方案】

  1. 增加对空数组和空对象的判断
  2. 更新 pageSettingState.currentPageData
    isCurrentDataSame() 中增加对 page_content 中的 children 信息进行对比
  3. syncPageContent 增加判断:只有当前页面设置的ID与正在编辑的页面ID一致时才同步内容,避免将正在编辑的页面内容错误同步到其他打开的页面设置中

【测试场景】

  1. 打开应用 A 页面,打开页面管理插件,
    打开 A 页面的设置页面。点击复制,表现正常✅

  2. 打开应用 A 页面,编辑,不保存。
    打开页面管理插件,打开 A 页面的设置页面。
    点击复制,提示未保存。表现正常✅,
    点击工具栏保存按钮,页面提示为保存状态。
    再次点击复制按钮,表现正常✅

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved accuracy when detecting changes in page data, reducing false positives when comparing arrays, objects, or primitive values.
    • Enhanced synchronization of page content to ensure consistency before data comparisons.
    • Updated page settings immediately after saving to keep data consistent and up to date.
  • New Features
    • Added automatic notification to update page settings after a page is saved, improving real-time data consistency across components.
    • Implemented reactive subscription management to handle page save events, ensuring page settings update automatically and subscriptions are cleaned up appropriately.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 7, 2025

Walkthrough

The import isEqual was renamed to isValuesEqual and used to replace strict inequality checks with deep equality checks in multiple functions. A new function syncPageContent was added to synchronize page content before comparisons. The isCurrentDataSame function now compares additional properties including children. The updatePageSettingAfterSave function was added to synchronize page data after saving and is triggered by a page-saved event. The updatePageContent parameters were reformatted to multi-line style. The savePage function was updated to publish a page-saved event after completing the page save. The PageSetting.vue component subscribes to the page-saved event to call updatePageSettingAfterSave and cleans up the subscription on component unmount.

Changes

File Change Summary
packages/plugins/page/src/composable/usePage.ts Renamed import to isValuesEqual; replaced strict inequality checks with deep equality checks; added syncPageContent to sync page content; enhanced isCurrentDataSame to compare children property; added updatePageSettingAfterSave to sync page data after save; reformatted updatePageContent parameters to multi-line style; exported updatePageSettingAfterSave.
packages/toolbars/save/src/js/index.ts Imported useMessage and published a page-saved event after the asynchronous page save completes to notify other components.
packages/plugins/page/src/PageSetting.vue Subscribed to page-saved event using useMessage; triggered updatePageSettingAfterSave on event; cleaned up subscription on component unmount.

Poem

In the warren of code, a new check hops in,
Comparing deep, where bugs might begin.
With isValuesEqual, we peer through the hay,
Ensuring our data won’t lead us astray.
Multiline whispers in function’s embrace—
A tidy-up touch for a hoppier place! 🐇✨
After saving, sync calls dance in line,
Keeping page data fresh and fine! 🎉🐰

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d434726 and 786cc4e.

📒 Files selected for processing (1)
  • packages/plugins/page/src/PageSetting.vue (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/plugins/page/src/PageSetting.vue

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added bug Something isn't working release merge to release/ branch, before release period labels May 7, 2025
@SonyLeo SonyLeo force-pushed the fix/compareValues branch from bf5b452 to 002bd96 Compare May 7, 2025 09:32
@SonyLeo SonyLeo marked this pull request as ready for review May 7, 2025 09:40
@chilingling
Copy link
Member

场景:

  1. 打开应用 A 页面,编辑,不保存。
  2. 打开页面管理插件,打开 A 页面的设置页面。
  3. 点击复制,提示未保存。表现正常✅
  4. 点击工具栏保存按钮,页面提示为保存状态。
  5. 再次点击复制按钮,仍然提示未保存,表现不正确 ❌

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Scene:

  1. Open the App A page, edit, and do not save.
  2. Open the page management plug-in and open the settings page of page A.
  3. Click Copy, and the prompt is not saved. Normal performance✅
  4. Click the toolbar save button, and the page prompts it to be saved.
  5. Click the copy button again, and the prompt is still not saved, and the performance is incorrect ❌

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)
packages/toolbars/save/src/js/index.ts (1)

67-69: Excellent addition to fix the data synchronization issue.

Adding a call to updatePageSettingAfterSave() after the page update completes ensures that the internal data copy (currentPageDataCopy) is synchronized with the latest saved state. This directly addresses the issue described in the PR objectives where the copy pop-up modal was incorrectly appearing after saving because currentPageDataCopy wasn't updated. This change will prevent the system from incorrectly detecting unsaved changes after a save operation.

Consider wrapping this call in a try-catch block similar to other function calls in this file (like saved() on line 175), to maintain consistent error handling throughout the codebase:

  isLoading.value = false

  // 更新页面设置状态,同步 currentPageDataCopy
+ try {
    usePage().updatePageSettingAfterSave()
+ } catch (error) {
+   useNotify({
+     type: 'error',
+     message: `Error in updating page settings: ${error}`
+   })
+ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b733ff and c4c275b.

📒 Files selected for processing (2)
  • packages/plugins/page/src/composable/usePage.ts (6 hunks)
  • packages/toolbars/save/src/js/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/plugins/page/src/composable/usePage.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check

@SonyLeo
Copy link
Contributor Author

SonyLeo commented May 12, 2025

场景:

  1. 打开应用 A 页面,编辑,不保存。
  2. 打开页面管理插件,打开 A 页面的设置页面。
  3. 点击复制,提示未保存。表现正常✅
  4. 点击工具栏保存按钮,页面提示为保存状态。
  5. 再次点击复制按钮,仍然提示未保存,表现不正确 ❌

一、问题分析

保存页面时,仅更新了 Canvas 的状态为“已保存”,
但 pageSettingState.currentPageDataCopy 并未同步更新为 pageSettingState.currentPageData 的最新数据。
在之后调用 isCurrentDataSame() 进行比较时,两个对象存在差异,因此错误地判断为存在未保存的更改。

二、结论

缺乏对 currentPageDataCopy 的更新,导致页面设置状态与 Canvas 状态不一致,引发用户混淆。

三、解决方案

在 usePage.ts 中新增 updatePageSettingAfterSave() 方法,用于同步 currentPageData 和 currentPageDataCopy

修改工具栏中的 savePage() 函数,在保存后调用上述同步方法

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Scenario:

  1. Open the App A page, edit, not save.
  2. Open the page management plug-in and open the settings page of page A.
  3. Click Copy, the prompt is not saved. Normal performance✅
  4. Click the toolbar save button, and the page prompts it to be saved.
  5. Click the copy button again, and the prompt is still not saved, and the performance is incorrect ❌

1. Problem analysis

When saving the page, only the Canvas status is updated to "Save".
However, pageSettingState.currentPageDataCopy does not synchronize the latest data updated to pageSettingState.currentPageData.
When the isCurrentDataSame() is called afterward for comparison, there is a difference between the two objects, so it is wrongly judged that there is an unsaved change.

2. Conclusion

The lack of updates to currentPageDataCopy causes the page setting status to be inconsistent with the Canvas status, causing user confusion.

3. Solution

Added updatePageSettingAfterSave() method in usePage.ts to synchronize currentPageData and currentPageDataCopy

Modify the savePage() function in the toolbar and call the above synchronization method after saving

@chilingling chilingling merged commit e9ea5b8 into opentiny:release/v2.5.x May 12, 2025
2 checks passed
xuanlid pushed a commit to xuanlid/tiny-engine that referenced this pull request May 13, 2025
修复:点击复制页面,弹出"您即将复制的页面有更改未保存,是否确定跳过更改直接复制?",但复制页面并没有更改未保存
@SonyLeo SonyLeo deleted the fix/compareValues branch August 24, 2025 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working release merge to release/ branch, before release period

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants