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

fix: Add width, height attrs to canvas element #32801

Closed
wants to merge 1 commit into from

Conversation

bsmth
Copy link
Member

@bsmth bsmth commented Mar 22, 2024

Description

The canvas element had no width and height attributes applied, so it was looking a little broken. This PR adds them in to the live sample so it looks a little better:

-<canvas></canvas>
+<canvas width="680" height="380"></canvas>

The defaults are 150 x 300: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas#attributes

Motivation

Reader reports a strange-looking example.

Related issues and pull requests

Fixes #31288

@bsmth bsmth requested a review from a team as a code owner March 22, 2024 15:09
@bsmth bsmth requested review from Josh-Cena and removed request for a team March 22, 2024 15:09
@github-actions github-actions bot added Content:Learn:JavaScript Learning area JavaScript docs size/s 6-50 LoC changed labels Mar 22, 2024
Copy link
Contributor

@wbamberg
Copy link
Collaborator

I think this is another regression caused by the fact that the Playground loads content after DOMContentLoaded is fired, which should be fixed by mdn/yari#10770.

You can see that the code sets canvas width and height inside the DOMContentLoaded event handler:

document.addEventListener("DOMContentLoaded", () => {
canvas.width = document.documentElement.clientWidth;
canvas.height = document.documentElement.clientHeight;
});
, and that the page used to work: https://web.archive.org/web/20230323062429/https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Looping_code.

So this page ought to not need this fix once mdn/yari#10770 percolates, and that seems like a better fix since it's not hardcoding the size.

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

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

See #32801 (comment), I'm not sure this fix is needed.

@bsmth
Copy link
Member Author

bsmth commented Mar 22, 2024

Nice, thanks for checking, let me close for now and we can check if the Yari fix resolved it 👍

@bsmth bsmth closed this Mar 22, 2024
@wbamberg
Copy link
Collaborator

No, the Yari PR does not seem to have fixed the regression :(

@bsmth
Copy link
Member Author

bsmth commented Apr 19, 2024

@wbamberg
Copy link
Collaborator

It is partly fixed by that PR. The canvas does occupy the whole iframe now, but actually it is a little too big, so we get scrollbars:

Screen Shot 2024-04-19 at 12 07 09 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:Learn:JavaScript Learning area JavaScript docs size/s 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<canvas> tag doesn't seem to be working properly
2 participants