Skip to content

send absolute path to frontend for file_browser#8668

Merged
Light2Dark merged 1 commit intomainfrom
sham/fix-path-passed-to-frontend
Mar 13, 2026
Merged

send absolute path to frontend for file_browser#8668
Light2Dark merged 1 commit intomainfrom
sham/fix-path-passed-to-frontend

Conversation

@Light2Dark
Copy link
Collaborator

@Light2Dark Light2Dark commented Mar 12, 2026

📝 Summary

Fixes #8665

In the backend, we passed the relative path to the frontend. We should instead send the normalized absolute path.

The un-normalized path would cause errors with the frontend's guessDeliminator, so passing "." would parse the delimiter as \\ even on Mac, when it should be /

before:
image

after:
image

🔍 Description of Changes

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Tests have been added for the changes made.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Pull request title is a good summary of the changes - it will be used in the release notes.

Copilot AI review requested due to automatic review settings March 12, 2026 18:18
@vercel
Copy link

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Mar 12, 2026 6:18pm

Request Review


# Frontend can't handle relative paths, so normalize it and make it absolute
# Use normalize_path to avoid symlink resolution
self._initial_path = self._create_path(normalize_path(initial_path))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

normalized here

@Light2Dark Light2Dark added the bug Something isn't working label Mar 12, 2026
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

Updates the file_browser UI element backend to always send a normalized absolute initial-path to the frontend, preventing frontend path delimiter mis-detection (Fixes #8665).

Changes:

  • Send self._initial_path (normalized/absolute) instead of the raw initial_path in the component args.
  • Add a regression test ensuring relative initial_path inputs are transmitted to the frontend as absolute paths and that navigating “up” works.
  • Minor formatting change to the restricted-navigation RuntimeError message.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
marimo/_plugins/ui/_impl/file_browser.py Uses the normalized absolute _initial_path when emitting initial-path to the frontend.
tests/_plugins/ui/_impl/test_file_browser.py Adds a test covering absolute-path transmission and parent navigation from the initial directory.

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

Comment on lines +971 to +978
assert "/" in initial_path_arg, (
f"initial-path sent to frontend must contain '/' "
f"(be absolute), got: {initial_path_arg!r}"
)
assert Path(initial_path_arg).is_absolute()

# Navigating up from the initial path should work
parent = str(Path(initial_path_arg).parent)
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

This test hard-codes '/' as the path separator ("assert '/' in initial_path_arg"). That will fail on Windows where absolute paths typically contain '\' (and may not contain '/'), even though the backend behavior is correct. Consider asserting that the value is absolute and/or equals the expected normalized path (e.g., Path(initial_path_arg) == sub_dir), or use os.sep for a separator check instead of '/'.

Suggested change
assert "/" in initial_path_arg, (
f"initial-path sent to frontend must contain '/' "
f"(be absolute), got: {initial_path_arg!r}"
)
assert Path(initial_path_arg).is_absolute()
# Navigating up from the initial path should work
parent = str(Path(initial_path_arg).parent)
initial_path = Path(initial_path_arg)
# The initial path sent to the frontend should be an absolute,
# normalized path pointing to the expected subdirectory.
assert initial_path.is_absolute()
assert initial_path == sub_dir
# Navigating up from the initial path should work
parent = str(initial_path.parent)

Copilot uses AI. Check for mistakes.
@mscolnick
Copy link
Contributor

im fixing this CI issue btw, elsehwere

@Light2Dark
Copy link
Collaborator Author

im fixing this CI issue btw, elsehwere

tq!

@Light2Dark Light2Dark merged commit af05ba0 into main Mar 13, 2026
36 of 53 checks passed
@Light2Dark Light2Dark deleted the sham/fix-path-passed-to-frontend branch March 13, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mo.ui.file_browser crashes when you try to go "up" the directory hierarchy

3 participants