Skip to content

fix: preserve pages when moving document blocks - #8999

Open
kaluli123123 wants to merge 2 commits into
AppFlowy-IO:mainfrom
kaluli123123:inspect/7588
Open

fix: preserve pages when moving document blocks#8999
kaluli123123 wants to merge 2 commits into
AppFlowy-IO:mainfrom
kaluli123123:inspect/7588

Conversation

@kaluli123123

@kaluli123123 kaluli123123 commented Sep 8, 2026

Copy link
Copy Markdown

Summary

  • avoid deleting a sub-page when its document block is moved or rearranged
  • preserve pages whose view parent already changed during a sidebar move
  • only treat sub_page blocks as references, so other blocks sharing view_id do not suppress deletion
  • cover nested references and non-sub-page nodes with the same attribute

Closes #7588

Validation

  • flutter test --no-pub test/unit_test/document/sub_page_transaction_handler_test.dart — 1 test passed
  • flutter analyze --no-pub . — no issues found
  • Dart formatting and git diff --check pass

Validated with Flutter 3.27.4 on macOS arm64.

@sourcery-ai

sourcery-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Updates sub-page transaction handling to distinguish actual deletions from block moves and sidebar reparenting, preserving views that remain referenced or have already changed parents. Adds a unit test for recursive nested-reference detection.

Sequence diagram for preserving sub-pages during block removal

sequenceDiagram
    participant Editor as EditorState
    participant Handler as SubPageTransactionHandler
    participant Backend as ViewBackendService

    Editor->>Handler: _subPageDeleted(context, editorState, node, parentViewId)
    Handler->>Editor: documentContainsSubPageReference(root, viewId)
    alt another block references viewId
        Editor-->>Handler: true
        Handler-->>Editor: preserve view
    else no remaining reference
        Handler->>Backend: getView(viewId)
        Backend-->>Handler: view
        alt view.parentViewId != parentViewId
            Handler-->>Editor: preserve reparented view
        else same parent
            Handler->>Backend: deleteView(viewId: viewId)
            Backend-->>Handler: result
        end
    end
Loading

File-Level Changes

Change Details Files
Prevent deletion of pages that are still referenced or whose hierarchy changed during block moves.
  • Recursively scan the document tree for remaining sub-page references before deleting a page.
  • Pass the removed block’s original parent view ID into deletion handling.
  • Fetch the referenced view and delete it only when it still belongs to the removed block’s parent.
  • Skip deletion when the view is missing, has no ID, or has already been reparented.
frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/sub_page/sub_page_transaction_handler.dart
Add coverage for nested sub-page reference detection.
  • Verify references are found beneath nested nodes.
  • Verify unrelated view IDs are not reported as references.
frontend/appflowy_flutter/test/unit_test/document/sub_page_transaction_handler_test.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#7588 Prevent a page containing a document block from being deleted or moved to the trash when that block is moved through the sidebar or rearranged in the document.
#7588 Preserve the referenced page when another document block still references it, including references nested inside layouts such as columns.
#7588 Add regression coverage for detecting nested sub-page references.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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.

[Bug] Moving a page that has an existing document block will send it to the trash can instead

2 participants