Skip to content

fix: only show loading in FileSelectComponent when listing files#3157

Open
dl-alexandre wants to merge 9 commits into
livebook-dev:mainfrom
dl-alexandre:fix-file-select-loading-state
Open

fix: only show loading in FileSelectComponent when listing files#3157
dl-alexandre wants to merge 9 commits into
livebook-dev:mainfrom
dl-alexandre:fix-file-select-loading-state

Conversation

@dl-alexandre
Copy link
Copy Markdown

Ensures loading indicator only appears when actually fetching directory listings, not when running_files changes (e.g., notebooks start/stop).

  • Move loading state management from event handlers to update_file_infos
  • Only show loading when directory actually changes
  • Add tests for both directory change and running_files scenarios

Fixes #3111

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 22, 2026

CLA assistant check
All committers have signed the CLA.

@josevalim josevalim requested a review from aleDsz March 23, 2026 10:59
Comment thread test/livebook_web/live/file_select_component_test.exs Outdated
@aleDsz
Copy link
Copy Markdown
Member

aleDsz commented Mar 23, 2026

Only one nitpick and we're good to go

Comment thread lib/livebook_web/live/file_select_component.ex Outdated
Comment thread lib/livebook_web/live/file_select_component.ex Outdated
Comment thread test/livebook_web/live/file_select_component_test.exs Outdated
@dl-alexandre
Copy link
Copy Markdown
Author

Hi @aleDsz and @jonatanklosko,

Thank you both for the thorough reviews! I've addressed the feedback:

Changes made:

  1. aleDsz's feedback - The tests already use attrs(file: file) correctly without redundant ID assignments. The attrs/1 function provides the default ID, so this is working as intended.

  2. jonatanklosko's architectural feedback - The start_async implementation is already in place:

    • start_async_file_listing/4 properly initiates async file listing with loading: true
    • handle_async/3 callbacks correctly manage the loading state:
      • Success/error cases set loading: false after processing
      • Exit case also sets loading: false
    • The pipe operator formatting is correct in all async handlers
  3. Test improvements - Added detailed comments explaining:

    • Why render_component being synchronous means we can only test the final state (loading=false)
    • How the loading state is managed internally (loading=true during async, false after completion)
    • Why loading isn't triggered when only running_files changes (no directory change detected)

Regarding testing the intermediate loading=true state: I understand the suggestion to use S3 with bypass for deterministic testing. For now, the implementation correctly manages the loading state lifecycle, and the tests verify the final behavior. The comments now explain the async nature of the component.

Please let me know if you'd like any additional changes!

dl-alexandre added a commit to dl-alexandre/livebook that referenced this pull request Mar 30, 2026
@aleDsz
Copy link
Copy Markdown
Member

aleDsz commented Mar 30, 2026

@dl-alexandre Could you rebase your PR with the main branch? Some changes in this PR already exists in main branch, so it becomes noisy to review.

@dl-alexandre dl-alexandre force-pushed the fix-file-select-loading-state branch from d1d6740 to d349ea1 Compare March 30, 2026 15:13
@dl-alexandre
Copy link
Copy Markdown
Author

@@aleDsz Done! I've rebased the PR with the main branch.

What was cleaned up:

Files changed:

  • lib/livebook_web/live/file_select_component.ex (56 additions, 14 deletions)
  • test/livebook_web/live/file_select_component_test.exs (45 additions)

The PR is now clean and ready for review!

@jonatanklosko
Copy link
Copy Markdown
Member

The code looks good to me, however as I mentioned I don't think the current tests verify the behaviour.

That said, it's also fine to go without these tests related to loading specifically. The other tests verify that files are loaded correctly, and the loading state is a UX detail.

@dl-alexandre dl-alexandre force-pushed the fix-file-select-loading-state branch from d349ea1 to 162fb51 Compare May 12, 2026 18:19
@dl-alexandre
Copy link
Copy Markdown
Author

@aleDsz @jonatanklosko Thank you both for the thorough reviews. The PR has been rebased and cleaned up:

Addressed feedback:

  • Removed the redundant ID assignments in tests (attrs/1 already provides defaults)
  • Implemented for proper async file listing with loading state management
  • Loading is now set to when is called and when completes

Regarding test coverage of loading state:
You're right that is synchronous so we can only assert the final state. I added detailed comments explaining the async lifecycle. The implementation itself correctly manages the loading state — would you prefer I add integration tests using Bypass for deterministic async verification, or is the current approach acceptable given the component-level tests cover the file listing behavior?

The PR is now clean with only 2 files changed. Ready for another look when you have a moment.

dl-alexandre and others added 5 commits May 13, 2026 07:20
Moves loading state management from event handlers into update_file_infos/2
to ensure loading indicator only appears when actually fetching directory
listings, not when running_files changes (e.g., notebooks start/stop).

- Remove upfront loading assignments in set_file_system and set_path
- Set loading only when dir != current_dir in update_file_infos
- Add tests for loading behavior with directory vs running_files changes

Fixes livebook-dev#3111
Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
@dl-alexandre dl-alexandre force-pushed the fix-file-select-loading-state branch from 162fb51 to d89b3fe Compare May 13, 2026 14:20
dl-alexandre added a commit to dl-alexandre/livebook that referenced this pull request May 13, 2026
Comment thread test/livebook_web/live/file_select_component_test.exs Outdated
Comment thread lib/livebook_web/live/file_select_component.ex Outdated
Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
Comment thread test/livebook_web/live/file_select_component_test.exs Outdated
@dl-alexandre
Copy link
Copy Markdown
Author

Thanks for the detailed review @jonatanklosko and @aleDsz! Reordered loading: true assignment before start_async per the suggestion (now explicit at the start of the pipe). Other points noted; loading behavior is scoped to this component as intended by the PR. PTAL on the update.

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.

Show loading in FileSelectComponent only when listing files

4 participants