@@ -78,14 +78,8 @@ export const PdfViewerCore = memo(function PdfViewerCore({ source, filename }: P
7878 const [ loadError , setLoadError ] = useState < string | null > ( null )
7979
8080 const sourceValue = source . kind === 'url' ? source . url : source . buffer
81- const isEmptyBufferSource = source . kind === 'buffer' && source . buffer . byteLength === 0
8281 const file = useMemo (
83- ( ) =>
84- source . kind === 'url'
85- ? source . url
86- : source . buffer . byteLength > 0
87- ? { data : new Uint8Array ( source . buffer . slice ( 0 ) ) }
88- : null ,
82+ ( ) => ( source . kind === 'url' ? source . url : { data : new Uint8Array ( source . buffer . slice ( 0 ) ) } ) ,
8983 [ sourceValue ]
9084 )
9185
@@ -260,57 +254,55 @@ export const PdfViewerCore = memo(function PdfViewerCore({ source, filename }: P
260254 className = 'relative flex flex-1 items-start overflow-auto bg-[var(--surface-1)]'
261255 >
262256 { ! isDocumentReady && PDF_SKELETON }
263- { ! isEmptyBufferSource && file && (
264- < ReactPdfDocument
265- file = { file }
266- onLoadSuccess = { ( { numPages } ) => {
267- setPageCount ( numPages )
268- setCurrentPage ( 1 )
269- setLoadError ( null )
270- setIsDocumentReady ( true )
257+ < ReactPdfDocument
258+ file = { file }
259+ onLoadSuccess = { ( { numPages } ) => {
260+ setPageCount ( numPages )
261+ setCurrentPage ( 1 )
262+ setLoadError ( null )
263+ setIsDocumentReady ( true )
264+ } }
265+ onLoadError = { ( err ) => {
266+ logger . error ( 'PDF load failed' , { error : err . message } )
267+ setLoadError ( err . message )
268+ setIsDocumentReady ( true )
269+ } }
270+ error = { < PdfError error = { loadError ?? 'Failed to load PDF' } /> }
271+ className = 'mx-auto'
272+ >
273+ < div
274+ ref = { paddingWrapperRef }
275+ style = { {
276+ padding : PDF_VIEWER_PADDING ,
277+ minWidth :
278+ pageWidth !== undefined
279+ ? `${ pageWidth * displayZoom + 2 * PDF_VIEWER_PADDING } px`
280+ : undefined ,
271281 } }
272- onLoadError = { ( err ) => {
273- logger . error ( 'PDF load failed' , { error : err . message } )
274- setLoadError ( err . message )
275- setIsDocumentReady ( true )
276- } }
277- error = { < PdfError error = { loadError ?? 'Failed to load PDF' } /> }
278- className = 'mx-auto'
279282 >
280- < div
281- ref = { paddingWrapperRef }
282- style = { {
283- padding : PDF_VIEWER_PADDING ,
284- minWidth :
285- pageWidth !== undefined
286- ? `${ pageWidth * displayZoom + 2 * PDF_VIEWER_PADDING } px`
287- : undefined ,
288- } }
289- >
290- < div ref = { pagesWrapperRef } style = { { width : pageWidth } } >
291- { Array . from ( { length : pageCount } , ( _ , i ) => (
292- < div
293- key = { i }
294- ref = { ( el ) => {
295- pageRefs . current [ i ] = el
296- } }
297- data-page = { i + 1 }
298- className = 'mb-4 overflow-clip rounded-md shadow-medium'
299- >
300- < ReactPdfPage
301- pageNumber = { i + 1 }
302- width = { pageWidth }
303- className = '!overflow-clip [&_.textLayer]:!overflow-clip'
304- renderTextLayer
305- renderAnnotationLayer = { false }
306- aria-label = { `${ filename } page ${ i + 1 } ` }
307- />
308- </ div >
309- ) ) }
310- </ div >
283+ < div ref = { pagesWrapperRef } style = { { width : pageWidth } } >
284+ { Array . from ( { length : pageCount } , ( _ , i ) => (
285+ < div
286+ key = { i }
287+ ref = { ( el ) => {
288+ pageRefs . current [ i ] = el
289+ } }
290+ data-page = { i + 1 }
291+ className = 'mb-4 overflow-clip rounded-md shadow-medium'
292+ >
293+ < ReactPdfPage
294+ pageNumber = { i + 1 }
295+ width = { pageWidth }
296+ className = '!overflow-clip [&_.textLayer]:!overflow-clip'
297+ renderTextLayer
298+ renderAnnotationLayer = { false }
299+ aria-label = { `${ filename } page ${ i + 1 } ` }
300+ />
301+ </ div >
302+ ) ) }
311303 </ div >
312- </ ReactPdfDocument >
313- ) }
304+ </ div >
305+ </ ReactPdfDocument >
314306 </ div >
315307 </ div >
316308 )
0 commit comments