fix(elements): keep drop listeners stable during text input - #474
Open
ephraimduncan wants to merge 1 commit into
Open
fix(elements): keep drop listeners stable during text input#474ephraimduncan wants to merge 1 commit into
ephraimduncan wants to merge 1 commit into
Conversation
With PromptInputProvider, each keystroke made a new controller identity. The drop effects had a dependency on the add callback through that identity. Thus each keystroke removed the dragover and drop listeners and installed them again. The file-input registration effect also ran again on each keystroke. This change uses useEffectEvent for the drop path. After this change, the listeners attach one time for each mount. The effect event calls the latest add closure. The validation behavior for accept, maxFiles, and maxFileSize does not change. The registration effect has a dependency only on the stable __registerFileInput callback. Four new tests show stable listener counts during text input and successful drops after prop changes. These tests are not successful on the code before this change.
Contributor
|
@ephraimduncan is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
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.
With
PromptInputProvider, each keystroke removed thedragoveranddroplisteners on the document or the form, and installed them again. The registration effect for the hidden file input also ran on each keystroke. After this change, the listeners attach one time for each mount, and text input does not touch them. The drop handlers call auseEffectEventwrapper, and the wrapper calls the latestaddclosure. Thus the validation behavior foraccept,maxFiles,maxFileSize, andonErrordoes not change.Five new tests spy on the document listeners and the form listeners during text input, and drop files after prop changes and count changes. Four of the five tests are not successful on the code before this change. The fifth test makes sure that a drop on the document adds the file.
Evidence:
packages/elements/src/prompt-input.tsx:348-359addmain,packages/elements/src/prompt-input.tsx:762,788main,packages/elements/src/prompt-input.tsx:717-722globalDroponlypackages/elements/src/prompt-input.tsx:772,798useEffectEventwrapper calls the latestaddclosurepackages/elements/src/prompt-input.tsx:711-713packages/elements/src/prompt-input.tsx:726-732packages/elements/src/prompt-input.tsx:644-685packages/elements/__tests__/prompt-input.test.tsx:1970,2005,2047,2106,2165