agentcooper / react-pdf-highlighter

Set of React components for PDF annotation
https://agentcooper.github.io/react-pdf-highlighter/
MIT License
1.02k stars 399 forks source link

Debounced method called with different contexts #276

Open dkazakov8 opened 1 month ago

dkazakov8 commented 1 month ago

Hello,

I just upgraded to version 7.0.0, and when I resize the window, this error appears in the console: "Uncaught Error: Debounced method called with different contexts." This occurs inside the "debounce" library, and the root cause is this line. The debouncedScaleValue method has no bound context, so when it's used in ResizeObserver or addEventListener, it has different contexts.

It seems like this error doesn't negatively affect functionality; it just spams the console with errors. this.debouncedScaleValue = this.debouncedScaleValue.bind(this) helps, maybe someone could include it in a PR.

ksnip_20240712-212106

agentcooper commented 1 month ago

Thanks, I'll take a look. Does the 7.0.0 work fine for you otherwise?

youlandEric commented 1 month ago

Thanks, I'll take a look. Does the 7.0.0 work fine for you otherwise?

Please update it if there's time . Thank you

dkazakov8 commented 1 month ago

Thanks, I'll take a look. Does the 7.0.0 work fine for you otherwise?

Yes, thanks. Everything else is working fine. The only difference from version 6.1.0 in my use cases was an incorrect z-index for the annotations layer (annotations are not clickable), which I fixed with:

.PdfHighlighter__highlight-layer {
  z-index: 3 !important;
}
israel-arvizu commented 1 month ago

Also encountering this issue on 7.0.0, any update?

codepeach commented 1 month ago

Same here, having the same issue

NathanHam16 commented 1 month ago

Simple bandaid solution is to replace:

debouncedScaleValue: () => void = debounce(this.handleScaleValue, 500); in PdfHighlighter.tsx with debouncedScaleValue = this.handleScaleValue;

Keep in mind that removing debouncing may result in severe performance losses for resizing functionality.