Skip to content

fix: init app without pageId cannot save page#1440

Merged
hexqi merged 2 commits intoopentiny:developfrom
chilingling:fix/initWithoutPageIdCannotSave
May 29, 2025
Merged

fix: init app without pageId cannot save page#1440
hexqi merged 2 commits intoopentiny:developfrom
chilingling:fix/initWithoutPageIdCannotSave

Conversation

@chilingling
Copy link
Member

@chilingling chilingling commented May 28, 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

【问题描述】
进入设计器时,如果 url 上没有页面 id,编辑画布后保存,无法保存,保存接口会报错。
详见 #1282

【问题分析】
url 上没有页面 id 的逻辑,跟有页面 id 的初始化逻辑有差异,没有页面 id 的初始化逻辑,没有往 initData 函数传入页面必要的相关参数,比如 route等等。导致点击保存按钮,调用保存接口传参的时候,缺少必要参数,导致报错。

【解决方案】
将有页面 id 和没有页面 id 的初始化逻辑保持一致。确保进入应用没有页面 id 时,自动寻找的页面 id 能够得到必要的相关参数。

【自测用例】

  • 进入没有页面的空白应用
  • 使用带有页面 id 的 url 进入应用
  • 使用不带有页面 id 的 url 进入应用

What is the current behavior?

Issue Number: #1282

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Refactor
    • Improved and streamlined page initialization for a more consistent user experience. Breadcrumbs and page status are now set more reliably based on updated page data handling. No visible changes to exported features or user interface.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 28, 2025

"""

Walkthrough

The changes refactor the page initialization logic in useResource.ts. The initPage function now accesses properties directly from pageInfo, simplifying data handling and reducing reliance on nested meta fields. The initPageOrBlock function centralizes page setup by consistently using the updated initPage method, streamlining how page data is processed and initialized.

Changes

File(s) Change Summary
packages/plugins/materials/src/composable/useResource.ts Refactored initPage to use direct pageInfo properties, updated data handling, and unified initialization logic in initPageOrBlock.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant useResource
    participant pagePluginApi
    participant useCanvas
    participant layout

    Caller->>useResource: initPageOrBlock(pageId, ...)
    useResource->>pagePluginApi: getPagePluginApi()
    alt pageId exists
        useResource->>pagePluginApi: getPage(pageId)
        pagePluginApi-->>useResource: pageInfo
        useResource->>useResource: initPage(pageInfo)
    else
        useResource->>useResource: initPage(defaultPageInfo)
    end
    useResource->>layout: setPageStatus(pageInfo.occupier)
    useResource->>useCanvas: initData(pageInfo.page_content)
    useResource->>layout: setBreadcrumb(pageInfo.name)
Loading

Poem

In the warren of pages, logic now flows,
With direct little hops where the data now goes.
Breadcrumbs are clearer, content’s in view,
No more meta-maze for this bunny crew!
Centralized, simplified, all in one place—
A carrot-sweet refactor, a streamlined embrace. 🥕
"""


📜 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 df82c13 and 6ec4c83.

📒 Files selected for processing (1)
  • packages/plugins/materials/src/composable/useResource.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/plugins/materials/src/composable/useResource.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check
✨ 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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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 the bug Something isn't working label May 28, 2025
@chilingling chilingling linked an issue May 28, 2025 that may be closed by this pull request
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: 1

🔭 Outside diff range comments (1)
packages/plugins/materials/src/composable/useResource.ts (1)

71-78: 🛠️ Refactor suggestion

Update interface to reflect new data structure.

The PageInfo interface should be updated to reflect the changes in data structure, particularly the addition of properties like occupier, page_content, and name.

Update the interface to match the new data structure:

 interface PageInfo {
   [x: string]: any
   meta: any
   id: string
   fileName: string
+  name?: string
+  occupier?: any
+  page_content?: any
   componentName: string
   props: any
 }
🧹 Nitpick comments (1)
packages/plugins/materials/src/composable/useResource.ts (1)

143-148: LGTM: Addresses the core issue effectively.

This change appears to be the key fix for the issue described in the PR. It properly handles the case where there's no pageId in the URL but a default page exists with an ID, ensuring proper page initialization and saving capability.

Consider adding error handling for the API call to improve robustness:

  if (pageInfo.meta?.id) {
-    const data = await pagePluginApi.getPageById(pageInfo.meta.id)
-    initPage(data)
+    try {
+      const data = await pagePluginApi.getPageById(pageInfo.meta.id)
+      initPage(data)
+    } catch (error) {
+      console.error('Failed to fetch page data:', error)
+      initPage(toRaw(pageInfo))
+    }
  } else {
    initPage(toRaw(pageInfo))
  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ff26ad6 and df82c13.

📒 Files selected for processing (1)
  • packages/plugins/materials/src/composable/useResource.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check
🔇 Additional comments (5)
packages/plugins/materials/src/composable/useResource.ts (5)

95-95: LGTM: Simplified data handling.

The change from destructured schema to pageInfo?.page_content || {} simplifies the data handling and aligns well with the new data structure approach.


119-119: LGTM: Improved code organization.

Moving the pagePluginApi declaration outside the conditional blocks improves code organization and reduces duplication.


123-123: LGTM: Centralized page initialization logic.

Calling initPage(data) instead of manually setting layout status, canvas data, and breadcrumb centralizes the initialization logic and improves maintainability.


138-141: LGTM: Consistent fallback structure.

The change to use page_content with nested componentName aligns with the new data structure and maintains consistency with how page data is handled throughout the function.


96-96:

Details

❓ Verification inconclusive

Verify property name consistency.

The change from pageInfo.fileName to pageInfo?.name suggests a property name change in the data structure.

Please verify that the property name change is consistent:


🏁 Script executed:

#!/bin/bash
# Description: Check for any remaining usage of fileName vs name property
# Expected: All should use the name property consistently

echo "=== Searching for fileName usage ==="
rg -A 2 "fileName" --type ts

echo "=== Searching for pageInfo.name usage ==="
rg -A 2 "pageInfo\.name" --type ts

Length of output: 25845


🏁 Script executed:

#!/bin/bash
echo "=== pageInfo in useResource.ts ==="
rg -n "pageInfo" packages/plugins/materials/src/composable/useResource.ts

echo -e "\n=== Searching for pageInfo.fileName usage ==="
rg -A2 "pageInfo\\.fileName" --type ts

echo -e "\n=== Inspecting type definitions in types.ts ==="
sed -n '1,200p' packages/plugins/materials/src/composable/types.ts

Length of output: 4867


🏁 Script executed:

#!/bin/bash
echo "=== Imports in useResource.ts ==="
sed -n '1,50p' packages/plugins/materials/src/composable/useResource.ts

echo -e "\n=== Searching for PageInfo type/interface definition ==="
rg -R "interface PageInfo" -n .

echo -e "\n=== Searching for type alias PageInfo ==="
rg -R "type PageInfo" -n .

Length of output: 2516


Confirm PageInfo property name

We searched the repo and found no pageInfo.fileName usages—only pageInfo?.name at line 96 in useResource.ts. The PageInfo type is defined externally (in @opentiny/tiny-engine-meta-register), so please verify that it indeed exposes a name property (and not fileName).

• packages/plugins/materials/src/composable/useResource.ts: line 96 (useBreadcrumb().setBreadcrumbPage([pageInfo?.name || '']))

@hexqi hexqi added this to the v2.6.0 milestone May 28, 2025
@chilingling chilingling added the ready_for_review This PR requires more reviews label May 28, 2025
@hexqi hexqi merged commit 03a1042 into opentiny:develop May 29, 2025
4 checks passed
chilingling added a commit to chilingling/tiny-engine that referenced this pull request Jun 4, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jun 27, 2025
14 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jul 29, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready_for_review This PR requires more reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: Page cannot be saved if there is no pageId on the url.

2 participants