Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 27, 2025

Problem

PDF documents were getting stuck showing "0% loaded" indefinitely instead of displaying error messages when they failed to load. This issue was particularly affecting Android users, where error messages were being ignored rather than shown to users, leaving them wondering if the app was broken.

Root Cause

The PdfScreen component only set the PDF source URI but didn't implement any error handling callbacks provided by the react-native-pdf library. When PDF loading failed (due to network issues, invalid URLs, or server errors), the component would remain in an indefinite loading state without user feedback.

Solution

Added comprehensive error handling and loading state management to the PDF viewer:

Error Handling:

  • Implemented onError callback to capture PDF loading failures
  • Display meaningful error messages with fallback to German default text
  • Show the problematic URL for debugging purposes
  • Added retry functionality with "Erneut versuchen" button

Loading Progress:

  • Added onLoadProgress callback to show actual loading percentages (0-100%)
  • Replaced indefinite 0% loading with real progress indicators
  • Clear loading UI with spinner and progress text: "Lädt PDF... 45%"

State Management:

  • Introduced PdfState interface to track loading, error, progress, and success states
  • Proper state transitions between loading → success/error states
  • Reset functionality for retry attempts

User Experience Improvements

Before:

PDF viewer shows: "0% loaded" (forever)
User sees: Nothing, assumes app is broken

After:

Loading: "Lädt PDF... 78%" with spinner
Success: PDF displays normally  
Error: "Network error" + URL + retry button

Technical Details

The implementation follows existing app patterns:

  • Uses styled-components consistent with the codebase
  • Follows German localization standards
  • Maintains TypeScript strict mode compliance
  • Leverages existing UI components (Button, ActivityIndicator)
  • Logs errors to console for developer debugging

Testing

  • ✅ ESLint and TypeScript checks pass
  • ✅ iOS prebuild successful
  • ✅ Metro bundler compiles correctly
  • ✅ Follows existing component architecture patterns

This fix addresses the core issue where PDF loading errors were silently ignored, providing users with clear feedback and retry options when documents fail to load.

Original prompt

This section details on the original issue you should resolve

<issue_title>PDF Dokumente werden nicht dargestellt</issue_title>
<issue_description>Wenn man einen Eintrag betrachtet, "Dokumente" ausklappt und eines antippt, wird lediglich angezeigt, dass er zu 0% fertig ist. Und das bleibt auch mindestens 5 Minuten lang so.
Es sieht so aus, als ob hier eine Fehlermeldung ignoriert werden würde. Sie sollte aber vielmehr dargestellt werden. </issue_description>

<agent_instructions>Es scheint überwiegend auf android geraten zu passieren.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #1638

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add loading state with progress indicator
- Implement onError handler to capture PDF loading failures
- Add error UI with retry functionality and error details
- Show actual loading progress instead of indefinite 0%
- Properly handle error objects and display meaningful messages
- Include URL in error display for debugging purposes

Co-authored-by: ManAnRuck <[email protected]>
Copilot AI changed the title [WIP] PDF Dokumente werden nicht dargestellt Fix PDF document loading stuck at 0% by adding proper error handling Sep 27, 2025
Copilot AI requested a review from ManAnRuck September 27, 2025 17:41
Copilot finished work on behalf of ManAnRuck September 27, 2025 17:41
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.

PDF Dokumente werden nicht dargestellt

2 participants