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

[ui] Directly set MiddleTruncate truncated text to fix flicker #26888

Merged
merged 2 commits into from
Jan 7, 2025

Conversation

bengotow
Copy link
Collaborator

@bengotow bengotow commented Jan 7, 2025

Summary & Motivation

This is a small follow-up to #26834

I've noticed that sometimes with MiddleTruncate, there is a very slight flicker when the text is first rendered. There's a single frame where the rendered text is null, and you can see it before the text appears.

I'm not sure if my computer is just running slow today (looking for excuses to get an M4 now...), or if it's the volume of MiddleTruncates on this page (there are at least 50 rendering all at the same time), but here's an example if you watch the tag on the right:

text-flicker.mov

Looking at the code for this, I don't think there's a reason for the sizing to update React state and set the text through a React render. The text is just used to set the span content, and the component doesn't re-render unless the text changes (in which case calculateTargetStyle changes and the effect runs again.) Setting the textContent directly removes the flicker shown in the video.

How I Tested These Changes

Tested in FF + Chrome manually

@bengotow bengotow requested review from salazarm and hellendag January 7, 2025 04:10
Copy link

github-actions bot commented Jan 7, 2025

Deploy preview for dagit-storybook ready!

✅ Preview
https://dagit-storybook-g5dvsnocm-elementl.vercel.app
https://bengotow-2025-01-fix-jank-2.components-storybook.dagster-docs.io

Built with commit da70ea5.
This pull request is being automatically deployed with vercel-action

@bengotow bengotow force-pushed the bengotow-2025-01/fix-jank-2 branch from c83d9cc to 9d7361b Compare January 7, 2025 04:14
Copy link
Contributor

@salazarm salazarm left a comment

Choose a reason for hiding this comment

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

Makes sense to me! I think this component doesn't using React.memo though so a parent component re-render could cause this component to re-render even if the text content hasn't changed. I think we should add a second ref to record the value of the truncatedText and fallback to that in this case. Or... more simply... just wrap this component with React.memo.

@bengotow
Copy link
Collaborator Author

bengotow commented Jan 7, 2025

Ahh good call I'll add a React.memo to this - definitely should have one 👍

@bengotow
Copy link
Collaborator Author

bengotow commented Jan 7, 2025

The build errors seem unrelated, going to merge this

@bengotow bengotow merged commit 194ba27 into master Jan 7, 2025
1 of 2 checks passed
@bengotow bengotow deleted the bengotow-2025-01/fix-jank-2 branch January 7, 2025 15:25
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.

2 participants