question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add RegistryProvider to all React apps

See original GitHub issue

Feature Description

In order for all components to have access all datastores, we should wrap all of our React apps with a RegistryProvider to avoid the need to add this provider to each individual component.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • All React apps (e.g. GoogleSitekitDashboard) should wrap their children in a <Root> component.
  • The <Root> component should wrap any app in all of the required components (ErrorHandler, Data.RegistryProvider, etc.)
  • Wrapping should be consistent across all apps

Implementation Brief

  • Create a new component (“Root”) in assets/js/components/root/index.js
  • Wrap children passed to <Root> in <Data.RegistryProvider value={ Data }> and <ErrorHandler>, to begin 😄
  • It likely makes sense to allow a custom registry to be passed to <Root> for testing, so it should accept a registry prop whose default value is Data.
  • Add googlesitekit-data to the common $dependencies array shared by all main entrypoints in Assets::get_assets()

QA Brief

Changelog entry

  • Wrap all JavaScript apps into Root component with essential providers, error handlers etc.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
felixarntzcommented, May 12, 2020

Thanks for the additional context @aaemnnosttv and @tofumatt! That all sounds good to me, IB ✅

Let’s stick with consistently using lowercase file/directory names for components for now, this is not the right point to change it. I’m in favor of making the change overall (as I think it’s a great way to easily differentiate components), but it should happen with a separate issue at some point.

1reaction
aaemnnosttvcommented, May 8, 2020

The main advantage here at this point is I guess that we don’t need to wrap our refactored components with a RegistryProvider every time, like we’re doing so far?

Yeah. The registry is just provided via Context to all child components. We only need it once so it makes component refactoring simpler as well. I’ve added this issue as a dependency of #1531 for this reason.

Let’s make sure there are no downsides to all the legacy code also being within this provider.

There should be no downside to adding this. I would imagine that if there was @tofumatt would have flagged that but a quick POC shows that everything seems to work fine 😄

One thing I did notice though is that we need to also enqueue googlesitekit-data everywhere as well. I’ll add this to the IB.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building a Component Registry in React - Medium
What if you have a list of hundred of components but your project just uses a few and you don't need to import...
Read more >
Create a New React App
Create React App is a comfortable environment for learning React, and is the best way to start building a new single-page application in...
Read more >
Context - React
Context provides a way to pass data through the component tree without having to pass props down manually at every level. In a...
Read more >
Components and Props - React
The simplest way to define a component is to write a JavaScript function: ... A button, a form, a dialog, a screen: in...
Read more >
@wordpress/data - npm
WordPress' data module serves as a hub to manage application state for ... Use the register function to add your own store to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found