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

Deprecate the original slot implementation and refactor usage #22027

Closed
wants to merge 3 commits into from

Conversation

youknowriad
Copy link
Contributor

The original implementation of Slot (without bubblesVirtually) suffers from a number of issues, Important one being the lack of React context support. We've been slowing moving out from its usage but we forget sometimes to use bubblesVirtually when we add a new Slot.

This PR deprecates the old implementation officially (deprecation message) and updates the existing usage.

@youknowriad youknowriad self-assigned this May 1, 2020
@youknowriad youknowriad added [Feature] UI Components Impacts or related to the UI component system [Type] Code Quality Issues or PRs that relate to code quality labels May 1, 2020
icon={ chevronDown }
label={ __( 'More rich text controls' ) }
controls={ orderBy(
fills.map( ( [ { props } ] ) => props ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mapping through fills and using them as "controls" is not something I was expecting. I'm not sure how we can solve this here? Why can't we just use a render Slot in renderContent of a "Dropdown" component. Anyway, @ellatrix, maybe you can help solve this. (bubbles virtually don't support children as function and can't support it)

Copy link
Member

Choose a reason for hiding this comment

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

Why can't we just use a render Slot in renderContent of a "Dropdown" component.

Could you elaborate?
I'm also not sure how to fix this here. Normally we use a controls array with control objects, but in the case of RichText, components are used. Not sure if we can change that now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed a fix, let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

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

How are they now sorted alphabetically?

Copy link
Member

Choose a reason for hiding this comment

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

I'm also not sure how the collapsed button can now know if any buttons are active. I guess this would be easier with a controls array.

Another thing I'm noticing is that the buttons have too much space in between them compared to master

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are not sorted, I believe they are probably sorted at the "import" level.

The thing is, with Slot/Fill, we're not supposed to know the shape of the children... So I'd say we were doing it wrong previously or Slot/Fill, is not the right API here.

Copy link
Member

Choose a reason for hiding this comment

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

I'll have a look at it now

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I tried converting it to control object but that doesn't really work because we're stuck with the React component rendered in the format type edit functions. Maybe we can create a slot and fill for each button, which could be sorted by the title of the format type?

Copy link
Member

Choose a reason for hiding this comment

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

It still wouldn't work perfectly though, because some format types could render multiple buttons. That's more of an edge case though.

@github-actions
Copy link

github-actions bot commented May 1, 2020

Size Change: +515 B (0%)

Total Size: 821 kB

Filename Size Change
build/block-directory/index.js 6.6 kB +1 B
build/block-editor/index.js 101 kB +301 B (0%)
build/block-editor/style-rtl.css 10.2 kB +13 B (0%)
build/block-editor/style.css 10.2 kB +14 B (0%)
build/block-library/index.js 115 kB +1 B
build/blocks/index.js 48.1 kB -1 B
build/components/index.js 179 kB +115 B (0%)
build/core-data/index.js 11.4 kB +1 B
build/data/index.js 8.44 kB +1 B
build/edit-post/index.js 28.2 kB +52 B (0%)
build/edit-site/index.js 12.3 kB +9 B (0%)
build/edit-widgets/index.js 8.34 kB +10 B (0%)
build/editor/index.js 44.3 kB -2 B (0%)
build/format-library/index.js 7.63 kB -1 B
build/nux/index.js 3.4 kB +2 B (0%)
build/rich-text/index.js 14.8 kB +1 B
build/server-side-render/index.js 2.67 kB -1 B
build/viewport/index.js 1.84 kB -1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.02 kB 0 B
build/annotations/index.js 3.62 kB 0 B
build/api-fetch/index.js 4.08 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 761 B 0 B
build/block-library/editor-rtl.css 7.08 kB 0 B
build/block-library/editor.css 7.08 kB 0 B
build/block-library/style-rtl.css 7.24 kB 0 B
build/block-library/style.css 7.25 kB 0 B
build/block-library/theme-rtl.css 683 B 0 B
build/block-library/theme.css 685 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/components/style-rtl.css 16.9 kB 0 B
build/components/style.css 16.9 kB 0 B
build/compose/index.js 6.66 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/date/index.js 5.47 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.1 kB 0 B
build/edit-navigation/index.js 4.05 kB 0 B
build/edit-navigation/style-rtl.css 485 B 0 B
build/edit-navigation/style.css 485 B 0 B
build/edit-post/style-rtl.css 12.2 kB 0 B
build/edit-post/style.css 12.2 kB 0 B
build/edit-site/style-rtl.css 5.19 kB 0 B
build/edit-site/style.css 5.2 kB 0 B
build/edit-widgets/style-rtl.css 4.67 kB 0 B
build/edit-widgets/style.css 4.66 kB 0 B
build/editor/editor-styles-rtl.css 428 B 0 B
build/editor/editor-styles.css 431 B 0 B
build/editor/style-rtl.css 5.07 kB 0 B
build/editor/style.css 5.08 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 734 B 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.51 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.13 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/media-utils/index.js 5.29 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/url/index.js 4.02 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

@gziolo
Copy link
Member

gziolo commented May 1, 2020

Can we land those which work without issues first so we can test them faster in master?

@youknowriad
Copy link
Contributor Author

Can we land those which work without issues first so we can test them faster in master?

There's only two that are not working properly. I can extract the remaining ones to a separate PR but I'll have to remove the "deprecated" call to avoid breaking the tests.

@gziolo
Copy link
Member

gziolo commented May 1, 2020

Right, you’d have to do it. You can always fix those issues but it might require some heavy debugging 😃

@@ -25,13 +29,20 @@ const BlockSettingsMenuControlsSlot = ( { fillProps } ) => {
),
};
}, [] );
const slot = useSlot( 'BlockSettingsMenuControls' );
const hasFills = Boolean( slot.fills && slot.fills.length );
Copy link
Member

@gziolo gziolo May 1, 2020

Choose a reason for hiding this comment

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

It’s used nearly everywhere, how about useSlot exposes hasFills by default?

@youknowriad youknowriad force-pushed the update/deprecate-old-slot branch from 281e713 to 8b81838 Compare May 5, 2020 10:27
@diegohaz
Copy link
Member

diegohaz commented May 6, 2020

Thanks for putting this together @youknowriad! :)

I wonder what are the plans for React Native, since it doesn't support bubblesVirtually (because of React Portal).

@youknowriad
Copy link
Contributor Author

@diegohaz I was not aware of this limitation. How are they handling it so far because we already make an extensive use of bubblesVirtually slots? cc @Tug

@gziolo gziolo added the Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) label May 6, 2020
@diegohaz
Copy link
Member

diegohaz commented May 6, 2020

I think they're simply not using bubblesVirtually on the .native.js versions. I noticed this while working on #19242:

It took so many workarounds for this to vaguely work that I think we should, in the future, re-consider the bubblesVirtually approach altogether. Maybe using React Portal wasn't a good idea? After all, it's not even supported by React Native.

#19242 (comment)

@Tug
Copy link
Contributor

Tug commented May 6, 2020

Yes, it might be simply luck, but we aren't using any components that uses a Slot with the bubblesVirtually prop. I guess we'll have have to write our own implementation of SlotFill when needed

@youknowriad
Copy link
Contributor Author

I guess we'll have have to write our own implementation of SlotFill when needed

I was thinking the same, I feel we should have a unique implementation for slot/fill for web and a unique one for mobile. the current situation is not great.

@etoledom
Copy link
Contributor

etoledom commented May 6, 2020

I have tested the mobile app with this branch, and I encountered an error when focusing a Rich-Text based component:

cc @hypest @Tug

@gziolo
Copy link
Member

gziolo commented Nov 28, 2020

@youknowriad, do you plan to refresh this PR. Do you need any help from the team working on mobile apps?

@gziolo gziolo added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Nov 28, 2020
@youknowriad
Copy link
Contributor Author

Definitely, I'd love help from the mobile team here to ensure the APP works with all kind of slots and then I would be able to refactor this and move it forward.

@Tug Tug self-requested a review November 30, 2020 08:42
@etoledom etoledom removed their request for review December 8, 2020 16:34
Base automatically changed from master to trunk March 1, 2021 15:43
@youknowriad youknowriad deleted the update/deprecate-old-slot branch June 11, 2021 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants