Skip to content

Commit ad34072

Browse files
authored
🐛 fix(pdf): ensure worker config before Document render (lobehub#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
1 parent 1754455 commit ad34072

File tree

6 files changed

+40
-22
lines changed

6 files changed

+40
-22
lines changed

CLAUDE.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,19 @@ see @.cursor/rules/typescript.mdc
6161
- **Dev**: Translate `locales/zh-CN/namespace.json` and `locales/en-US/namespace.json` locales file only for dev preview
6262
- DON'T run `pnpm i18n`, let CI auto handle it
6363

64-
## Linear Issue Management (search tools first; ignore if not installed)
64+
## Linear Issue Management
6565

66-
ClaudeCode may not inject MCP tools until they are discovered/used.\
67-
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.\
68-
Then read `@.cursor/rules/linear.mdc` when working with Linear issues.
66+
**Trigger conditions** - when ANY of these occur, apply Linear workflow:
67+
68+
- User mentions issue ID like `LOBE-XXX`
69+
- User says "linear", "link linear", "linear issue"
70+
- Creating PR that references a Linear issue
71+
72+
**Workflow:**
73+
74+
1. Use `ToolSearch` to confirm `linear-server` MCP exists (search `linear` or `mcp__linear-server__`)
75+
2. If found, read `.cursor/rules/linear.mdc` and follow the workflow
76+
3. If not found, skip Linear integration (treat as not installed)
6977

7078
## Rules Index
7179

src/features/FileViewer/Renderer/PDF/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import { Flexbox } from '@lobehub/ui';
44
import { Fragment, memo, useCallback, useState } from 'react';
5-
import { Document, Page, pdfjs } from 'react-pdf';
65
import 'react-pdf/dist/Page/AnnotationLayer.css';
76
import 'react-pdf/dist/Page/TextLayer.css';
87

98
import NeuralNetworkLoading from '@/components/NeuralNetworkLoading';
10-
import '@/libs/pdfjs/worker';
9+
import { Document, Page, pdfjs } from '@/libs/pdfjs';
1110
import { lambdaQuery } from '@/libs/trpc/client';
1211

1312
import HighlightLayer from './HighlightLayer';
@@ -71,7 +70,7 @@ const PDFViewer = memo<PDFViewerProps>(({ url, fileId }) => {
7170
onLoadSuccess={onDocumentLoadSuccess}
7271
options={options}
7372
>
74-
{Array.from({ length: numPages }, (el, index) => {
73+
{Array.from({ length: numPages }, (_, index) => {
7574
const width = containerWidth ? Math.min(containerWidth, maxWidth) : maxWidth;
7675

7776
return (

src/features/ShareModal/SharePdf/PdfPreview.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import { createStaticStyles, cx } from 'antd-style';
77
import { ChevronLeft, ChevronRight, Expand, FileText } from 'lucide-react';
88
import { memo, useState } from 'react';
99
import { useTranslation } from 'react-i18next';
10-
import { Document, Page } from 'react-pdf';
1110

1211
import { useIsMobile } from '@/hooks/useIsMobile';
13-
import '@/libs/pdfjs/worker';
12+
import { Document, Page } from '@/libs/pdfjs';
1413

1514
import { containerStyles } from '../style';
1615

src/libs/pdfjs/index.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use client';
2+
3+
import type { ComponentProps } from 'react';
4+
import { Document as PdfDocument, Page as PdfPage, pdfjs } from 'react-pdf';
5+
6+
const workerSrc = `https://registry.npmmirror.com/pdfjs-dist/${pdfjs.version}/files/build/pdf.worker.min.mjs`;
7+
8+
function ensureWorker() {
9+
if (!pdfjs.GlobalWorkerOptions.workerSrc) {
10+
pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
11+
}
12+
}
13+
14+
export type DocumentProps = ComponentProps<typeof PdfDocument>;
15+
export type PageProps = ComponentProps<typeof PdfPage>;
16+
17+
export const Document = (props: DocumentProps) => {
18+
ensureWorker();
19+
return <PdfDocument {...props} />;
20+
};
21+
22+
23+
24+
25+
export {Page, pdfjs} from 'react-pdf';

src/libs/pdfjs/pdf.worker.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/libs/pdfjs/worker.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)