Repository navigation
fix(pdf): render CJK text with pdf.js resources - #21625
Conversation
Co-authored-by: innocarpe <[email protected]>
|
This run was cancelled 🛑 The workflow was cancelled before completion. Please check the link below for details. |
📝 WalkthroughWalkthroughThe change adds a Vite plugin for PDF.js Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to Paired web clients served from a 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, the implementation, the validation, and links issue Resolution Update the description to include all required template sections. Add visual proof or write
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 720e1203-4ee6-49e3-85f9-239c8768f8f8
📒 Files selected for processing (8)
config/build-plugins/pdfjs-viewer-assets.tsconfig/scripts/project-renderer-web-client.mjselectron.vite.config.tssrc/main/runtime/rpc/static-web-client-handler.tssrc/renderer/src/components/editor/PdfViewer.tsxsrc/renderer/src/components/editor/pdf-js-document-options.test.tssrc/renderer/src/components/editor/pdf-js-document-options.tsvite.web.config.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| const assetIndex = pathname.indexOf(assetMarker) | ||
| if (assetIndex !== -1) { | ||
| const prefixIndex = STATIC_WEB_ALLOWED_PREFIXES.reduce( | ||
| (deepest, prefix) => Math.max(deepest, pathname.indexOf(prefix)), |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
rg -n -C 4 'mapProxyPrefixedStaticPathname|STATIC_WEB_ALLOWED_PREFIXES|static-web' src config --glob '!node_modules'
sed -n '1,180p' src/main/runtime/rpc/static-web-client-handler.tsRepository: stablyai/orca
Length of output: 9285
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- symbol and handler references ---'
rg -n -C 5 'mapProxyPrefixedStaticPathname|createStaticWebClientHandler|STATIC_WEB_ALLOWED_PREFIXES|/cmaps/|foo\.bcmap|standard_fonts|wasm/' src --glob '*.{ts,tsx,js,json}' --glob '!node_modules'
printf '%s\n' '--- relevant test files ---'
rg --files src | rg '(static-web|ws-transport-static-web|pdf|cmaps|standard_fonts|wasm)'
printf '%s\n' '--- transport setup around static handler ---'
sed -n '1,180p' src/main/runtime/rpc/ws-transport.tsRepository: stablyai/orca
Length of output: 17098
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- static web test outline and targeted content ---'
ast-grep outline src/main/runtime/rpc/ws-transport-static-web.test.ts
sed -n '1,280p' src/main/runtime/rpc/ws-transport-static-web.test.ts
printf '%s\n' '--- static root and PDF.js asset packaging references ---'
rg -n -C 4 'staticRoot|cmaps|standard_fonts|wasm|pdfjs|pdf\.worker|web-index\.html' src package.json config --glob '*.{ts,tsx,js,json,mjs,cjs,yml,yaml}' --glob '!node_modules'Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- PDF.js asset plugin ---'
sed -n '1,115p' config/build-plugins/pdfjs-viewer-assets.ts
printf '%s\n' '--- runtime lifecycle web-root wiring ---'
sed -n '145,190p' src/main/runtime/runtime-rpc/runtime-rpc-lifecycle.ts
printf '%s\n' '--- endpoint and web-client path construction ---'
sed -n '120,155p' src/main/runtime/runtime-rpc/runtime-rpc-pairing-types.ts
rg -n -C 5 'webClientPathForEndpoint|webClientUrl|proxy|pathname' src/main/runtime/runtime-rpc src/main/runtime --glob '*.{ts,tsx}' | head -n 180Repository: stablyai/orca
Length of output: 22407
🌐 Web query:
pdfjs-dist 6.3.289 cmaps directory nested files package contents
💡 Result:
<search_synthesis>
In the pdfjs-dist package (version 6.3.289), the cmaps directory does not contain any nested subdirectories [1][2]. It consists of a flat structure containing a collection of character map files, which are typically stored with the.bcmap file extension [1][3]. These files are used by the PDF.js library to map character codes to Unicode values [4][5]. As of this version, the directory contains over 160 individual files directly within the cmaps folder [1].
</search_synthesis>
<source_evidence>
Citations:
- 1: https://app.unpkg.com/[email protected]/files/cmaps
- 2: https://app.unpkg.com/[email protected]
- 3: https://github.com/mozilla/pdfjs-dist/tree/master/cmaps
- 4: https://mozilla.github.io/pdf.js/getting_started/
- 5: https://github.com/mozilla/pdf.js/blob/master/docs/contents/getting_started/index.md
Use the last occurrence of each allowed prefix.
When the proxy path is /cmaps, the web client requests PDF.js CMaps as /cmaps/cmaps/<file>.bcmap. indexOf() keeps the outer prefix, so the handler can look for staticRoot/cmaps/cmaps/<file>.bcmap instead of staticRoot/cmaps/<file>.bcmap and return 404.
- (deepest, prefix) => Math.max(deepest, pathname.indexOf(prefix)),
+ (deepest, prefix) => Math.max(deepest, pathname.lastIndexOf(prefix)),📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| (deepest, prefix) => Math.max(deepest, pathname.indexOf(prefix)), | |
| (deepest, prefix) => Math.max(deepest, pathname.lastIndexOf(prefix)), |

Problem
Japanese and other CJK PDFs can open with Latin text visible but CJK glyphs missing because pdf.js is initialized without its CMap resources. The same missing resource configuration affects standard fonts and WASM decoders.
Change
Pass CMap, standard-font, and WASM URLs to pdf.js and make the corresponding
pdfjs-distdirectories available in desktop builds, web builds, development, and the paired web runtime. The resources remain local and are loaded on demand.Validation
pnpm run build:webpasses and outputs all three resource directories.Fixes #21458.