Skip to content

fix(text-viewer): read the text file off the main thread - #6862

Merged
mahibi merged 4 commits into
nextcloud:masterfrom
ToteMeiSter:fix/provider-main-text-viewer
Oct 15, 2026
Merged

mahibi merged 4 commits into
nextcloud:masterfrom
ToteMeiSter:fix/provider-main-text-viewer

Conversation

@ToteMeiSter

Copy link
Copy Markdown
Contributor

The whole file was read in onCreate. Read it in produceState on Dispatchers.IO.

🤖 Generated with Claude Code

The whole file was read in onCreate. Read it in produceState on Dispatchers.IO.

Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
Assisted-by: Claude-Code:claude-sonnet-5-5
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1e4df238-6397-412f-b311-ea1dd6672366
📥 Commits

Reviewing files that changed from the base of the PR and between a17385e and cc40e42.

📒 Files selected for processing: 1
  • app/src/test/java/com/nextcloud/talk/fullscreenfile/FullScreenTextViewerActivityTest.kt

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The activity reads the text file asynchronously on Dispatchers.IO and exposes the result as Compose state. If reading fails or returns no text, the activity logs an error, shows a long error toast, and finishes. The screen shows a progress indicator while text is null. Once text is available, it displays Markdown or selectable plain text.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to cc40e

The viewer loads text off the main thread, shows loading until content is ready, and handles read failures by closing the viewer. No concrete merge-blocking behavior is identified.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description states the main implementation change and includes the AI disclosure, but it omits the required Screenshots, TODO, and Checklist sections and does not document testing or other checkli… Add the required template sections: Screenshots, TODO, and Checklist. Mark each applicable checklist item, including tests, capability, backport, milestone, and title review. Keep the implementation summary and AI disclosure.
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: moving text-file reading off the main thread.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description states the main implementation change and includes the AI disclosure, but it omits the required Screenshots, TODO, and Checklist sections and does not document testing or other checklist items.

  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 68f2891d-c70c-48ce-882b-99d5b60861ed
📥 Commits

Reviewing files that changed from the base of the PR and between 976034c and e1fd79b.

📒 Files selected for processing (1)
  • app/src/main/java/com/nextcloud/talk/fullscreenfile/FullScreenTextViewerActivity.kt

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

…d file is gone

The system may clear the cache directory between the exists() check and the
read. Catch IOException in the producer, tell the user and finish.

Assisted-by: Claude-Code:claude-sonnet-5-5
Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>

@rapterjet2004 rapterjet2004 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.

Thanks, moving the read off the main thread and handling a missing file instead of crashing are both good. Two things need to change before this can go in:

1. Markdown files now open blank. In FullScreenTextScreen, markdown is rendered in the AndroidView factory, which runs only once, on the first composition. With produceState, text is still "" at that point, and when the real text arrives the factory doesn't run again. Plain text is fine because Text(text) recomposes, but every .md file stays empty. Please move setMarkdown into update = { markwon.setMarkdown(it, text) } (with a remembered Markwon instance), or only compose the content once the text is loaded.

2. Please add a loading indicator. Until the read finishes, the screen is empty and looks exactly like an empty file, and the wait grows with file size. A String? state where null means loading, with a progress indicator until it's set, would cover this and also fixes point 1 if the content is only composed once the text is there.

Follow-up (not for this PR): for large files the freeze isn't gone yet, it moves from the read to the render:

  • The plain-text view is a single Text in verticalScroll, so the whole string is measured and laid out on the main thread at once, and Markwon also parses on the main thread. For a few MB that costs more than the read.
  • readBytes() loads the whole file into memory (and the String about twice that again). FileViewerUtils has no size cap for text files, so a very large file can run out of memory, and an OutOfMemoryError isn't caught by the IOException handler.

A size cap with "Open in Files" for anything bigger, or a lazy line-by-line list, would address both. Happy to see that as a separate issue or PR.

…loaded

The text state was a String initialised to "", so the screen looked like an
empty file while the read was running, and markdown was set once in the
AndroidView factory with that empty text and never updated.

Make the state a String? where null means loading: show a progress
indicator until it is set and compose the content only afterwards. Markdown
is applied in update with a remembered Markwon.

Assisted-by: Claude-Code:claude-sonnet-5-5
Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
@ToteMeiSter

Copy link
Copy Markdown
Contributor Author

Thanks, both points are fixed in a17385e. The state is now a String? where null means loading; a progress indicator is shown until it is set and the content is only composed after that, so markdown no longer renders from the initial empty string. Markdown is applied in update with a remembered Markwon. I added unit tests for the file read (missing / empty / UTF-8 file); the Compose rendering itself is not covered, since the unit-test source set has no Compose UI test dependency.

The follow-up on large files is now #6901.

… other Robolectric tests

Without @config the runner picks the target SDK (36) and has to download a
second android-all jar, which already failed with an SSLException on CI
for another class added the same way.

Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
Assisted-by: Claude-Code:claude-opus-5-5
@mahibi
mahibi merged commit 5a2fc92 into nextcloud:master Oct 15, 2026
16 of 19 checks passed
@AndyScherzinger AndyScherzinger added this to the 25.1.0 milestone Oct 15, 2026

@rapterjet2004 rapterjet2004 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.

Thanks, both points fixed: markdown is applied in update with a remembered Markwon, and the String? loading state with the progress indicator looks good. Thanks for filing #6901 for the large-file follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants