Skip to content

Commit

Permalink
Add: Possibility to tree shake DataViewsProvider. (#55641)
Browse files Browse the repository at this point in the history
* Add: Possibility to tree shake DataViewsProvider.

* Remove redundant check for __experimentalAdminViews

---------

Co-authored-by: Miguel Fonseca <[email protected]>
  • Loading branch information
jorgefilipecosta and mcsf authored Oct 26, 2023
1 parent 8aaac1a commit 0869790
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/edit-site/src/components/dataviews/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
* WordPress dependencies
*/
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { useEffect, useState, useRef, useMemo } from '@wordpress/element';
import {
useEffect,
useState,
useRef,
useMemo,
Fragment,
} from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

Expand Down Expand Up @@ -236,18 +242,29 @@ function DataviewsProviderInner( { type, children } ) {
</DataviewsContext.Provider>
);
}
export default function DataviewsProvider( { children } ) {
function DataviewsProvider( { children } ) {
const {
params: { path },
} = useLocation();
const viewType = PATH_TO_DATAVIEW_TYPE[ path ];

if ( window?.__experimentalAdminViews && viewType ) {
if ( viewType ) {
return (
<DataviewsProviderInner type={ viewType }>
{ children }
</DataviewsProviderInner>
);
}
return <> { children }</>;
return <>{ children }</>;
}

let DataviewsProviderExported = Fragment;

// This condition must stand on its own for correct tree-shaking
if ( process.env.IS_GUTENBERG_PLUGIN ) {
if ( window?.__experimentalAdminViews ) {
DataviewsProviderExported = DataviewsProvider;
}
}

export default DataviewsProviderExported;

0 comments on commit 0869790

Please sign in to comment.