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

Refactor ContextMenuWrapper #5679

Merged
merged 9 commits into from
May 22, 2024
Merged

Refactor ContextMenuWrapper #5679

merged 9 commits into from
May 22, 2024

Conversation

benwolfram
Copy link
Collaborator

@benwolfram benwolfram commented May 14, 2024

Problem:
Modernizing this file to show it some love in preparation of work to improve context menus and upgrade react-contexify, ie. keyboard navigation.

Fix:
Updating to modern react hooks and functional components.

Only note, is that I chose to remove the memoization (formerly shouldComponentUpdate, replace with memo in one of my earlier commits). I don't see a performance impact from this and it's better to not pre-emptively memoize. Typescript wasn't able to properly infer the generic types when wrapping with memo (see the commit related to removing memo).

s/o to @Rheeseyb for the help

Manual Tests:
I hereby swear that:

  • I opened a hydrogen project and it loaded
  • I could navigate to various routes in Preview mode

Relates to #5643

@benwolfram benwolfram self-assigned this May 14, 2024
Copy link
Contributor

github-actions bot commented May 14, 2024

Try me

Copy link

relativeci bot commented May 14, 2024

#12561 Bundle Size — 62.13MiB (~-0.01%).

cb6af71(current) vs 6339ece master#12560(baseline)

Warning

Bundle contains 52 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Improvement 1 improvement
                 Current
#12561
     Baseline
#12560
Improvement  Initial JS 45.21MiB(~-0.01%) 45.21MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 22.01% 22.71%
No change  Chunks 30 30
No change  Assets 33 33
No change  Modules 4288 4288
No change  Duplicate Modules 519 519
No change  Duplicate Code 31.01% 31.01%
No change  Packages 449 449
No change  Duplicate Packages 52 52
Bundle size by type  Change 2 changes Improvement 2 improvements
                 Current
#12561
     Baseline
#12560
Improvement  JS 62.12MiB (~-0.01%) 62.12MiB
Improvement  HTML 11.16KiB (-0.33%) 11.2KiB

Bundle analysis reportBranch standardized-context-menuProject dashboard

Copy link
Contributor

github-actions bot commented May 14, 2024

Performance test results:
(Chart1)
(Chart2)

@benwolfram benwolfram force-pushed the standardized-context-menu branch 3 times, most recently from 62c5462 to 372d930 Compare May 15, 2024 19:50
@benwolfram benwolfram marked this pull request as ready for review May 16, 2024 19:48
@benwolfram benwolfram requested a review from a team May 16, 2024 19:48
dispatch?: EditorDispatch
data: T
renderTag?: string
children?: ReactNode
Copy link
Contributor

Choose a reason for hiding this comment

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

Normally we'd use React.PropsWithChildren but this is fine tbh

hidden={isHidden(item)}
style={{
height: item?.isSeparator ? 9 : 28,
display: 'flex',
Copy link
Member

Choose a reason for hiding this comment

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

Maybe too soon / out of scope for this refactor: but I wonder if we'd be better off with a grid here, or even a variable for the list-item layout that we want (just label, label with accesor, icon+ label, icon+label+accessor etc).

Copy link
Contributor

Choose a reason for hiding this comment

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

These are valid points, but this PR is a prep step that was just about turning the thing into a functional component (I asked Ben to open this PR now so that there is less noise in the work around standardising the context menus)


show(
event,
localXHack_KILLME === 'local-x-coord-KILLME'
Copy link
Contributor

Choose a reason for hiding this comment

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

again, minor - but maybe extract it to

  const options = localXHack_KILLME === 'local-x-coord-KILLME' 
      ? { position: { x: event.nativeEvent.offsetX, y: event.nativeEvent.pageY } } 
      : undefined

  show(event, options)

}
const renderItem = useCallback(
(item: Item<T>, index: number) => {
return (
Copy link
Contributor

Choose a reason for hiding this comment

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

how easy/hard will it be to extract it to its own component instead of a callback?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I probably should do this.. I'll update!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So... this felt easy and like a no brainer for organization. But I feel like there are just hidden traps waiting for me in this component 😂. I spent all afternoon trying to get it and making it a new component broke the 'Paste' functionality and tests. So I've reverted that.

If you think it's important, maybe we can follow up later.

Copy link
Contributor

@liady liady left a comment

Choose a reason for hiding this comment

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

lgtm, left some code style comments

@benwolfram benwolfram force-pushed the standardized-context-menu branch 2 times, most recently from 8c7424b to 3d13512 Compare May 17, 2024 22:22
@Rheeseyb Rheeseyb merged commit 99354b6 into master May 22, 2024
13 checks passed
@Rheeseyb Rheeseyb deleted the standardized-context-menu branch May 22, 2024 10:35
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.

None yet

5 participants