Skip to content

Fix pdf.js worker regression in editor preview#14

Open
Junio243 wants to merge 1 commit intomainfrom
codex/fix-bugs-in-signature-editor-euy20b
Open

Fix pdf.js worker regression in editor preview#14
Junio243 wants to merge 1 commit intomainfrom
codex/fix-bugs-in-signature-editor-euy20b

Conversation

@Junio243
Copy link
Owner

Summary

  • configure pdf.js to use the bundled worker again so uploaded PDFs render in the editor preview
  • read files as Uint8Array before loading and keep loading/error handling while cancelling pending tasks
  • show the selected PDF name and reset the input so the same file can be re-uploaded if needed

Testing

  • npm run lint (fails: Failed to load config "next/core-web-vitals" to extend from.)

https://chatgpt.com/codex/tasks/task_b_68fd50605910832f878834bdbd162b36

@vercel
Copy link
Contributor

vercel bot commented Oct 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
signflow Error Error Oct 26, 2025 0:18am

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines 30 to +68
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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments