Skip to content

Restore canvas box sizing after chart destruction - #12375

Open
hakarrr wants to merge 2 commits into
chartjs:masterfrom
hakarrr:fix-canvas-box-sizing-restoration
Open

hakarrr wants to merge 2 commits into
chartjs:masterfrom
hakarrr:fix-canvas-box-sizing-restoration

Conversation

@hakarrr

@hakarrr hakarrr commented Oct 26, 2026

Copy link
Copy Markdown

Problem

The DOM platform sets an empty inline canvas.style.boxSizing to border-box when acquiring the context, but does not save that property alongside the other styles restored by releaseContext().

After chart.destroy(), the injected inline rule therefore continues to override the page's CSS. For example, a 300 x 150 CSS-pixel canvas with box-sizing: content-box, 20px padding and a 5px border starts at an outer size of 350 x 200px. After creating and destroying a nonresponsive chart, it remains 300 x 150px instead of returning to its initial size. Reusing the canvas also treats this leftover inline value as its initial state.

Change

Save the initial inline boxSizing with display, height and width, so the existing release path restores it. This leaves chart-time sizing behavior unchanged and does not add a public option.

Tests

Add six native DOM tests covering empty, explicit content-box and explicit border-box inline values, with and without a stylesheet that supplies padding, borders and content-box sizing. Each checks chart-time sizing, restored inline/computed styles, outer dimensions and a second create/destroy cycle.

  • Without the source fix: two regressions fail; the four explicit-style controls pass.
  • With the fix: all 1,709 native Jasmine tests pass in headless Chrome, including all 27 DOM-platform tests.
  • pnpm build, declaration generation, tsc --noEmit, and ESLint on the two changed files pass.

Used a local headless launcher adjustment for this environment; it is not part of the PR. Firefox and downstream integration projects were not run.

hakarrr and others added 2 commits October 26, 2026 23:52
Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
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.

1 participant