perf(autosize): fix maxHeight regression under min-height CSS; add Vitest browser test suite#49
Merged
mattcosta7 merged 3 commits intoJun 29, 2026
Conversation
Copilot
AI
changed the title
[WIP] Fix maxHeight calculation regression in autosize performance
perf(autosize): fix maxHeight regression under min-height CSS; add Vitest browser test suite
Jun 29, 2026
There was a problem hiding this comment.
Pull request overview
This PR fixes a maxHeight regression in autosize when min-height/max-height CSS causes the rendered height to diverge from the library’s last-written inline height, and it introduces a real-browser (Chromium/Playwright) Vitest test suite to prevent future regressions.
Changes:
- Restore original
maxHeightsemantics by always deriving it from the live computed (rendered) textarea height. - Add Vitest browser-mode configuration and a new browser-based test suite covering growth/shrink, min-height behavior, drag-resize disabling, form reset, and unsubscribe cleanup.
- Update tooling/config (
package.jsonscripts + devDependencies,tsconfig.jsonskipLibCheck,.gitignore) to support the new test setup.
Show a summary per file
| File | Description |
|---|---|
src/index.js |
Fixes maxHeight calculation to use rendered/computed height under CSS clamping. |
test/autosize.test.js |
Adds Chromium-based regression and behavior tests for autosizing and resize detection. |
vitest.config.js |
Enables Vitest browser mode using the Playwright provider (Chromium headless). |
package.json |
Replaces placeholder test script with vitest run and adds Vitest/Playwright devDependencies. |
package-lock.json |
Locks the new Vitest/Playwright dependency graph. |
tsconfig.json |
Adds skipLibCheck to avoid type-check conflicts introduced by new test tooling types. |
.gitignore |
Ignores Vitest browser screenshot output directory. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/8 changed files
- Comments generated: 2
- Review effort level: Low
| // With the pre-fix logic, style.maxHeight would be capped lower than the | ||
| // actual rendered height, which is incorrect. | ||
| textarea.style.minHeight = '120px' | ||
| const {unsubscribe} = autosize(textarea) |
Comment on lines
+18
to
+19
| "test": "vitest run", | ||
| "test:watch": "vitest", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The performance rewrite on this branch introduced a subtle
maxHeightbug by reusing the library's last-written inlineheightinstead of the live computed height. Undermin-height/max-heightCSS, these diverge — e.g. the library writes"40px"but the element renders at100px— producing a smaller, incorrectmaxHeightcap. This PR restores the original semantics and adds a real-browser test suite to prevent regressions.src/index.js— maxHeight fixThe
cachedBorderAddOnoptimization,heighttracking forResizeObserver, and the reads-before-writes batching structure are all preserved.Test suite — Vitest browser mode
jsdom is a non-starter here (
scrollHeightalways returns0, no layout). Tests run in real Chromium via Playwright.vitest.config.js— browser mode, playwright provider, chromium, headlesstest/autosize.test.js— 7 tests covering:min-heightfloor is respected (rendered height ≥ min-height)min-heightset,style.maxHeightis not capped below the live computed heightisUserResizedand clearsmaxHeightunsubscribe()stops further resizingSupporting changes
devDependencies:vitest@4.1.9,@vitest/browser@4.1.9,@vitest/browser-playwright@4.1.9,playwright@1.61.1(all at patched versions per advisory DB check)package.json"test"script replaced withvitest run;"test:watch"added;pretestbuild hook removed (tests importsrc/index.jsdirectly, no build needed)tsconfig.json:skipLibCheck: trueto prevent vitest's@types/chaiconflicting with the existingtarget: es5build.gitignore: excludetest/__screenshots__/