Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
components/PdfEditor.tsx
Outdated
| useEffect(()=>{ | ||
| let cancelled = false; | ||
| let task: any; | ||
| (async()=>{ | ||
| if (!file) return; | ||
| const ab = await file.arrayBuffer(); | ||
| const loadingTask = (pdfjsLib as any).getDocument({data: ab}); | ||
| setPdf(await loadingTask.promise); | ||
| setPage(1); | ||
| if (!file) { | ||
| setPdf(null); | ||
| setError(null); | ||
| return; | ||
| } | ||
| try { | ||
| setLoading(true); | ||
| setError(null); | ||
| const ab = await file.arrayBuffer(); | ||
| task = (pdfjsLib as any).getDocument({ | ||
| data: new Uint8Array(ab), | ||
| }); | ||
| const doc = await task.promise; | ||
| if (cancelled) { | ||
| await doc?.destroy?.(); | ||
| return; | ||
| } | ||
| setPdf(doc); | ||
| if (controlledPage === undefined) { | ||
| setPage(1); | ||
| } | ||
| onDocumentLoaded?.({ pages: doc.numPages || 1 }); | ||
| onPageChange?.(1); | ||
| } catch (err) { |
There was a problem hiding this comment.
Avoid reloading document when just changing pages
The new useEffect that loads the PDF is keyed to controlledPage and onPageChange. When the editor is used in controlled mode (as in EditorPage, which passes page={activePage}), every page navigation triggers this effect again even though the file didn’t change. Each rerun reloads the entire PDF, calls setPage(1) and onPageChange(1), and therefore snaps the preview back to the first page and forces another reload. The result is that users cannot stay on pages beyond 1 and the PDF is needlessly fetched on every page change. This effect should only depend on the file (and maybe stable callbacks), not on the current page value.
Useful? React with 👍 / 👎.
Summary
Testing
https://chatgpt.com/codex/tasks/task_b_68fd50605910832f878834bdbd162b36