Skip to content

POC: bundled components detector #10896

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

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module.exports = {
env: {
production: {
plugins: [
[
'react-remove-properties',
{ properties: [ 'data-wcpay-bundled-wp-component' ] },
],
[
'@wordpress/babel-plugin-makepot',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ export const makeWrappedComponent = <
const context = useContext( WordPressComponentsContext );

if ( ! context || useBundledComponent ) {
// @ts-expect-error: the type of props is not always well-defined, ignoring the error.
return <BundledComponent { ...rest } ref={ ref } />;
return (
// @ts-expect-error: the type of props is not always well-defined, ignoring the error.
<BundledComponent
{ ...rest }
ref={ ref }
data-wcpay-bundled-wp-component="true"
/>
);
}

const ContextComponent = context[
Expand Down
4 changes: 3 additions & 1 deletion client/settings/card-body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* External dependencies
*/
import React, { useContext } from 'react';
import { CardBody as BundledWordPressComponentsCardBody } from 'wcpay/components/wp-components-wrapped';
// eslint-disable-next-line no-restricted-syntax
import { CardBody as BundledWordPressComponentsCardBody } from '@wordpress/components';
import clsx from 'clsx';

/**
Expand All @@ -27,6 +28,7 @@ const WcpayCardBody: React.FC< React.PropsWithChildren<
<BundledWordPressComponentsCardBody
className={ clsx( 'wcpay-card-body', className ) }
{ ...props }
data-wcpay-bundled-wp-component="true"
/>
);
}
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"archiver": "5.2.0",
"babel-eslint": "10.1.0",
"babel-loader": "8.2.2",
"babel-plugin-react-remove-properties": "0.3.0",
"chalk": "4.1.2",
"clsx": "2.1.1",
"config": "3.3.6",
Expand Down
Loading