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

Update SlotFillProvider to the new context API #11123

Merged
merged 9 commits into from
Nov 2, 2018

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Oct 26, 2018

To be merged after #11314 lands.

The SlotFillProvider is using the React's legacy context API which will be removed in the next major version and was added as a deprecation in StrictMode in 16.6.0.

This PR updates the SlotFillProvider to the stable React's context API.

Test

  • The popover component works as expected. For example, use the / inserter to add blocks.
  • Install a plugin that uses the SlotFill API (for example: DropIt or Yoast SEO) and make sure it works as expected.

@oandregal oandregal self-assigned this Oct 26, 2018
@oandregal oandregal added [Status] In Progress Tracking issues with work in progress Framework Issues related to broader framework topics, especially as it relates to javascript labels Oct 26, 2018
@oandregal oandregal requested a review from a team October 26, 2018 16:16
@oandregal oandregal removed the [Status] In Progress Tracking issues with work in progress label Oct 26, 2018
@oandregal oandregal added this to the 4.2 milestone Oct 26, 2018
@noisysocks
Copy link
Member

I'm thinking we should upgrade to React v16.6 first so that we can use Class.contextType to migrate these components to the new Context API without having to introduce new wrapper components.

@oandregal
Copy link
Member Author

oandregal commented Oct 29, 2018

I'm thinking we should upgrade to React v16.6 first so that we can use Class.contextType to migrate these components to the new Context API without having to introduce new wrapper components.

I'd rather have this upgrade in 5.0. Using legacy APIs inside Gutenberg justifies its use within third-party (plugins, etc), which are a lot harder to migrate. Also, when we upgrade React we might end doing things differently (hooks anyone? where Class.contextType can't be used), or perhaps at that point there is an even newer/better API built on top of the low-level primitives.

@youknowriad
Copy link
Contributor

Moving out of 4.2 as it doesn't really touch the public API but still good to have for 5.0 among other react deprecations/upgrade.

@youknowriad youknowriad modified the milestones: 4.2, WordPress 5.0 Oct 29, 2018
@oandregal
Copy link
Member Author

Wanted to note that this PR is blocked until the tests are fixed.

The reason why they fail is that we are using an old version of enzyme that doesn't support the new React Context API. Updating enzyme and enzyme-adapter-react-16 fixes the issue. I'll put together a PR to update those dependencies so we can explore their impact. Note that enzyme not fully supporting React 16 has been a problem in the past that forced us to either skip tests, remove, or migrate them to react-test-renderer.

@oandregal
Copy link
Member Author

oandregal commented Oct 29, 2018

Update: I'm going to explore update those tests to the react-test-renderer.

Also, I've created #11214 to keep track of workarounds we do to make (the versions we use of) enzyme and enzyme-adapter-react-16 work with React.

<div>
1
</div>,
<button
Copy link
Member Author

@oandregal oandregal Oct 30, 2018

Choose a reason for hiding this comment

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

Note that, previously, we weren't doing snapshot testing and the button component wasn't checked for.

<div>
2
</div>,
<button
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that, previously, we weren't doing snapshot testing and the button component wasn't checked for.

first
second
</div>,
<button
Copy link
Member Author

@oandregal oandregal Oct 30, 2018

Choose a reason for hiding this comment

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

Note that, previously, we weren't doing snapshot testing and the button component wasn't checked for.

@oandregal
Copy link
Member Author

Tests updated - note that tests are migrated in atomic commits one by one so it's easier to compare the changes. This is ready for a second review.

@oandregal oandregal requested a review from a team October 30, 2018 11:06
@oandregal oandregal added the [Status] In Progress Tracking issues with work in progress label Oct 30, 2018
@oandregal oandregal removed the request for review from a team October 30, 2018 11:12
@oandregal
Copy link
Member Author

oandregal commented Oct 30, 2018

mmm, some other tests still need to be migrated:

  • Tooltip
  • Popover
  • PluginPostPublishPanel
  • PluginPrePublishPanel
  • PluginPostStatusInfo

@oandregal
Copy link
Member Author

Tests have been fixed. This is ready for review.

@oandregal oandregal removed the [Status] In Progress Tracking issues with work in progress label Oct 31, 2018
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

It would be nice to move all test updates to their own PR. Ensure it works with master and then upgrade Slot and Fill to the new Context API. Otherwise, it's not that obvious if we didn't break anything.

I also would love to avoid using snapshots for Slot tests as they become very hard to reason after changes introduced. In general they are awesome for UI components, but Slot is more container which doesn't care as much about UI but to ensure that all fills are properly rendered.

packages/components/src/slot-fill/provider.js Show resolved Hide resolved
packages/components/src/slot-fill/index.js Outdated Show resolved Hide resolved
packages/components/src/slot-fill/slot.js Outdated Show resolved Hide resolved
packages/components/src/slot-fill/test/slot.js Outdated Show resolved Hide resolved
@oandregal oandregal changed the base branch from master to update/tests-for-context-api October 31, 2018 16:02
@oandregal
Copy link
Member Author

@gziolo Tests are now in a separate PR at #11314 I've rebased this with that PR, so we can merge cleanly after that lands into master.

@gziolo
Copy link
Member

gziolo commented Oct 31, 2018

Nice work, changes in this PR looks great. There are a few e2e tests which ensure that plugins can extend editor, so I think it also covers Slot and FIll logic indirectly.

@oandregal
Copy link
Member Author

Cool! The base branch is #11314 I'll wait until that's approved and merged, then I'll rebase this with master and will merge.

@oandregal oandregal changed the base branch from update/tests-for-context-api to master November 2, 2018 12:21
@oandregal oandregal merged commit aad371d into master Nov 2, 2018
@oandregal oandregal deleted the update/slotfill-context-api branch November 2, 2018 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants