Skip to content

[BUG] Big txt file leads to frozen preview #3794

Open

Description

@jesmrec

Steps to reproduce

  1. Open a 2MB txt file (or greater)

Actual behaviour

Blank preview. Takes long to open and ANR happens

Expected behaviour

Preview loads faster, or set an spinner/waiter

Sample file:
sample-2mb-text-file.txt

device-2022-11-23-141001.mp4

Environment data

Android version: 12

Device model: Samsung A51

ownCloud app version: 2.21.2

ownCloud server version: 10.11

Activity

  1. added this to the 3.1 - Next milestone on Nov 23, 2022
  2. michaelstingl commented on Apr 13, 2023

    @michaelstingl
    Contributor

    Check if there are any libraries for this?

  3. modified the milestones: 4.1 - Next, on Apr 13, 2023
  4. removed this from the milestone on May 3, 2024
  5. modified the milestones: Backlog, 4.7 - Next on Jun 6, 2025
  6. modified the milestones: 4.7 - Current, Backlog on Oct 31, 2025
  7. DeepDiver1975 commented on Jun 29, 2026

    @DeepDiver1975
    Contributor

    Confirmed — still present on current main. The freeze is not the file read (that already runs off the UI thread); it's rendering the whole file into a single TextView on the main thread.

    In PreviewTextFragment.kt the TextLoadAsyncTask reads the entire file into one StringWriter/String with no size cap (doInBackground → String(result.buffer)), then on onPostExecute (UI thread) does textView.text = text. Measuring/laying out a multi-megabyte string in a single TextView (StaticLayout build) on the main thread is the ANR — a 2 MB file produces a 2 MB+ CharSequence for one view.

    For .md files it's worse: the same full string goes through markwon.setMarkdown(textView, text) in PreviewFormatTextFragmentStateAdapter.PreviewFormatTextFragment — synchronous Markdown parsing of the whole document on the UI thread, again uncapped.

    So the bug reproduces by design: background read OK, but the big-string layout/parse on the main thread blocks. A loading dialog now shows during the read, but it's dismissed right before the expensive UI-thread layout, so the freeze still surfaces.

    Fix directions (any of):

    • Cap preview size (read first N bytes/lines, append a "truncated, open with…" notice).
    • Render incrementally / use a paginated or RecyclerView-backed view instead of one TextView.
    • Move Markdown parsing off the main thread (markwon.toMarkdown(text) on a worker, then setParsedMarkdown on the UI thread) and cap input.

    Files: owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.kt, .../PreviewFormatTextFragmentStateAdapter.kt.

    🤖 Generated with Claude Code

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions