Skip to content

[DataViews]: introduce DataViewsContainer component #102987

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

Closed
wants to merge 7 commits into from

Conversation

retrofox
Copy link
Contributor

@retrofox retrofox commented Apr 29, 2025

Closes WOOA7S-124

Note

This PR is one of two alternative approaches currently being explored for improving DataViews composition.
Please also see [DataViews]: Support dual rendering mode (controlled props or free composition) #102996 for the other direction we’re considering.

Introduce DataViewsProvider, a new wrapper component that allows free composition using the existing DataViewsContext.

Why are these changes being made?

Our goal was to enable a more flexible usage of DataViews, where developers can access data and shared config from context, without relying on the built-in layout rendering or manually passing props through the component tree.

We initially explored supporting both "controlled" (rendered) and "headless" (composed via children) behaviors directly within the DataViews component.
However, this approach introduced complex conditional prop logic and made type inference unstable, particularly when working with optional children and conditional data/view combinations.

Additionally, this duality made the TypeScript definitions fragile and more complex to maintain or extend. In multiple iterations, we encountered type assertion issues, context mismatches, etc.

To reduce maintenance risk and preserve backward compatibility (both in runtime behavior and type definitions), we opted to create DataViewsProvider as a lightweight facade. It provides only the context layer, allowing custom rendering logic while preserving the same context shape and types.

This setup also ensures we keep the DataViews component aligned with Gutenberg’s implementation, minimizing divergence and simplifying future upstream merges.

Testing Instructions

  • Run yarn dataviews:storybook:start
  • Verify that DataViewsProvider renders correctly using FreeComposition story.
image
  • Confirm DataViews behavior remains unchanged in all existing stories.

⚠️ react-docgen-typescript has known issues parsing advanced generic types. We’ve added a scoped override to ignore props from DataViewsProvider in Storybook docgen to avoid build-time crashes.
See: styleguidist/react-docgen-typescript#356

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@matticbot matticbot added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Apr 29, 2025
Copy link

github-actions bot commented Apr 29, 2025

@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, this is close to what I had in my, but why a new component instead of just passing the "children" prop to the DataViews component.

  • when the children prop is passed to the DataViews It would only render the <DataViewsContext.Provider which it already renders
  • when the children prop is not passed, it would work just like today.

In other words, the DataViews component is the provider when "children" are passed.

Copy link
Contributor Author

retrofox commented Apr 30, 2025

Yes, I know this is the approach we discussed yesterday.

The issue with this “dual” behavior is that I ran into a TypeScript problem I couldn’t solve properly. If we go this route, we might introduce a breaking change at the TS level.

Assuming that’s true, would it still be okay to move forward with an approach that could trigger TS errors when users update the package?

Or should we consider releasing a new major version where TS compatibility is not guaranteed?

@retrofox retrofox changed the title Update/dataviews introduce dataviewsprovider [DataViews]: introduce DataViewsProvider component Apr 30, 2025
@retrofox
Copy link
Contributor Author

Thanks for the PR, this is close to what I had in my, but why a new component instead of just passing the "children" prop to the DataViews component.

@youknowriad this is the PR #102996 that implements what we agreed yesterday, with some notes about the TS issue.

@retrofox retrofox added [Status] In Progress and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Apr 30, 2025
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Apr 30, 2025
@retrofox retrofox force-pushed the update/dataviews-introduce-dataviewsprovider branch from ad87734 to 4eb44a2 Compare April 30, 2025 16:24
@retrofox retrofox requested a review from a team as a code owner April 30, 2025 16:24
@retrofox retrofox changed the title [DataViews]: introduce DataViewsProvider component [DataViews]: introduce DataViewsContainer component Apr 30, 2025
@retrofox retrofox force-pushed the update/dataviews-introduce-dataviewsprovider branch 2 times, most recently from 6e1d398 to 15c6d19 Compare April 30, 2025 16:45
@retrofox retrofox force-pushed the update/dataviews-introduce-dataviewsprovider branch from 15c6d19 to f4c2187 Compare April 30, 2025 16:47
Reduces type duplication and improves maintainability
@retrofox
Copy link
Contributor Author

retrofox commented May 1, 2025

closing in favor of #102996

@retrofox retrofox closed this May 1, 2025
@github-actions github-actions bot removed [Status] In Progress [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels May 1, 2025
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.

3 participants