fix title textarea auto-height for firefox and improve sync reliability#815
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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 problem:

field-sizing: contentis chrome-only. on firefox, the title textarea wouldn't grow as you typed it stayed at one line. the previous attempt at a firefox fallback usedheight: auto !important+overflow: hidden !importantin css, which caused layout jank and didn't reliably sync on mount or when switching notes.what changed:
ref strategy:
replaced the plain
useRef<HTMLTextAreaElement>(titleRef) with a callback ref (setTitleRef) usinguseCallback. this lets us:syncHeightimmediately when the element mounts (before any react render cycle)inputevent listener directly on the element for real-time height sync as the user types, bypassing react's synthetic event batchingsyncHeightfunction:the height sync logic was updated from:
to:
resetting to
0instead ofautogives a more reliable scroll height read on firefox, whereautocan return a stale value before the browser recalculates layout.manual sync on noteId/editedTitle change:
kept the
useEffectthat callssyncHeightwhennoteIdoreditedTitlechanges, so switching notes correctly resizes the textarea to match the incoming title.stableNote async sync:
added a
useEffectto seteditedTitlefromstableNote.titleif the title is still empty when data arrives. this handles the case where the note loads after initial render and the textarea would otherwise stay blank.onChangehandler:removed the manual
syncHeight(e.target)call fromonChangesince the nativeinputlistener on the ref now handles this. this avoids double-calling sync.css cleanup:
height: auto !importantandoverflow: hidden !importantfromtextarea.field-sizing-content— these were the source of the jank.field-sizing-contentutility class that are no longer neededtextarea classnames:
whitespace-pre-wrap [overflow-wrap:anywhere]with[white-space:pre-wrap] [overflow-wrap:break-word] [word-break:break-word]for more explicit control and better cross-browser wrappingoverflow: hiddenandwidth: 100%to inline styles to prevent any scrollbar flash during height recalcoverflow-hiddento the wrapper div to clip any overflow during transitionsfield-sizing-contentkept for chrome; js height sync handles firefox