Skip to content
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

Try #2: Upgrade @wordpress packages to pre-React 18 #73890

Merged
merged 56 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
4819ea4
Update packages to pre- react 18 versions
tyxla Feb 28, 2023
1e7cf25
Noop some type packages with stale @wordpress/data module declarations
tyxla Feb 28, 2023
88e7597
Fix some TS errors
tyxla Feb 9, 2023
afb5603
Fix some unit tests
tyxla Feb 9, 2023
a63151a
Fix TS errors in wpcom-checkout
tyxla Feb 9, 2023
266cc23
Fix more TS errors
tyxla Feb 13, 2023
ba554bb
Fix TS errors in wpcom-plans-ui data store
tyxla Feb 28, 2023
868db66
Fix a bunch of other TS errors
tyxla Feb 13, 2023
2760aa8
Fix a bunch of other TS errors
tyxla Feb 13, 2023
bb07c00
Fix a bunch more TS errors
tyxla Feb 13, 2023
97bdf7f
Fix type confusion
tyxla Feb 13, 2023
990750a
Add core/data temp placeholder types
tyxla Feb 13, 2023
6b1ac77
deduplicate packages
tyxla Feb 28, 2023
787a9f2
Ignore some logs
tyxla Feb 28, 2023
2fd2d15
Fix another failing test
tyxla Feb 14, 2023
0684633
Fix a couple more tests
tyxla Feb 14, 2023
b8e4a20
Fix a bad import
tyxla Feb 14, 2023
39c8d53
Force @wordpress/element resolution
tyxla Feb 28, 2023
3070be4
Fix more code style errors
tyxla Feb 23, 2023
3f7ba02
Fix some code style errors
tyxla Feb 23, 2023
684a109
Declare TS modules of the nooped types
tyxla Feb 28, 2023
c6ffa97
Pin @wordpress/data-controls version
tyxla Feb 28, 2023
5489d74
Fix a ton of ETK TS errors
tyxla Mar 2, 2023
62fc636
Remove some undesired obsolete type packages
tyxla Mar 2, 2023
0131606
Restore @wordpress/data-controls types
tyxla Mar 2, 2023
6aca0fd
Add necessary @wordpress/blocks types inline
tyxla Mar 2, 2023
9254527
Remove a duplicate __i18n_text_domain__
tyxla Mar 2, 2023
3fd901e
Dedupe again
tyxla Mar 2, 2023
ebc0e59
Revert "Remove a duplicate __i18n_text_domain__"
tyxla Mar 2, 2023
ec4d5a6
Workaround a __i18n_text_domain__ duplication
tyxla Mar 2, 2023
bb7139d
Fix a bunch of store and checkout TS errors
tyxla Mar 2, 2023
9487ea0
Fix more package TS errors
tyxla Mar 2, 2023
e684094
Start fixing some more TS errors
tyxla Mar 6, 2023
93bdb81
More TS fixes
tyxla Mar 7, 2023
e026b9e
Fix a bunch more TS errors
tyxla Mar 7, 2023
5971e49
More TS error fixes
tyxla Mar 7, 2023
80003b4
Fix some imports
tyxla Mar 7, 2023
217d151
More TS errors
tyxla Mar 7, 2023
25f49de
Fix bad import
tyxla Mar 7, 2023
effc4d7
A few more TS fixes
tyxla Mar 7, 2023
9c29f87
More TS errors fixed
tyxla Mar 7, 2023
ebb6b5d
Add @automattic/global-styles to tsconfig references
tyxla Mar 7, 2023
00f0469
Fix a few more type errors
tyxla Mar 7, 2023
cc70ca0
Fix a few more TS errors
tyxla Mar 7, 2023
a012406
Ignore another log entry
tyxla Mar 8, 2023
c88396f
Fix more TS errors
tyxla Mar 8, 2023
7e8bd30
Pin @wordpress/base-styles
tyxla Mar 8, 2023
2891422
Revert @wordpress/env upgrade
tyxla Mar 8, 2023
ed8ceb8
Add missing select dependency
noahtallen Mar 8, 2023
6b61059
Add missing data dependencies to useSelect calls
noahtallen Mar 8, 2023
11edb1a
Remove some now uneeded ts-ignore lines
noahtallen Mar 8, 2023
d740121
Polish some useSelect dependencies
tyxla Mar 9, 2023
3f2cac9
Polish another useSelect data dependency
noahtallen Mar 9, 2023
c5df3e5
Account for possibly undefined stores
noahtallen Mar 9, 2023
cd45678
Add more data dependencies to useSelect calls
noahtallen Mar 10, 2023
b8a0f10
Fix render loop caused by obj reference changing each render
noahtallen Mar 10, 2023
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
23 changes: 7 additions & 16 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ logFilters:
pattern: "@automattic/global-styles@workspace:packages/global-styles provides react-dom (*) with version 17.0.2, which doesn't satisfy what @wordpress/block-editor and some of its descendants request"
- level: discard
pattern: "@automattic/global-styles@workspace:packages/global-styles provides react-dom (*) with version 17.0.2, which doesn't satisfy what @wordpress/components and some of its descendants request"
- level: discard
pattern: "@wordpress/data-controls@npm:2.27.0 doesn't provide react (p90380), requested by @wordpress/data"
- level: discard
pattern: "@wordpress/notices@npm:3.27.0 doesn't provide react (pcdad4), requested by @wordpress/data"
- level: discard
pattern: "calypso@workspace:client provides @wordpress/data (pd64ed) with version 7.6.0, which doesn't satisfy what @automattic/subscription-manager requests"

nodeLinker: node-modules

Expand All @@ -123,28 +129,13 @@ packageExtensions:
"@signal-noise/[email protected]":
peerDependencies:
postcss: "*"
"@types/[email protected]":
peerDependencies:
react: "*"
react-dom: "*"
"@types/[email protected]":
peerDependencies:
react: "*"
"@types/[email protected]":
peerDependencies:
react: "*"
"@types/[email protected]":
peerDependencies:
react: "*"
react-dom: "*"
"@types/[email protected]":
peerDependencies:
react: "*"
react-dom: "*"
"@types/[email protected]":
peerDependencies:
react: "*"
"@wordpress/stylelint-config@20.0.3":
"@wordpress/stylelint-config@21.10.0":
peerDependencies:
postcss: "*"
[email protected]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { inIframe } from '../../block-inserter-modifications/contextual-tips/uti
import { IMMEDIATE_LAUNCH_QUERY_ARG } from './constants';
import { LAUNCH_STORE, SITE_STORE } from './stores';
import { openCheckout, redirectToWpcomPath, getCurrentLaunchFlowUrl } from './utils';
import type { LaunchSelect, SiteSelect } from '@automattic/data-stores';

const registerPlugin = ( name: string, settings: Omit< PluginSettings, 'icon' > ) =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -17,12 +18,12 @@ registerPlugin( 'a8c-editor-editor-focused-launch', {
const currentSiteId = window._currentSiteId;

const isSiteLaunched = useSelect(
( select ) => select( SITE_STORE ).isSiteLaunched( currentSiteId ),
( select ) => ( select( SITE_STORE ) as SiteSelect ).isSiteLaunched( currentSiteId ),
[ currentSiteId ]
);

const { isFocusedLaunchOpen, isAnchorFm } = useSelect(
( select ) => select( LAUNCH_STORE ).getState(),
( select ) => ( select( LAUNCH_STORE ) as LaunchSelect ).getState(),
[]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ import { FLOW_ID } from './constants';
import LaunchModal from './launch-modal';
import { LAUNCH_STORE } from './stores';
import { openCheckout, redirectToWpcomPath, getCurrentLaunchFlowUrl } from './utils';
import type { LaunchSelect } from '@automattic/data-stores';

const registerPlugin = ( name: string, settings: Omit< PluginSettings, 'icon' > ) =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
originalRegisterPlugin( name, settings as any );

registerPlugin( 'a8c-editor-site-launch', {
render: function LaunchSidebar() {
const { isSidebarOpen } = useSelect( ( select ) => select( LAUNCH_STORE ).getState() );
const { isSidebarOpen } = useSelect(
( select ) => ( select( LAUNCH_STORE ) as LaunchSelect ).getState(),
[]
);
const { closeSidebar, setSidebarFullscreen, unsetSidebarFullscreen } =
useDispatch( LAUNCH_STORE );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as React from 'react';
import { LAUNCH_STORE } from '../stores';
import LaunchMenuItem from './item';
import type { LaunchStepType } from '../../../common/data-stores/launch';
import type { LaunchSelect } from '@automattic/data-stores';

import './styles.scss';

Expand All @@ -16,15 +17,16 @@ const LaunchMenu: React.FunctionComponent< Props > = ( { onMenuItemClick } ) =>

const { currentStep, LaunchStep, LaunchSequence, isStepCompleted, isFlowCompleted } = useSelect(
( select ) => {
const launchStore = select( LAUNCH_STORE );
const launchStore: LaunchSelect = select( LAUNCH_STORE );
return {
currentStep: launchStore.getCurrentStep(),
LaunchStep: launchStore.getLaunchStep(),
LaunchSequence: launchStore.getLaunchSequence(),
isStepCompleted: launchStore.isStepCompleted,
isFlowCompleted: launchStore.isFlowCompleted(),
};
}
},
[]
);

const LaunchStepMenuItemTitles = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Launch from '../launch';
import LaunchProgress from '../launch-progress';
import LaunchSidebar from '../launch-sidebar';
import { LAUNCH_STORE, SITE_STORE, PLANS_STORE } from '../stores';
import type { LaunchSelect, PlansSelect } from '@automattic/data-stores';

import './styles.scss';

Expand All @@ -21,8 +22,9 @@ interface Props {
const LaunchModal: React.FunctionComponent< Props > = ( { onClose, isLaunchImmediately } ) => {
const { siteId } = React.useContext( LaunchContext );

const { step: currentStep, isSidebarFullscreen } = useSelect( ( select ) =>
select( LAUNCH_STORE ).getState()
const { step: currentStep, isSidebarFullscreen } = useSelect(
( select ) => ( select( LAUNCH_STORE ) as LaunchSelect ).getState(),
[]
);
const [ isLaunching, setIsLaunching ] = React.useState( false );
const [ isImmediateLaunchStarted, setIsImmediateLaunchStarted ] = React.useState( false );
Expand All @@ -32,8 +34,9 @@ const LaunchModal: React.FunctionComponent< Props > = ( { onClose, isLaunchImmed

const locale = useLocale();
const { setPlanProductId } = useDispatch( LAUNCH_STORE );
const defaultFreePlan = useSelect( ( select ) =>
select( PLANS_STORE ).getDefaultFreePlan( locale )
const defaultFreePlan = useSelect(
( select ) => ( select( PLANS_STORE ) as PlansSelect ).getDefaultFreePlan( locale ),
noahtallen marked this conversation as resolved.
Show resolved Hide resolved
[ locale ]
);

const handleLaunch = React.useCallback( () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ import { sprintf } from '@wordpress/i18n';
import { useI18n } from '@wordpress/react-i18n';
import * as React from 'react';
import { LAUNCH_STORE } from '../stores';
import type { LaunchSelect } from '@automattic/data-stores';

import './styles.scss';

const LaunchProgress: React.FunctionComponent = () => {
const { __ } = useI18n();

const { currentStep, LaunchSequence } = useSelect( ( select ) => {
const launchStore = select( LAUNCH_STORE );
const launchStore: LaunchSelect = select( LAUNCH_STORE );
return {
currentStep: launchStore.getCurrentStep(),
LaunchSequence: launchStore.getLaunchSequence(),
};
} );
}, [] );

const current = LaunchSequence.indexOf( currentStep ) + 1;
const total = LaunchSequence.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { __ } from '@wordpress/i18n';
import * as React from 'react';
import LaunchMenu from '../launch-menu';
import { LAUNCH_STORE } from '../stores';

import type { LaunchSelect } from '@automattic/data-stores';
import './styles.scss';

const LaunchSidebar: React.FunctionComponent = () => {
const { setStep, unsetSidebarFullscreen } = useDispatch( LAUNCH_STORE );

const LaunchSequence = useSelect( ( select ) => select( LAUNCH_STORE ).getLaunchSequence() );
const LaunchSequence = useSelect(
( select ) => ( select( LAUNCH_STORE ) as LaunchSelect ).getLaunchSequence(),
[]
);

const handleStart = () => {
setStep( LaunchSequence[ 0 ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import classnames from 'classnames';
import * as React from 'react';
import LaunchStepContainer, { Props as LaunchStepProps } from '../../launch-step';
import { LAUNCH_STORE, PLANS_STORE } from '../../stores';
import type { LaunchSelect, PlansSelect } from '@automattic/data-stores';

import './styles.scss';

Expand All @@ -30,24 +31,28 @@ const TickIcon = <Icon icon={ check } size={ 17 } />;
const FinalStep: React.FunctionComponent< LaunchStepProps > = ( { onNextStep, onPrevStep } ) => {
const { domain, LaunchStep, isStepCompleted, isFlowCompleted, planProductId } = useSelect(
( select ) => {
const launchStore = select( LAUNCH_STORE );
const launchStore: LaunchSelect = select( LAUNCH_STORE );
return {
domain: launchStore.getSelectedDomain(),
LaunchStep: launchStore.getLaunchStep(),
isStepCompleted: launchStore.isStepCompleted,
isFlowCompleted: launchStore.isFlowCompleted(),
planProductId: launchStore.getSelectedPlanProductId(),
};
}
},
[]
);

const { __, hasTranslation } = useI18n();
const locale = useLocale();

const [ plan, planProduct ] = useSelect( ( select ) => [
select( PLANS_STORE ).getPlanByProductId( planProductId, locale ),
select( PLANS_STORE ).getPlanProductById( planProductId ),
] );
const { plan, planProduct } = useSelect(
( select ) => ( {
plan: ( select( PLANS_STORE ) as PlansSelect ).getPlanByProductId( planProductId, locale ),
planProduct: ( select( PLANS_STORE ) as PlansSelect ).getPlanProductById( planProductId ),
} ),
[ planProductId, locale ]
);

const { title } = useTitle();
const { siteSubdomain } = useSiteDomains();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import { __, sprintf } from '@wordpress/i18n';
import * as React from 'react';
import LaunchStepContainer, { Props as LaunchStepProps } from '../../launch-step';
import { LAUNCH_STORE } from '../../stores';
import type { LaunchSelect } from '@automattic/data-stores';

import './styles.scss';

const PlanStep: React.FunctionComponent< LaunchStepProps > = ( { onPrevStep, onNextStep } ) => {
const { domain, LaunchStep, selectedPlanProductId } = useSelect( ( select ) => {
const launchStore = select( LAUNCH_STORE );
const launchStore: LaunchSelect = select( LAUNCH_STORE );
return {
domain: launchStore.getSelectedDomain(),
LaunchStep: launchStore.getLaunchStep(),
selectedPlanProductId: launchStore.getSelectedPlanProductId(),
};
} );
}, [] );

const { setPlanProductId, setStep } = useDispatch( LAUNCH_STORE );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@ import FinalStep from '../launch-steps/final-step';
import NameStep from '../launch-steps/name-step';
import PlanStep from '../launch-steps/plan-step';
import { LAUNCH_STORE } from '../stores';
import type { LaunchSelect } from '@automattic/data-stores';

interface Props {
onSubmit?: () => void;
}

const Launch: React.FunctionComponent< Props > = ( { onSubmit } ) => {
const { step: currentStep } = useSelect( ( select ) => select( LAUNCH_STORE ).getState() );

const LaunchStep = useSelect( ( select ) => select( LAUNCH_STORE ).getLaunchStep() );
const LaunchSequence = useSelect( ( select ) => select( LAUNCH_STORE ).getLaunchSequence() );
const firstIncompleteStep = useSelect( ( select ) =>
select( LAUNCH_STORE ).getFirstIncompleteStep()
const { step: currentStep } = useSelect(
( select ) => ( select( LAUNCH_STORE ) as LaunchSelect ).getState(),
[]
);
const LaunchStep = useSelect(
( select ) => ( select( LAUNCH_STORE ) as LaunchSelect ).getLaunchStep(),
[]
);
const LaunchSequence = useSelect(
( select ) => ( select( LAUNCH_STORE ) as LaunchSelect ).getLaunchSequence(),
[]
);
const firstIncompleteStep = useSelect(
( select ) => ( select( LAUNCH_STORE ) as LaunchSelect ).getFirstIncompleteStep(),
[]
);

const { setStep, setSidebarFullscreen, unsetSidebarFullscreen } = useDispatch( LAUNCH_STORE );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { useCallback } from '@wordpress/element';
import { addFilter, removeFilter } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';

import { selectors as starterPageTemplatesSelectors } from '../starter-page-templates/store';
import type { SelectFromMap } from '@automattic/data-stores';
import '@wordpress/nux';

const INSERTING_HOOK_NAME = 'isInsertingPagePattern';
Expand All @@ -12,6 +13,17 @@ const INSERTING_HOOK_NAMESPACE = 'automattic/full-site-editing/inserting-pattern
interface PagePatternsPluginProps {
patterns: PatternDefinition[];
}
type StarterPageTemplatesSelectors = SelectFromMap< typeof starterPageTemplatesSelectors >;
type CoreEditorPlaceholder = {
getBlocks: ( ...args: unknown[] ) => Array< { name: string; clientId: string } >;
getEditedPostAttribute: ( ...args: unknown[] ) => unknown;
};
type CoreEditPostPlaceholder = {
isFeatureActive: ( ...args: unknown[] ) => boolean;
};
type CoreNuxPlaceholder = {
areTipsEnabled: ( ...args: unknown[] ) => boolean;
};

export function PagePatternsPlugin( props: PagePatternsPluginProps ) {
const { setOpenState } = useDispatch( 'automattic/starter-page-layouts' );
Expand All @@ -22,12 +34,16 @@ export function PagePatternsPlugin( props: PagePatternsPluginProps ) {
const { disableTips } = useDispatch( 'core/nux' );

const selectProps = useSelect( ( select ) => {
const { isOpen, isPatternPicker } = select( 'automattic/starter-page-layouts' );
const { isOpen, isPatternPicker }: StarterPageTemplatesSelectors = select(
'automattic/starter-page-layouts'
);
return {
isOpen: isOpen(),
isWelcomeGuideActive: select( 'core/edit-post' ).isFeatureActive( 'welcomeGuide' ) as boolean, // Gutenberg 7.2.0 or higher
isWelcomeGuideActive: (
select( 'core/edit-post' ) as CoreEditPostPlaceholder
).isFeatureActive( 'welcomeGuide' ) as boolean, // Gutenberg 7.2.0 or higher
areTipsEnabled: select( 'core/nux' )
? ( select( 'core/nux' ).areTipsEnabled() as boolean )
? ( ( select( 'core/nux' ) as CoreNuxPlaceholder ).areTipsEnabled() as boolean )
: false, // Gutenberg 7.1.0 or lower
...( isPatternPicker() && {
title: __( 'Choose a Pattern', 'full-site-editing' ),
Expand All @@ -37,21 +53,22 @@ export function PagePatternsPlugin( props: PagePatternsPluginProps ) {
),
} ),
};
} );
}, [] );

const { getMeta, postContentBlock } = useSelect( ( select ) => {
const getMeta = () => select( 'core/editor' ).getEditedPostAttribute( 'meta' );
const currentBlocks = select( 'core/editor' ).getBlocks();
const getMeta = () =>
( select( 'core/editor' ) as CoreEditorPlaceholder ).getEditedPostAttribute( 'meta' );
const currentBlocks = ( select( 'core/editor' ) as CoreEditorPlaceholder ).getBlocks();
return {
getMeta,
postContentBlock: currentBlocks.find( ( block ) => block.name === 'a8c/post-content' ),
};
} );
}, [] );

const savePatternChoice = useCallback(
( name: string ) => {
// Save selected pattern slug in meta.
const currentMeta = getMeta();
const currentMeta = getMeta() as Record< string, unknown >;
editPost( {
meta: {
...currentMeta,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const actions = {
} ),
};

const selectors = {
export const selectors = {
isOpen: ( state: OpenState ): boolean => 'CLOSED' !== state,
isPatternPicker: ( state: OpenState ): boolean => 'OPEN_FOR_BLANK_CANVAS' === state,
};
Expand All @@ -30,11 +30,3 @@ registerStore( STORE_KEY, {
actions,
selectors,
} );

declare module '@wordpress/data' {
function dispatch( key: 'automattic/starter-page-layouts' ): typeof actions;
function select( key: 'automattic/starter-page-layouts' ): {
isOpen: () => ReturnType< typeof selectors.isOpen >;
isPatternPicker: () => ReturnType< typeof selectors.isPatternPicker >;
};
}
Loading