Skip to content
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

Avoid calling getCharacterCoordinates when fullHeight is set in the MarkdownEditor #3423

Merged
merged 2 commits into from
Jun 19, 2023

Conversation

japf
Copy link
Contributor

@japf japf commented Jun 19, 2023

This fixes a performance issue where on each keystroke getCharacterCoordinates is called in the markdown editor.
When fullHeight is set to true, we can skip this call and save some cpu cycles 🚀

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Changes are SSR compatible
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@changeset-bot
Copy link

changeset-bot bot commented Jun 19, 2023

🦋 Changeset detected

Latest commit: 718e28e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jun 19, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 101.06 KB (0%)
dist/browser.umd.js 101.59 KB (0%)

@japf japf temporarily deployed to github-pages June 19, 2023 11:54 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3423 June 19, 2023 11:54 Inactive
@@ -4,6 +4,7 @@ import {SxProp} from '../../sx'
import {getCharacterCoordinates} from '../utils/character-coordinates'

type UseDynamicTextareaHeightSettings = {
fullHeight?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just call this disabled or something generic like that? This hook isn't specific to the Markdown editor - it can be used to size any textarea - but fullHeight is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done in 718e28e

Copy link
Contributor

@iansan5653 iansan5653 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's still draft, but looks good 🙂

@japf japf marked this pull request as ready for review June 19, 2023 13:31
@japf japf requested review from a team and broccolinisoup June 19, 2023 13:31
Copy link
Contributor

@mperrotti mperrotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@japf - could you add a Storybook example for this behavior in src/drafts/MarkdownEditor/MarkdownEditor.stories.tsx?

@japf
Copy link
Contributor Author

japf commented Jun 19, 2023

src/drafts/MarkdownEditor/MarkdownEditor.stories.tsx

👋 @mperrotti it looks like fullHeight is already in the storybook:

screenshot of the storybook settings for the markdown editor, showing the fullheight option

when this is enabled, we can see there are no calls to getCharacterCoordinates 🎉

@github-actions
Copy link
Contributor

Uh oh! @japf, the image you shared is missing helpful alt text. Check #3423 (comment).

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

1 similar comment
@github-actions
Copy link
Contributor

Uh oh! @japf, the image you shared is missing helpful alt text. Check #3423 (comment).

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

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.

4 participants