Skip to content

[codex] Keep canvas size stable across rerenders - #89

Open
Komzpa wants to merge 1 commit into
masterfrom
codex/stable-canvas-rerender-size
Open

[codex] Keep canvas size stable across rerenders#89
Komzpa wants to merge 1 commit into
masterfrom
codex/stable-canvas-rerender-size

Conversation

@Komzpa

@Komzpa Komzpa commented May 8, 2026

Copy link
Copy Markdown
Member

Summary

  • keep the logical canvas size stable across repeated Kothic.render(...) calls on the same canvas
  • derive logical width/height from existing CSS size when a HiDPI backing store was already created
  • add a focused regression test that renders the same canvas twice at DPR=2 and verifies the backing store does not double again

Fixes #51.

Validation

  • npm test
  • git diff --check

@Komzpa
Komzpa force-pushed the codex/stable-canvas-rerender-size branch 2 times, most recently from 545327b to 39294a0 Compare May 8, 2026 15:02
@Komzpa
Komzpa marked this pull request as ready for review May 17, 2026 16:06

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39294a0e69

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/kothic.js Outdated

var width = canvas.width,
height = canvas.height;
var width = parseFloat(canvas.style.width) || canvas.width,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid parsing non-pixel CSS widths as raw numbers

Reading canvas.style.width with parseFloat(...) treats values like "100%" or "12em" as pixel counts (100, 12), so render() can immediately shrink the logical canvas and then overwrite the style to that incorrect px value. This is a regression from using canvas.width directly and breaks canvases sized via non-px CSS units when this path runs in Kothic.render.

Useful? React with 👍 / 👎.

Signed-off-by: Darafei Praliaskouski <me@komzpa.net>
@Komzpa
Komzpa force-pushed the codex/stable-canvas-rerender-size branch from 39294a0 to b28a5c5 Compare May 20, 2026 02:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b28a5c5934

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/kothic.js
Comment on lines +19 to +21
if (pixelMatch) {
return parseFloat(pixelMatch[1]);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Respect updated canvas width/height attributes on rerender

Reading pixel style.width/style.height first makes rerenders ignore caller-driven size changes via canvas.width/canvas.height. After the first HiDPI render, the code stores inline "...px" styles; on later renders this branch returns the old style value and overwrites the backing store back to the previous size, so programmatic canvas resize no longer works. In practice, setting canvas.width = 300 between renders is discarded and the canvas snaps back to the old dimensions.

Useful? React with 👍 / 👎.

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

Successfully merging this pull request may close these issues.

Icons not redrawn correctly after zooming

1 participant