Repository navigation
perf(keyboard): the keyboard height no longer loads the selection lock #14289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+78
−38
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b98e7d7
perf(keyboard): the keyboard height no longer loads the selection lock
vjeux e84b7a7
perf(keyboard): review round: the changeset scopes the saving, and ca…
vjeux ed56d5e
test(keyboard): the snap-paging bundle test counts caretAt with the s…
vjeux 7ec7797
perf(keyboard): review round: the changeset's saving needs no other c…
vjeux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [perf] The keyboard height reads the caret position from a module of its own, not from the selection lock. On a page whose lazily loaded code also uses the selection lock, as a page with a DropdownMenu or a Table does, the bundler no longer puts the whole lock in the page's first load: first-load JavaScript drops by about 1.6 to 1.8 KB gzip there, with esbuild and with Rolldown. Other pages that load the keyboard height, such as a TextInput, ChatLayout or BottomSheet page, change by under 50 bytes minified. A page that uses the selection lock itself loads up to 80 bytes more. The keyboard height reads the same caret as before. | ||
|
|
||
| @vjeux | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file caretAt.ts | ||
| * @input A document, a client point and the shadow roots that | ||
| * `caretPositionFromPoint` looks into | ||
| * @output caretAt: the caret position the engine puts at that point | ||
| * @position An internal utility. The keyboard height imports it from here, so | ||
| * it does not load the selection lock. | ||
| */ | ||
|
|
||
| /** The caret position the engine puts at a point, by either query. */ | ||
| export function caretAt( | ||
|
astracat-bot[bot] marked this conversation as resolved.
Resolved
|
||
| doc: Document, | ||
| x: number, | ||
| y: number, | ||
| shadowRoots: ReadonlyArray<ShadowRoot>, | ||
| ): {node: Node; offset: number} | null { | ||
| const queries = doc as Document & { | ||
| caretPositionFromPoint?: ( | ||
| x: number, | ||
| y: number, | ||
| options?: {shadowRoots?: ShadowRoot[]}, | ||
| ) => {offsetNode: Node; offset: number} | null; | ||
| caretRangeFromPoint?: (x: number, y: number) => Range | null; | ||
| }; | ||
| if (typeof queries.caretPositionFromPoint === 'function') { | ||
| // Without the roots, a point over shadow text answers at its host. | ||
| const position = | ||
| shadowRoots.length > 0 | ||
| ? queries.caretPositionFromPoint(x, y, { | ||
| shadowRoots: [...shadowRoots], | ||
| }) | ||
| : queries.caretPositionFromPoint(x, y); | ||
| return position == null | ||
| ? null | ||
| : {node: position.offsetNode, offset: position.offset}; | ||
|
astracat-bot[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| if (typeof queries.caretRangeFromPoint === 'function') { | ||
| // This query takes no shadow roots: over shadow text it answers at the | ||
| // shadow host. | ||
| const range = queries.caretRangeFromPoint(x, y); | ||
| return range == null | ||
| ? null | ||
| : {node: range.startContainer, offset: range.startOffset}; | ||
| } | ||
|
astracat-bot[bot] marked this conversation as resolved.
Resolved
|
||
| return null; | ||
| } | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.