Skip to content
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

[Bug]: toDataURL will incorrectly trigger the before:render and after:render hooks. #10397

Open
7 tasks done
zhe-he opened this issue Jan 13, 2025 · 3 comments
Open
7 tasks done

Comments

@zhe-he
Copy link
Contributor

zhe-he commented Jan 13, 2025

CheckList

  • I agree to follow this project's Code of Conduct
  • I have read and followed the Contributing Guide
  • I have read and followed the Issue Tracker Guide
  • I have searched and referenced existing issues and discussions
  • I am filing a BUG report.
  • I have managed to reproduce the bug after upgrading to the latest version
  • I have created an accurate and minimal reproduction

Version

6.0.2

In What environments are you experiencing the problem?

No response

Node Version (if applicable)

None

Link To Reproduction

https://codepen.io/zhe-he-the-vuer/pen/EaYLxLB

Steps To Reproduce

  1. Add before:render and after:render hooks.
  2. Call canvas.toDataURL.

Expected Behavior

toDataURL:  

Actual Behavior

toDataURL: before:render -- after:render

image

Error Message & Stack Trace

No response

@asturur
Copy link
Member

asturur commented Jan 13, 2025

What do you mean incorrectly trigger? Why do you think is incorrect? Let's first discuss that.

@zhe-he
Copy link
Contributor Author

zhe-he commented Jan 14, 2025

@asturur

  1. toDataURL is an export method, not a user-initiated re-render operation. Triggering render hooks might mislead developers into thinking the canvas is being redrawn on the screen, while it is actually just generating image data.
  2. If toDataURL triggers hooks, time-consuming operations within the hooks could cause unnecessary performance degradation.
  3. To maintain consistency, we could add an option that allows developers to choose not to skip hooks (default to skipping for better performance): canvas.toDataURL({ skipHooks: false });

@asturur
Copy link
Member

asturur commented Jan 16, 2025

no we are not adding more options, that is for sure.
ToDataUrl should mimic more or less what toCanvasElement does, and all of them need to render the canvas again.
On the other side if you are using after:render to modify the render, you may want it into your export as well.

The safest thing to do could be to try to emit during the event the type of render that is happening, normal, toDataUrl, toCanvasElement or whatever. But i think that could be slightly complicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants