Skip to content

Conversation

@richard-to
Copy link
Collaborator

Implements feature request from issue #1287 to allow opening URLs in a new
browser tab. This enables users to navigate to detail pages while preserving
the state of the current page.

Changes:

  • Added open_in_new_tab boolean field to NavigateCommand proto
  • Updated navigate() function to accept open_in_new_tab parameter
  • Modified shell.ts to use window.open() when opening in new tab
  • Handles both absolute and relative URLs correctly
  • Preserves current page query params when opening in new tab
  • Added comprehensive example in navigate_new_tab.py
  • Added E2E tests for new tab navigation

Fixes #1287

claude and others added 3 commits December 24, 2025 23:55
Implements feature request from issue #1287 to allow opening URLs in a new
browser tab. This enables users to navigate to detail pages while preserving
the state of the current page.

Changes:
- Added open_in_new_tab boolean field to NavigateCommand proto
- Updated navigate() function to accept open_in_new_tab parameter
- Modified shell.ts to use window.open() when opening in new tab
- Handles both absolute and relative URLs correctly
- Preserves current page query params when opening in new tab
- Added comprehensive example in navigate_new_tab.py
- Added E2E tests for new tab navigation

Fixes #1287
Fixed critical bug where opening an internal app page in a new tab would
also navigate the current page to the same URL.

Root cause: The server was processing NavigateCommand for relative URLs by
changing the path variable and rendering the new page, then sending that UI
back to the current tab, causing unwanted navigation.

Changes:
- Server (server.py): Skip navigation logic when open_in_new_tab is true
  - Breaks out of navigate command processing to avoid path changes
  - Renders current page unchanged while frontend opens new tab
- Frontend (shell.ts): Added explicit return after window.open()
  - Prevents any potential fall-through or async issues

The fix ensures that when open_in_new_tab=True:
1. Frontend opens new tab with window.open() and returns immediately
2. Server skips all path changes and renders current page as-is
3. Current page remains unchanged while new tab loads independently

Fixes the issue reported in PR #1325
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a new feature allowing users to open URLs in a new browser tab via an open_in_new_tab parameter in the me.navigate() function. This addresses issue #1287 by enabling navigation to detail pages while preserving the current page state.

Key Changes:

  • Added open_in_new_tab boolean parameter to the navigate API throughout the stack
  • Implemented frontend logic to use window.open() for new tab navigation
  • Modified backend to skip server-side navigation when opening in new tabs
  • Added comprehensive E2E tests and example code

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
mesop/protos/ui.proto Added open_in_new_tab field to NavigateCommand proto message
mesop/commands/navigate.py Added open_in_new_tab parameter to navigate() function with documentation
mesop/runtime/context.py Updated context.navigate() to accept and pass through open_in_new_tab parameter
mesop/server/server.py Modified server logic to skip navigation when opening in new tab, letting frontend handle it
mesop/web/src/shell/shell.ts Implemented window.open() logic for new tab navigation with URL normalization
mesop/examples/navigate_new_tab.py Added comprehensive example demonstrating various new tab navigation scenarios
mesop/examples/init.py Imported new navigate_new_tab example module
mesop/tests/e2e/navigate_new_tab_test.ts Added E2E tests covering relative URLs, absolute URLs, query params, and same-tab navigation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@richard-to richard-to merged commit 180fbdd into main Dec 31, 2025
4 checks passed
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.

Add open_in_new_tab parameter to me.navigate

3 participants