🐛 fix(pdf): ensure worker config before Document render (#11746)

* 🐛 fix(pdf): ensure worker config before Document render

Fixes "No GlobalWorkerOptions.workerSrc specified" error in TurboPack by:
- Creating unified pdfjs module that ensures worker config at render time
- Wrapping Document component to call ensureWorker() before render
- Removing side-effect imports that may be optimized away by bundler

Closes LOBE-4108

* 📝 docs: clarify Linear issue management trigger conditions
This commit is contained in:
Innei
2026-01-23 22:19:03 +08:00
committed by GitHub
parent 1754455890
commit ad34072d9c
6 changed files with 40 additions and 22 deletions

View File

@@ -61,11 +61,19 @@ see @.cursor/rules/typescript.mdc
- **Dev**: Translate `locales/zh-CN/namespace.json` and `locales/en-US/namespace.json` locales file only for dev preview
- DON'T run `pnpm i18n`, let CI auto handle it
## Linear Issue Management (search tools first; ignore if not installed)
## Linear Issue Management
ClaudeCode may not inject MCP tools until they are discovered/used.\
Before applying Linear workflows, **use tool search** to confirm `linear-server` exists (e.g. search `linear` / `mcp__linear-server__`). If not found, treat it as not installed.\
Then read `@.cursor/rules/linear.mdc` when working with Linear issues.
**Trigger conditions** - when ANY of these occur, apply Linear workflow:
- User mentions issue ID like `LOBE-XXX`
- User says "linear", "link linear", "linear issue"
- Creating PR that references a Linear issue
**Workflow:**
1. Use `ToolSearch` to confirm `linear-server` MCP exists (search `linear` or `mcp__linear-server__`)
2. If found, read `.cursor/rules/linear.mdc` and follow the workflow
3. If not found, skip Linear integration (treat as not installed)
## Rules Index

View File

@@ -2,12 +2,11 @@
import { Flexbox } from '@lobehub/ui';
import { Fragment, memo, useCallback, useState } from 'react';
import { Document, Page, pdfjs } from 'react-pdf';
import 'react-pdf/dist/Page/AnnotationLayer.css';
import 'react-pdf/dist/Page/TextLayer.css';
import NeuralNetworkLoading from '@/components/NeuralNetworkLoading';
import '@/libs/pdfjs/worker';
import { Document, Page, pdfjs } from '@/libs/pdfjs';
import { lambdaQuery } from '@/libs/trpc/client';
import HighlightLayer from './HighlightLayer';
@@ -71,7 +70,7 @@ const PDFViewer = memo<PDFViewerProps>(({ url, fileId }) => {
onLoadSuccess={onDocumentLoadSuccess}
options={options}
>
{Array.from({ length: numPages }, (el, index) => {
{Array.from({ length: numPages }, (_, index) => {
const width = containerWidth ? Math.min(containerWidth, maxWidth) : maxWidth;
return (

View File

@@ -7,10 +7,9 @@ import { createStaticStyles, cx } from 'antd-style';
import { ChevronLeft, ChevronRight, Expand, FileText } from 'lucide-react';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Document, Page } from 'react-pdf';
import { useIsMobile } from '@/hooks/useIsMobile';
import '@/libs/pdfjs/worker';
import { Document, Page } from '@/libs/pdfjs';
import { containerStyles } from '../style';

25
src/libs/pdfjs/index.tsx Normal file
View File

@@ -0,0 +1,25 @@
'use client';
import type { ComponentProps } from 'react';
import { Document as PdfDocument, Page as PdfPage, pdfjs } from 'react-pdf';
const workerSrc = `https://registry.npmmirror.com/pdfjs-dist/${pdfjs.version}/files/build/pdf.worker.min.mjs`;
function ensureWorker() {
if (!pdfjs.GlobalWorkerOptions.workerSrc) {
pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
}
}
export type DocumentProps = ComponentProps<typeof PdfDocument>;
export type PageProps = ComponentProps<typeof PdfPage>;
export const Document = (props: DocumentProps) => {
ensureWorker();
return <PdfDocument {...props} />;
};
export {Page, pdfjs} from 'react-pdf';

View File

@@ -1 +0,0 @@
import 'pdfjs-dist/build/pdf.worker.min.mjs';

View File

@@ -1,12 +0,0 @@
'use client';
import { pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = `https://registry.npmmirror.com/pdfjs-dist/${pdfjs.version}/files/build/pdf.worker.min.mjs`;
// TODO: Re-enable module worker when fully on Turbopack.
// if (typeof Worker !== 'undefined' && !pdfjs.GlobalWorkerOptions.workerPort) {
// pdfjs.GlobalWorkerOptions.workerPort = new Worker(new URL('./pdf.worker.ts', import.meta.url), {
// type: 'module',
// });
// }