Skip to content

Update SlotFillProvider to the new context API - #11123

Merged
oandregal merged 9 commits into
masterfrom
update/slotfill-context-api
Nov 2, 2018
Merged

oandregal merged 9 commits into
masterfrom
update/slotfill-context-api

Conversation

@oandregal

@oandregal oandregal commented Oct 26, 2018 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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

oandregal commented Oct 29, 2018 •

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
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

oandregal commented Oct 29, 2018 •

Copy link
Copy Markdown
Member Author

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.

@oandregal
oandregal force-pushed the update/slotfill-context-api branch from 875b034 to 4c4a70e Compare October 30, 2018 10:53
<div>
1
</div>,
<button

@oandregal oandregal Oct 30, 2018 •

Copy link
Copy Markdown
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.

<div>
2
</div>,
<button

Copy link
Copy Markdown
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

@oandregal oandregal Oct 30, 2018 •

Copy link
Copy Markdown
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.

@oandregal

Copy link
Copy Markdown
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

oandregal commented Oct 30, 2018 •

Copy link
Copy Markdown
Member Author

mmm, some other tests still need to be migrated:

  • Tooltip
  • Popover
  • PluginPostPublishPanel
  • PluginPrePublishPanel
  • PluginPostStatusInfo

@oandregal

Copy link
Copy Markdown
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

@gziolo gziolo left a comment

Copy link
Copy Markdown
Member

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.

@oandregal
oandregal force-pushed the update/slotfill-context-api branch from ccdf0bb to d04fb12 Compare October 31, 2018 16:02
@oandregal
oandregal changed the base branch from master to update/tests-for-context-api October 31, 2018 16:02
@oandregal

Copy link
Copy Markdown
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

gziolo commented Oct 31, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

@youknowriad youknowriad mentioned this pull request Nov 1, 2018
11 of 12 tasks
@oandregal
oandregal force-pushed the update/tests-for-context-api branch from 6ac3037 to 4e5b61c Compare November 2, 2018 10:40
@oandregal
oandregal force-pushed the update/slotfill-context-api branch from cb19a4e to cc36d71 Compare November 2, 2018 10:41
@youknowriad youknowriad modified the milestones: WordPress 5.0, 4.3 Nov 2, 2018
@oandregal
oandregal force-pushed the update/slotfill-context-api branch from cc36d71 to 08daa84 Compare November 2, 2018 12:21
@oandregal
oandregal changed the base branch from update/tests-for-context-api to master November 2, 2018 12:21
@oandregal
oandregal force-pushed the update/slotfill-context-api branch from 08daa84 to 24a9729 Compare November 2, 2018 12:47
@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