-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(PdfReader): add setUrl method #815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,14 +16,42 @@ export async function init(id, invoke, options) { | |||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (options.url === null) { | ||||||||||||
| Data.set(id, { el, invoke, options }); | ||||||||||||
|
|
||||||||||||
| if (options.url) { | ||||||||||||
| setUrl(id, options.url); | ||||||||||||
| } | ||||||||||||
| else { | ||||||||||||
| setData(id, options.data); | ||||||||||||
|
||||||||||||
| setData(id, options.data); | |
| await setData(id, options.data); |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setUrl function doesn't check if the pdf object exists before calling disposePdf. If Data.get(id) returns undefined or null (e.g., if init was never called or the component was already disposed), this will cause disposePdf to receive an invalid value, potentially leading to runtime errors when trying to destructure properties.
| const pdf = Data.get(id); | |
| const pdf = Data.get(id); | |
| if (!pdf) { | |
| return; | |
| } |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setData function doesn't check if the pdf object exists before calling disposePdf. If Data.get(id) returns undefined or null, this will cause similar issues as in setUrl.
| disposePdf(pdf); | |
| if (pdf) { | |
| disposePdf(pdf); | |
| } |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The disposePdf function doesn't check if the pdf parameter is null or undefined before destructuring. If called with an invalid value, this will cause a runtime error.
| const disposePdf = pdf => { | |
| const disposePdf = pdf => { | |
| if (!pdf) { | |
| return; | |
| } |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon at the end of the statement. While JavaScript allows this due to automatic semicolon insertion, it's a best practice to include semicolons for consistency with the rest of the codebase.
| }) | |
| }); |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused variable scaleEl.
| const scaleEl = el.querySelector(".bb-view-scale-input"); |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dispose function doesn't check if the pdf object exists before calling disposePdf. If Data.get(id) returns undefined, disposePdf will be called with an invalid value.
| disposePdf(pdf); | |
| if (pdf) { | |
| disposePdf(pdf); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
setUrlfunction is called withoutawaitin theinitfunction, butsetUrlis an async function that performs important operations likeloadPdf. This means theinitfunction may complete before the PDF is fully loaded, which could cause race conditions or unexpected behavior. Either await the call or ensure the function doesn't need to complete beforeinitreturns.