Move SlotFillProvider to frontend only (https://github.com/woocommerce/woocommerce-blocks/pull/4437)
* Move SlotFillProvider to frontend only * remove extra config for editor scripts * update tests
This commit is contained in:
parent
9975868956
commit
2f440bbe20
|
@ -4,8 +4,6 @@
|
|||
import { PluginArea } from '@wordpress/plugins';
|
||||
import { CURRENT_USER_IS_ADMIN } from '@woocommerce/settings';
|
||||
import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary';
|
||||
import { SlotFillProvider } from '@woocommerce/blocks-checkout';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
|
@ -38,18 +36,16 @@ export const CheckoutProvider = ( {
|
|||
<CustomerDataProvider>
|
||||
<ShippingDataProvider>
|
||||
<PaymentMethodDataProvider>
|
||||
<SlotFillProvider>
|
||||
{ children }
|
||||
{ /* If the current user is an admin, we let BlockErrorBoundary render
|
||||
{ children }
|
||||
{ /* If the current user is an admin, we let BlockErrorBoundary render
|
||||
the error, or we simply die silently. */ }
|
||||
<BlockErrorBoundary
|
||||
renderError={
|
||||
CURRENT_USER_IS_ADMIN ? null : () => null
|
||||
}
|
||||
>
|
||||
<PluginArea scope="woocommerce-checkout" />
|
||||
</BlockErrorBoundary>
|
||||
</SlotFillProvider>
|
||||
<BlockErrorBoundary
|
||||
renderError={
|
||||
CURRENT_USER_IS_ADMIN ? null : () => null
|
||||
}
|
||||
>
|
||||
<PluginArea scope="woocommerce-checkout" />
|
||||
</BlockErrorBoundary>
|
||||
<CheckoutProcessor />
|
||||
</PaymentMethodDataProvider>
|
||||
</ShippingDataProvider>
|
||||
|
|
|
@ -9,7 +9,9 @@ import { __ } from '@wordpress/i18n';
|
|||
import {
|
||||
StoreNoticesProvider,
|
||||
StoreSnackbarNoticesProvider,
|
||||
CartProvider,
|
||||
} from '@woocommerce/base-context/providers';
|
||||
import { SlotFillProvider } from '@woocommerce/blocks-checkout';
|
||||
import { CURRENT_USER_IS_ADMIN } from '@woocommerce/settings';
|
||||
import {
|
||||
renderFrontend,
|
||||
|
@ -31,7 +33,11 @@ const CartFrontend = ( props ) => {
|
|||
return (
|
||||
<StoreSnackbarNoticesProvider context="wc/cart">
|
||||
<StoreNoticesProvider context="wc/cart">
|
||||
<Block { ...props } />
|
||||
<SlotFillProvider>
|
||||
<CartProvider>
|
||||
<Block { ...props } />
|
||||
</CartProvider>
|
||||
</SlotFillProvider>
|
||||
</StoreNoticesProvider>
|
||||
</StoreSnackbarNoticesProvider>
|
||||
);
|
||||
|
|
|
@ -32,7 +32,6 @@ import Title from '@woocommerce/base-components/title';
|
|||
import { getSetting } from '@woocommerce/settings';
|
||||
import { useEffect } from '@wordpress/element';
|
||||
import { decodeEntities } from '@wordpress/html-entities';
|
||||
import { CartProvider } from '@woocommerce/base-context';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -210,12 +209,4 @@ const Cart = ( { attributes }: CartProps ) => {
|
|||
);
|
||||
};
|
||||
|
||||
const Block = ( props: CartProps ): JSX.Element => {
|
||||
return (
|
||||
<CartProvider>
|
||||
<Cart { ...props } />
|
||||
</CartProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export default Block;
|
||||
export default Cart;
|
||||
|
|
|
@ -728,9 +728,6 @@ exports[`Testing cart Contains a Taxes section if Core options are set to show i
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style="display: none;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1469,9 +1466,6 @@ exports[`Testing cart Shows individual tax lines if the store is set to do so 1`
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style="display: none;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -2210,9 +2204,6 @@ exports[`Testing cart Shows rate percentages after tax lines if the block is set
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style="display: none;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -5,15 +5,21 @@ import { render, screen, waitFor } from '@testing-library/react';
|
|||
import { previewCart } from '@woocommerce/resource-previews';
|
||||
import { dispatch } from '@wordpress/data';
|
||||
import { CART_STORE_KEY as storeKey } from '@woocommerce/block-data';
|
||||
import { SlotFillProvider } from '@woocommerce/blocks-checkout';
|
||||
import { default as fetchMock } from 'jest-fetch-mock';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import CartBlock from '../block';
|
||||
import Block from '../block';
|
||||
import { defaultCartState } from '../../../../data/default-states';
|
||||
import { allSettings } from '../../../../settings/shared/settings-init';
|
||||
|
||||
const CartBlock = ( props ) => (
|
||||
<SlotFillProvider>
|
||||
<Block { ...props } />
|
||||
</SlotFillProvider>
|
||||
);
|
||||
describe( 'Testing cart', () => {
|
||||
beforeEach( async () => {
|
||||
fetchMock.mockResponse( ( req ) => {
|
||||
|
|
|
@ -10,7 +10,6 @@ import {
|
|||
ReturnToCartButton,
|
||||
} from '@woocommerce/base-components/cart-checkout';
|
||||
import {
|
||||
CheckoutProvider,
|
||||
useCheckoutContext,
|
||||
useEditorContext,
|
||||
useValidationContext,
|
||||
|
@ -34,20 +33,6 @@ import { CheckoutExpressPayment } from '../payment-methods';
|
|||
import { LOGIN_TO_CHECKOUT_URL } from './utils';
|
||||
import './style.scss';
|
||||
|
||||
/**
|
||||
* Renders the Checkout block wrapped within the CheckoutProvider.
|
||||
*
|
||||
* @param {Object} props Component props.
|
||||
* @return {*} The component.
|
||||
*/
|
||||
const Block = ( props ) => {
|
||||
return (
|
||||
<CheckoutProvider>
|
||||
<Checkout { ...props } />
|
||||
</CheckoutProvider>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Main Checkout Component.
|
||||
*
|
||||
|
@ -163,4 +148,4 @@ const Checkout = ( { attributes, scrollToTop } ) => {
|
|||
);
|
||||
};
|
||||
|
||||
export default withScrollToTop( Block );
|
||||
export default withScrollToTop( Checkout );
|
||||
|
|
|
@ -23,6 +23,7 @@ import {
|
|||
EditorProvider,
|
||||
useEditorContext,
|
||||
StoreNoticesProvider,
|
||||
CheckoutProvider,
|
||||
} from '@woocommerce/base-context';
|
||||
import { CartCheckoutFeedbackPrompt } from '@woocommerce/editor-components/feedback-prompt';
|
||||
import PageSelector from '@woocommerce/editor-components/page-selector';
|
||||
|
@ -382,7 +383,9 @@ const CheckoutEditor = ( { attributes, setAttributes } ) => {
|
|||
>
|
||||
<StoreNoticesProvider context="wc/checkout">
|
||||
<Disabled>
|
||||
<Block attributes={ attributes } />
|
||||
<CheckoutProvider>
|
||||
<Block attributes={ attributes } />
|
||||
</CheckoutProvider>
|
||||
</Disabled>
|
||||
</StoreNoticesProvider>
|
||||
</BlockErrorBoundary>
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
} from '@woocommerce/block-hocs';
|
||||
import { useStoreCart } from '@woocommerce/base-context/hooks';
|
||||
import {
|
||||
CheckoutProvider,
|
||||
StoreNoticesProvider,
|
||||
ValidationContextProvider,
|
||||
} from '@woocommerce/base-context';
|
||||
|
@ -18,6 +19,7 @@ import {
|
|||
getValidBlockAttributes,
|
||||
} from '@woocommerce/base-utils';
|
||||
import { StoreSnackbarNoticesProvider } from '@woocommerce/base-context/providers';
|
||||
import { SlotFillProvider } from '@woocommerce/blocks-checkout';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -59,7 +61,11 @@ const CheckoutFrontend = ( props ) => {
|
|||
<StoreSnackbarNoticesProvider context="wc/checkout">
|
||||
<StoreNoticesProvider context="wc/checkout">
|
||||
<ValidationContextProvider>
|
||||
<Block { ...props } />
|
||||
<SlotFillProvider>
|
||||
<CheckoutProvider>
|
||||
<Block { ...props } />
|
||||
</CheckoutProvider>
|
||||
</SlotFillProvider>
|
||||
</ValidationContextProvider>
|
||||
</StoreNoticesProvider>
|
||||
</StoreSnackbarNoticesProvider>
|
||||
|
|
|
@ -21,8 +21,6 @@ const {
|
|||
CHECK_CIRCULAR_DEPS,
|
||||
requestToExternal,
|
||||
requestToHandle,
|
||||
requestToExternalInsideGB,
|
||||
requestToHandleInsideGB,
|
||||
findModuleMatch,
|
||||
getProgressBarPluginConfig,
|
||||
} = require( './webpack-helpers' );
|
||||
|
@ -148,55 +146,6 @@ woocommerce_blocks_env = ${ NODE_ENV }
|
|||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Build config for core packages, in the editor context.
|
||||
*
|
||||
* This is meant to fix issue #3839 in which we have two instances of SlotFillProvider context. Should be deleted once wordpress/gutenberg#27462.
|
||||
*
|
||||
* @param {Object} options Build options.
|
||||
*/
|
||||
const getCoreEditorConfig = ( options = {} ) => {
|
||||
// @todo delete getCoreEditorConfig when wordpress/gutenberg#27462 or equivalent is merged.
|
||||
return {
|
||||
...getCoreConfig( options ),
|
||||
entry: {
|
||||
blocksCheckout: './packages/checkout/index.js',
|
||||
},
|
||||
output: {
|
||||
filename: ( chunkData ) => {
|
||||
return `${ kebabCase( chunkData.chunk.name ) }-editor.js`;
|
||||
},
|
||||
path: path.resolve( __dirname, '../build/' ),
|
||||
library: [ 'wc', '[name]' ],
|
||||
libraryTarget: 'this',
|
||||
// This fixes an issue with multiple webpack projects using chunking
|
||||
// overwriting each other's chunk loader function.
|
||||
// See https://webpack.js.org/configuration/output/#outputjsonpfunction
|
||||
jsonpFunction: 'webpackWcBlocksJsonp',
|
||||
},
|
||||
plugins: [
|
||||
new DependencyExtractionWebpackPlugin( {
|
||||
injectPolyfill: true,
|
||||
requestToExternal: requestToExternalInsideGB,
|
||||
requestToHandle: requestToHandleInsideGB,
|
||||
} ),
|
||||
new ProgressBarPlugin(
|
||||
getProgressBarPluginConfig( 'Core', options.fileSuffix )
|
||||
),
|
||||
new CreateFileWebpack( {
|
||||
path: './',
|
||||
// file name
|
||||
fileName: 'blocks.ini',
|
||||
// content of the file
|
||||
content: `
|
||||
woocommerce_blocks_phase = ${ process.env.WOOCOMMERCE_BLOCKS_PHASE || 3 }
|
||||
woocommerce_blocks_env = ${ NODE_ENV }
|
||||
`.trim(),
|
||||
} ),
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Build config for Blocks in the editor context.
|
||||
*
|
||||
|
@ -826,5 +775,4 @@ module.exports = {
|
|||
getPaymentsConfig,
|
||||
getExtensionsConfig,
|
||||
getStylingConfig,
|
||||
getCoreEditorConfig,
|
||||
};
|
||||
|
|
|
@ -108,13 +108,6 @@ const requestToExternal = ( request ) => {
|
|||
}
|
||||
};
|
||||
|
||||
const requestToExternalInsideGB = ( request ) => {
|
||||
if ( request === 'wordpress-components' ) {
|
||||
return [ 'wp', 'components' ];
|
||||
}
|
||||
return requestToExternal( request );
|
||||
};
|
||||
|
||||
const requestToHandle = ( request ) => {
|
||||
if ( requiredPackagesInWPLegacy.includes( request ) ) {
|
||||
return false;
|
||||
|
@ -124,13 +117,6 @@ const requestToHandle = ( request ) => {
|
|||
}
|
||||
};
|
||||
|
||||
const requestToHandleInsideGB = ( request ) => {
|
||||
if ( request === 'wordpress-components' ) {
|
||||
return 'wp-components';
|
||||
}
|
||||
return requestToHandle( request );
|
||||
};
|
||||
|
||||
const getProgressBarPluginConfig = ( name, fileSuffix ) => {
|
||||
const isLegacy = fileSuffix && fileSuffix === 'legacy';
|
||||
const progressBarPrefix = isLegacy ? 'Legacy ' : '';
|
||||
|
@ -159,7 +145,5 @@ module.exports = {
|
|||
findModuleMatch,
|
||||
requestToHandle,
|
||||
requestToExternal,
|
||||
requestToHandleInsideGB,
|
||||
requestToExternalInsideGB,
|
||||
getProgressBarPluginConfig,
|
||||
};
|
||||
|
|
|
@ -60,7 +60,7 @@ final class AssetsController {
|
|||
$this->api->register_script( 'wc-price-format', 'build/price-format.js', [], false );
|
||||
|
||||
if ( Package::feature()->is_feature_plugin_build() ) {
|
||||
$this->api->register_script( 'wc-blocks-checkout', is_admin() ? 'build/blocks-checkout-editor.js' : 'build/blocks-checkout.js', [] );
|
||||
$this->api->register_script( 'wc-blocks-checkout', 'build/blocks-checkout.js', [] );
|
||||
}
|
||||
|
||||
wp_add_inline_script(
|
||||
|
|
|
@ -10,7 +10,6 @@ const {
|
|||
getPaymentsConfig,
|
||||
getExtensionsConfig,
|
||||
getStylingConfig,
|
||||
getCoreEditorConfig,
|
||||
} = require( './bin/webpack-configs.js' );
|
||||
|
||||
// Only options shared between all configs should be defined here.
|
||||
|
@ -40,12 +39,6 @@ const CoreConfig = {
|
|||
...getCoreConfig( { alias: getAlias() } ),
|
||||
};
|
||||
|
||||
// Core config for shared libraries to be run inside the editor.
|
||||
const CoreEditorConfig = {
|
||||
...sharedConfig,
|
||||
...getCoreEditorConfig( { alias: getAlias() } ),
|
||||
};
|
||||
|
||||
// Main Blocks config for registering Blocks and for the Editor.
|
||||
const MainConfig = {
|
||||
...sharedConfig,
|
||||
|
@ -173,5 +166,4 @@ module.exports = [
|
|||
ExtensionsConfig,
|
||||
PaymentsConfig,
|
||||
StylingConfig,
|
||||
CoreEditorConfig,
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue