You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Sentry: APP-A2K] HybridApp iOS Fatal App Hang in bcmap_addDelta during PDF rendering #97099
PDF CMap/font decoding (bcmap_addDelta) is blocking the main thread during receipt or PDF display on HybridApp iOS. APP-A2K and APP-85A are siblings with the same hang site; Sentry splits fully-blocked vs non-fully-blocked variants.
Reproduction
Unknown — see Sentry events linked above. Likely triggered when opening or rendering a PDF receipt attachment.
The hang is Apple PDFKit decoding an embedded PDF font/CMap synchronously on the main thread, not App JS code.
On iOS every PDF (full‑screen viewer and thumbnails) renders through react-native-pdf@7.0.2, which uses usePDFKit: true → the native Fabric view RNPDFPdfView (Apple PDFDocument/PDFView). When the path prop is applied, Fabric flushes it on the main queue (RCTMountingManager synchronouslyDispatchCommandOnUIThread → _dispatch_main_queue_drain), and RNPDFPdfView.didSetProps: synchronously does [[PDFDocument alloc] initWithURL:] → _pdfView.document = … → layoutDocumentView. PDFKit then parses the doc and decodes its fonts/CMaps on that same thread — the bcmap_addDelta / FSTerminate frames. bcmap_addDelta is CMap/CID decode, so the hang concentrates on receipts with non‑Latin / CID (e.g. CJK) or heavily‑subset embedded fonts.
The App‑controllable amplifier: PDFThumbnail/index.native.tsx spins up a full PDFKit instance per thumbnail (not a lightweight raster), and thumbnails are mounted in lists/carousels (e.g. ReportActionItemImage.tsx, AttachmentPreview, ReceiptImage), so several synchronous font decodes can stack on the main thread at once.
Investigation details (high confidence — code path traced end to end)
Render path on iOS: AttachmentViewPdf/index.ios.tsx → BaseAttachmentViewPdf → PDFView/index.native.tsx:189-206 → react-native-pdf <PDF>. pdfjs-dist/react-fast-pdf is web‑only (PDFView/index.tsx), never hit on native.
Synchronous decode site: node_modules/react-native-pdf/ios/RNPDFPdf/RNPDFPdfView.mmdidSetProps: (PDFDocument initWithURL, _pdfView.document =, layoutDocumentView). This is upstream/Apple code — no App permalink.
The App never calls the one imperative command (setNativePage) and never sets page, so the trigger is the initial path prop apply (document open + font decode), not paging.
The 4 existing App/patches/react-native-pdf/*.patch are all Android‑only; nothing touches the iOS main‑thread decode.
Alternative explanations considered & ruled out: (a) a specific App synchronous command — ruled out, App issues no PDF commands; (b) the JS pdfjs path — ruled out, web‑only; (c) network on main thread — ruled out, JS downloads/caches the file before setting path. The remaining variable that fits bcmap_addDelta is embedded font/CMap decode inside PDFKit.
What changes do you think we should make in order to solve the problem?
The actual bcmap_addDelta font decode is inside Apple PDFKit and cannot be run in App JS — so this is mitigation, not elimination. In rough order of impact:
Cap/virtualize concurrent PDFThumbnail rendering. Only mount a PDFKit instance for on‑screen thumbnails and/or a small concurrency limit, using the component's existing enabled/visibility props, so multiple decodes don't stack on the main thread in receipt/attachment lists. This is the biggest App‑side lever.
Defer/lazy‑mount the <PDF> viewer until the item is actually focused/visible.
Add an iOS patch (or upgrade react-native-pdf past 7.0.2) that opens PDFDocument on a background dispatch queue and assigns _pdfView.document back on main. This is the only way to move the decode off the main thread; it requires a native patch since the current 4 patches are Android‑only.
What alternative solutions did you explore? (Optional)
Rendering thumbnails as pre‑generated raster images (server‑side or a one‑time off‑main decode) instead of a live PDFKit instance per thumbnail would remove repeated font decode entirely in list contexts.
Recommend pulling Sentry data before committing to a fix (via the sentry skill): group APP‑A2K / APP‑85A by screen and device to confirm the concurrent‑thumbnail amplification, and sample the affected receipts to confirm the non‑Latin/CID‑font hypothesis. That decides whether (1) alone is enough or whether the native patch (3) is required.
Next Steps for Contributor+ team: To accept:@MelvinBot implement this to create a draft PR. To refine:@MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.
The crash is a main-thread AppHang (≥2000ms watchdog), and the reliable frame in the trace is -[RCTMountingManager synchronouslyDispatchCommandOnUIThread:...] → PDFKit → bcmap_addDelta. bcmap_addDelta is CoreGraphics decoding an embedded CID/CMap font program while it rasterizes a PDF page. That decode is running on the main thread.
On iOS, react-native-pdf renders every PDF — including receipt previews — into a live, on-screen PDFView (PDFKit). When the path prop is committed on the UI thread, its native RNPDFPdfView.didSetProps assigns the document to that live view (_pdfView.document = _pdfDocument) and forces layout (layoutDocumentView + setNeedsDisplay). PDFKit then draws the visible page on the main thread, and for a receipt whose text uses an embedded CID-keyed font it must build that font's CMap (bcmap_addDelta) before it can lay out a single glyph. For a font-heavy receipt this one draw pass exceeds 2000ms and the OS kills the app. PDFKit exposes no API to draw a live PDFView off the main thread, so react-native-pdf's iOS path has no way to avoid blocking the UI thread here.
Two things make this concrete and iOS-specific:
Sibling contrast (why Android stays silent):react-native-pdf's Android view decodes and rasterizes pages on a background DecodingAsyncTask thread (the same worker the existing Android patches in patches/react-native-pdf/ interact with), so the identical PDF never blocks the Android UI thread. Only the iOS live-PDFView path rasterizes fonts on the main thread — matching "Platform: iOS HybridApp" in the report.
The codebase already treats a live PDF view as too expensive to mount freely. The attachment carousel mounts the full viewer for only the focused item and renders a placeholder for the rest:
// Every mounted PDF viewer is a full PDF.js document parse (its own worker + parsed document), so in a
// carousel the memory cost scales with the number of PDF attachments — enough to OOM the WebContent
// process on iOS Safari and reload the tab when several PDFs are added at once. Only mount the viewer
// for the item the carousel currently focuses; off-screen items render a lightweight placeholder until
// they're swiped to. isFocused is undefined outside the carousel (single-attachment hosts), which must
// keep mounting immediately.
if(isFocused===false){
return(
<DefaultAttachmentView
fileName={file?.name}
shouldShowLoadingSpinnerIcon
containerStyles={containerStyles}
/>
);
}
The receipt thumbnail surface has no equivalent gate. Local PDF receipts render a live <Pdf singlePage> — PDFThumbnail/index.native.tsx — chosen only for local files (ReportActionItemImage.tsx:202; remote receipts use a server-generated JPG and never touch native PDFKit). These thumbnails are userInteractionEnabled = NO, kPDFDisplaySinglePage static previews, yet each one still runs a full main-thread PDFKit rasterization, and several can mount at once from ReportActionItemImages.tsx:84.
So the root cause is: the non-interactive receipt-thumbnail surface rasterizes embedded CID/CMap fonts through a live PDFKit PDFView on the main thread, and PDFKit cannot do that off-main — exactly the work the Android sibling does on a background thread.
What changes do you think we should make in order to solve the problem?
For the thumbnail surface — where the PDF is static, non-interactive, and displayed at a fixed small size — we should stop rendering a live PDFView and instead rasterize page 1 to a UIImage on a background queue, then display that image, moving the bcmap font decode off the main thread. PDFKit supports this directly: -[PDFPage thumbnailOfSize:forBox:] operates on the PDFPage/PDFDocument model (not a UIView) and is safe to call off the main thread; only the final image assignment hops back to main.
The convergence point is react-native-pdf's ios/RNPDFPdf/RNPDFPdfView.mm, which the app already patches via patches/react-native-pdf/. In the singlePage branch of didSetProps (currently just _pdfView.displayMode = kPDFDisplaySinglePage; _pdfView.userInteractionEnabled = NO;), render the page off-main instead of driving the live view:
// _singlePage == static, non-interactive preview: render off the main thread.PDFPage *page = [_pdfDocument pageAtIndex:0];
CGSize size = self.bounds.size;
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
UIImage *img = [page thumbnailOfSize:size forBox:kPDFDisplayBoxCropBox]; // bcmap decode happens HERE, off-maindispatch_async(dispatch_get_main_queue(), ^{
self->_thumbnailView.image = img; // only the assignment is on main
[selfnotifyOnChangeWithMessage:@"loadComplete|1"]; // preserve the onLoadComplete contract
});
});
The interactive multi-page viewer (!_singlePage, PDFView/index.native.tsx) keeps live PDFView rendering so scroll/zoom/link-tap still work, and that path is already bounded to one instance by the carousel focus gate above.
This is safe because:
singlePage thumbnails already disable interaction (userInteractionEnabled = NO) and use kPDFDisplaySinglePage, so a rasterized UIImage is visually equivalent — no gesture, zoom, or link behavior is lost on the thumbnail surface.
-[PDFPage thumbnailOfSize:forBox:] reads the model object; the only UIKit touch (UIImageView.image =) is dispatched back to the main queue, so it respects UIKit's main-thread requirement.
The interactive !_singlePage path is untouched, so the full-screen viewer's scroll/zoom/onPressLink (and the existing Android onPressLink/already-closed patches) are unaffected.
The loadComplete/error messages are still emitted, so PDFThumbnail's onLoadSuccess/onLoadError — and the sequential mount gate in useFilesValidation that depends on them — keep working unchanged.
Note: the full-screen viewer still draws on the main thread, but it is a deliberate single-instance action already gated to the focused carousel item, whereas the thumbnail is the passive, high-frequency, multi-instance surface (it re-renders as users scroll chats/reports containing local PDF receipts). Moving the thumbnail off-main removes the widespread, compounding source of the hang; deferring the viewer's mount out of the modal-open transition can follow as a smaller change if the viewer path shows up in the Sentry route breakdown.
What alternative solutions did you explore? (Optional)
Offload only the PDFDocument construction (initWithURL:/initWithData:) to a background queue. Insufficient: the watchdog fires on the draw tick, not on document parsing. bcmap_addDelta is font rasterization that PDFKit performs when the live PDFView draws (scheduled via setNeedsDisplay), so moving construction off-main leaves the blocking draw on the main thread.
Set enableAntialiasing={false} on the thumbnails. Only trims per-glyph cost and regresses text sharpness; the CID/CMap decode still runs on the main thread, so a font-heavy receipt can still trip the 2000ms watchdog.
Defer the thumbnail mount with InteractionManager.runAfterInteractions. This only reschedules the same main-thread draw to a later tick; a single ≥2000ms font decode still trips the watchdog wherever it runs, and multiple thumbnails flipped after interactions still commit and draw together.
I'm debugging the issue and trying to reproduce it - no luck with repro steps for now.
My main suspect is FullStory that is present in all those issues
The revert PR was merged and CPed to staging, so I think we should wait a bit and monitor the Sentry issue. Once we confirm it's fixed, we can investigate further and try to find the real cause in FS
Activity
melvin-bot commentedon Jul 27, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @brunovjk (
External)melvin-bot commentedon Jul 27, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022081739643032819703
MelvinBot commentedon Jul 27, 2026
Proposal
What is the root cause of that problem?
The hang is Apple PDFKit decoding an embedded PDF font/CMap synchronously on the main thread, not App JS code.
On iOS every PDF (full‑screen viewer and thumbnails) renders through
react-native-pdf@7.0.2, which usesusePDFKit: true→ the native Fabric viewRNPDFPdfView(ApplePDFDocument/PDFView). When thepathprop is applied, Fabric flushes it on the main queue (RCTMountingManager synchronouslyDispatchCommandOnUIThread→_dispatch_main_queue_drain), andRNPDFPdfView.didSetProps:synchronously does[[PDFDocument alloc] initWithURL:]→_pdfView.document = …→layoutDocumentView. PDFKit then parses the doc and decodes its fonts/CMaps on that same thread — thebcmap_addDelta/FSTerminateframes.bcmap_addDeltais CMap/CID decode, so the hang concentrates on receipts with non‑Latin / CID (e.g. CJK) or heavily‑subset embedded fonts.The App‑controllable amplifier:
PDFThumbnail/index.native.tsxspins up a full PDFKit instance per thumbnail (not a lightweight raster), and thumbnails are mounted in lists/carousels (e.g.ReportActionItemImage.tsx,AttachmentPreview,ReceiptImage), so several synchronous font decodes can stack on the main thread at once.Investigation details (high confidence — code path traced end to end)
Render path on iOS:
AttachmentViewPdf/index.ios.tsx→BaseAttachmentViewPdf→PDFView/index.native.tsx:189-206→react-native-pdf <PDF>.pdfjs-dist/react-fast-pdfis web‑only (PDFView/index.tsx), never hit on native.usePDFKitdefaults totrue(node_modules/react-native-pdf/index.js:94) → iOS always uses PDFKitRNPDFPdfView.node_modules/react-native-pdf/ios/RNPDFPdf/RNPDFPdfView.mmdidSetProps:(PDFDocument initWithURL,_pdfView.document =,layoutDocumentView). This is upstream/Apple code — no App permalink.setNativePage) and never setspage, so the trigger is the initialpathprop apply (document open + font decode), not paging.App/patches/react-native-pdf/*.patchare all Android‑only; nothing touches the iOS main‑thread decode.Alternative explanations considered & ruled out: (a) a specific App synchronous command — ruled out, App issues no PDF commands; (b) the JS pdfjs path — ruled out, web‑only; (c) network on main thread — ruled out, JS downloads/caches the file before setting
path. The remaining variable that fitsbcmap_addDeltais embedded font/CMap decode inside PDFKit.What changes do you think we should make in order to solve the problem?
The actual
bcmap_addDeltafont decode is inside Apple PDFKit and cannot be run in App JS — so this is mitigation, not elimination. In rough order of impact:PDFThumbnailrendering. Only mount a PDFKit instance for on‑screen thumbnails and/or a small concurrency limit, using the component's existingenabled/visibility props, so multiple decodes don't stack on the main thread in receipt/attachment lists. This is the biggest App‑side lever.<PDF>viewer until the item is actually focused/visible.react-native-pdfpast 7.0.2) that opensPDFDocumenton a background dispatch queue and assigns_pdfView.documentback on main. This is the only way to move the decode off the main thread; it requires a native patch since the current 4 patches are Android‑only.What alternative solutions did you explore? (Optional)
Rendering thumbnails as pre‑generated raster images (server‑side or a one‑time off‑main decode) instead of a live PDFKit instance per thumbnail would remove repeated font decode entirely in list contexts.
Next Steps for Contributor+ team:
To accept:
@MelvinBot implement thisto create a draft PR.To refine:
@MelvinBot <your feedback>To reject: Explain why you are rejecting Melvin's proposal.
yusufdeveloper2903 commentedon Jul 27, 2026
Proposal
What is the root cause of that problem?
The crash is a main-thread
AppHang(≥2000ms watchdog), and the reliable frame in the trace is-[RCTMountingManager synchronouslyDispatchCommandOnUIThread:...]→ PDFKit →bcmap_addDelta.bcmap_addDeltais CoreGraphics decoding an embedded CID/CMap font program while it rasterizes a PDF page. That decode is running on the main thread.On iOS,
react-native-pdfrenders every PDF — including receipt previews — into a live, on-screenPDFView(PDFKit). When thepathprop is committed on the UI thread, its nativeRNPDFPdfView.didSetPropsassigns the document to that live view (_pdfView.document = _pdfDocument) and forces layout (layoutDocumentView+setNeedsDisplay). PDFKit then draws the visible page on the main thread, and for a receipt whose text uses an embedded CID-keyed font it must build that font's CMap (bcmap_addDelta) before it can lay out a single glyph. For a font-heavy receipt this one draw pass exceeds 2000ms and the OS kills the app. PDFKit exposes no API to draw a livePDFViewoff the main thread, so react-native-pdf's iOS path has no way to avoid blocking the UI thread here.Two things make this concrete and iOS-specific:
Sibling contrast (why Android stays silent):
react-native-pdf's Android view decodes and rasterizes pages on a backgroundDecodingAsyncTaskthread (the same worker the existing Android patches inpatches/react-native-pdf/interact with), so the identical PDF never blocks the Android UI thread. Only the iOS live-PDFViewpath rasterizes fonts on the main thread — matching "Platform: iOS HybridApp" in the report.The codebase already treats a live PDF view as too expensive to mount freely. The attachment carousel mounts the full viewer for only the focused item and renders a placeholder for the rest:
App/src/components/Attachments/AttachmentView/index.tsx
Lines 262 to 277 in 557846e
The receipt thumbnail surface has no equivalent gate. Local PDF receipts render a live
<Pdf singlePage>—PDFThumbnail/index.native.tsx— chosen only for local files (ReportActionItemImage.tsx:202; remote receipts use a server-generated JPG and never touch native PDFKit). These thumbnails areuserInteractionEnabled = NO,kPDFDisplaySinglePagestatic previews, yet each one still runs a full main-thread PDFKit rasterization, and several can mount at once fromReportActionItemImages.tsx:84.So the root cause is: the non-interactive receipt-thumbnail surface rasterizes embedded CID/CMap fonts through a live PDFKit
PDFViewon the main thread, and PDFKit cannot do that off-main — exactly the work the Android sibling does on a background thread.What changes do you think we should make in order to solve the problem?
For the thumbnail surface — where the PDF is static, non-interactive, and displayed at a fixed small size — we should stop rendering a live
PDFViewand instead rasterize page 1 to aUIImageon a background queue, then display that image, moving thebcmapfont decode off the main thread. PDFKit supports this directly:-[PDFPage thumbnailOfSize:forBox:]operates on thePDFPage/PDFDocumentmodel (not aUIView) and is safe to call off the main thread; only the final image assignment hops back to main.The convergence point is
react-native-pdf'sios/RNPDFPdf/RNPDFPdfView.mm, which the app already patches viapatches/react-native-pdf/. In thesinglePagebranch ofdidSetProps(currently just_pdfView.displayMode = kPDFDisplaySinglePage; _pdfView.userInteractionEnabled = NO;), render the page off-main instead of driving the live view:The interactive multi-page viewer (
!_singlePage,PDFView/index.native.tsx) keeps livePDFViewrendering so scroll/zoom/link-tap still work, and that path is already bounded to one instance by the carousel focus gate above.This is safe because:
singlePagethumbnails already disable interaction (userInteractionEnabled = NO) and usekPDFDisplaySinglePage, so a rasterizedUIImageis visually equivalent — no gesture, zoom, or link behavior is lost on the thumbnail surface.-[PDFPage thumbnailOfSize:forBox:]reads the model object; the only UIKit touch (UIImageView.image =) is dispatched back to the main queue, so it respects UIKit's main-thread requirement.!_singlePagepath is untouched, so the full-screen viewer's scroll/zoom/onPressLink(and the existing AndroidonPressLink/already-closed patches) are unaffected.loadComplete/errormessages are still emitted, soPDFThumbnail'sonLoadSuccess/onLoadError— and the sequential mount gate inuseFilesValidationthat depends on them — keep working unchanged.Note: the full-screen viewer still draws on the main thread, but it is a deliberate single-instance action already gated to the focused carousel item, whereas the thumbnail is the passive, high-frequency, multi-instance surface (it re-renders as users scroll chats/reports containing local PDF receipts). Moving the thumbnail off-main removes the widespread, compounding source of the hang; deferring the viewer's mount out of the modal-open transition can follow as a smaller change if the viewer path shows up in the Sentry route breakdown.
What alternative solutions did you explore? (Optional)
PDFDocumentconstruction (initWithURL:/initWithData:) to a background queue. Insufficient: the watchdog fires on the draw tick, not on document parsing.bcmap_addDeltais font rasterization that PDFKit performs when the livePDFViewdraws (scheduled viasetNeedsDisplay), so moving construction off-main leaves the blocking draw on the main thread.enableAntialiasing={false}on the thumbnails. Only trims per-glyph cost and regresses text sharpness; the CID/CMap decode still runs on the main thread, so a font-heavy receipt can still trip the 2000ms watchdog.InteractionManager.runAfterInteractions. This only reschedules the same main-thread draw to a later tick; a single ≥2000ms font decode still trips the watchdog wherever it runs, and multiple thumbnails flipped after interactions still commit and draw together.war-in commentedon Jul 27, 2026
I'm debugging the issue and trying to reproduce it - no luck with repro steps for now.
My main suspect is FullStory that is present in all those issues
When app is under heavy load (e.g. rendering markdown in composer) it also have to perform some FS-related work (e.g.
set_fsClass) on the main thread.It looks like all issues started happening after RN upgrade in march (0.81 -> 0.83) but intensified a few days ago after upgrading FullStory (PR).
I'll keep you posted about my findings and potential fixes
brunovjk commentedon Jul 27, 2026
Thanks @war-in! Please let me know if I can help with anything.
war-in commentedon Jul 28, 2026
The revert PR was merged and CPed to staging, so I think we should wait a bit and monitor the Sentry issue. Once we confirm it's fixed, we can investigate further and try to find the real cause in FS
3 remaining items
mountiny commentedon Jul 31, 2026
Monitoring
melvin-bot commentedon Aug 3, 2026
@brunovjk Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
brunovjk commentedon Aug 4, 2026
Not overdue
mountiny commentedon Aug 6, 2026
I dont see this for the version above the revert
so I would say the revert actually fixed it
melvin-bot commentedon Aug 7, 2026
@brunovjk Whoops! This issue is 2 days overdue. Let's get this updated quick!
mountiny commentedon Aug 9, 2026
We can close this now, the original author is aware and looking into preventing this crash