popcodeorg / popcodeorg/popcode

validation on canvas element incorrectly flags 'width' attribute as an error

オープン
#671 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug
主要言語
JavaScript
スター
191
フォーク
143
平均マージ
4日 11時間
マージ済み PR(30日)
5

説明

I'm trying to use a <canvas> element (for a Tiny Turtle exercise) and set its width to something larger than the default of 300px. Naively I tried a css rule:

canvas {
  width: 100%;
  min-height: 400px;
}

But with <canvas>, a css-specified width actually scales the content. This makes the turtle head and line segments appear quite large and even pixellated and does not actually give any more room to draw.

MDN recommends instead that you set the width and height directly on the element. Trying this triggered a popcode validation error on width:

9
Don't use the "width" attribute. Instead, use the CSS width property

Impact: mostly a little annoying. You can't set the real width of the canvas, so there will be unused space at the right margin -- and quite noticeable with a bigger screen. Complicated turtle drawings may not fit well into 300x150 px (although for some reason the height attribute is allowed through validation, so the canvas can be made taller).

Also, the validator-recommended fix isn't a real fix, which is minor in and of itself but we'd like users to be able to rely on its recommendations.

Steps to reproduce:

  1. Open this popcode link: https://popcode.org/?gist=1791db30a9fa1cbcc39e0ec181388634
  2. In the html panel, set the <canvas> element's width attribute to, say, 400. Observe the validation error.
  3. Observe the somewhat-pixellated turtle stamp render (due to the css width being set w/o html width).
  4. Observe the rendered length of a forward(30) segment. Cut that forward down to 10 units to allow more drawing room. Observe that the stamp now overwhelms the line segment.

On a page without validation, eg jsbin, setting the width attr has the desired result of setting the canvas's coordinate system width (which can then optionally be scaled with css).

Tested on macos 10.11 with Safari 10.0.3 and Chrome 56.0.2924.87.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされた Popcode gist を使って検証エラーを再現し、width 属性を持つ canvas 要素と CSS width を推奨する validator メッセージに焦点を当てます。このメッセージを出力する validator のエントリポイントを追跡し、width の扱いを height と比較します。完了条件は、有効な canvas の width が受け入れられ、推奨内容が canvas のサイズ指定の挙動と矛盾しなくなることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
html, javascript
領域
frontend, testing-qa, web-dev
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。