fix: go to previous page after current page delete by tiensonqin · Pull Request #13156 · logseq/logseq · GitHub
Skip to content

fix: go to previous page after current page delete - #13156

Open
tiensonqin wants to merge 1 commit into
masterfrom
logseq/fix-delete-page-nav-03ef
Open

fix: go to previous page after current page delete#13156
tiensonqin wants to merge 1 commit into
masterfrom
logseq/fix-delete-page-nav-03ef

Conversation

@tiensonqin

Copy link
Copy Markdown
Contributor

Description

Fixes db-test#1135.

After deleting the page (or focused block) you are viewing, Logseq now returns to the previously visited page/block in history instead of sending you home.

Deleting a page that is not the current route does not change navigation.

Behavior

  • Recycle or hard-delete of the current page/block → history.back() to the previous page/block.
  • No previous history entry → replace the current entry with home (does not create today's journal).
  • Delete of a non-current page → no navigation.
  • Mobile is left to its own stack. The mobile header delete handler already calls history.back; the pipeline does not also go back (avoids a double pop after Fix UI #1135: redirect to previous page instead of home on page delete #13153).

Tests

  • frontend.modules.outliner.pipeline-test covers current vs non-current recycle/hard-delete, focused-block delete, mobile skip, and graph-load (:initial-pages?).
  • frontend.handler.route-test covers history-back vs home fallback.

Notes

#13153 already replaced the hardcoded home redirect with history.back. This follow-up unifies that path, adds the empty-history fallback, stops mobile double-back on recycle, and adds tests. It does not change #1137 or #1139.

Open in Web Open in Cursor 

After deleting the current page or focused block, restore the previous
history entry instead of sending the user home. Fall back to replacing
the current entry with home only when there is no previous entry.
Skip this on mobile so the native stack is not double-popped.

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
Copilot AI lite review requested due to automatic review settings September 1, 2026 16:30

Copilot AI 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.

🟡 Changes recommended

The new route-handler tests mutate js/window.history directly, which is commonly non-writable and can make the test suite fail or become flaky.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the delete-page navigation behavior so that when the currently viewed page or focused block is deleted/recycled, Logseq returns to the previous route (via history back) rather than redirecting to home, with a fallback that replaces the current entry with home when no prior history exists; non-current deletions do not affect navigation, and mobile avoids double-pop behavior.

Changes:

  • Add route-handler/redirect-to-previous! with a no-history fallback to :home using :push false.
  • Update outliner pipeline delete/recycle hook handling to use redirect-to-previous! on desktop for current-route removals (skip on mobile; skip recycle during :initial-pages?).
  • Add targeted tests for pipeline navigation decisions and the route-handler history-back vs home fallback behavior.
File summaries
File Description
src/main/frontend/modules/outliner/pipeline.cljs Uses a single helper to leave the removed current route by delegating to route handler logic (desktop-only, with initial-load guard for recycle).
src/main/frontend/handler/route.cljs Introduces redirect-to-previous! that goes back when history exists and replaces with home when it does not.
src/test/frontend/modules/outliner/pipeline_test.cljs Adds coverage for current vs non-current delete/recycle, focused-block delete, mobile skip, and initial-pages guard.
src/test/frontend/handler/route_test.cljs Adds tests for redirect-to-previous! behavior; currently uses a history-stubbing approach that should be adjusted.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +22 to +29
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.

[UI] After deleting a page, dont return the user to home, instead take them to the previous visited page

3 participants