/**
 * Analytics Main setup component.
 *
 * Site Kit by Google, Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * WordPress dependencies
 */
import { _x } from '@wordpress/i18n';

/**
 * Internal dependencies
 */
import Data from 'googlesitekit-data';
import SetupForm from './setup-form';
import ProgressBar from '../../../components/progress-bar';
import { SvgIcon } from '../../../util';
import { STORE_NAME } from '../datastore';
import { ACCOUNT_CREATE } from '../datastore/constants';
import {
	AccountCreate,
	ErrorNotice,
	ExistingTagError,
} from '../common';
const { useSelect } = Data;

export default function SetupMain( { finishSetup } ) {
	const accounts = useSelect( ( select ) => select( STORE_NAME ).getAccounts() ) || [];
	const accountID = useSelect( ( select ) => select( STORE_NAME ).getAccountID() );
	const hasExistingTag = useSelect( ( select ) => select( STORE_NAME ).hasExistingTag() );
	const existingTagPermission = useSelect( ( select ) => select( STORE_NAME ).hasExistingTagPermission() );
	const isFetchingAccounts = useSelect( ( select ) => select( STORE_NAME ).isFetchingAccounts() );
	const isDoingSubmitChanges = useSelect( ( select ) => select( STORE_NAME ).isDoingSubmitChanges() );
	const isCreateAccount = ACCOUNT_CREATE === accountID;

	let viewComponent;
	if ( isFetchingAccounts || isDoingSubmitChanges ) {
		viewComponent = <ProgressBar />;
	} else if ( hasExistingTag && existingTagPermission === false ) {
		viewComponent = <ExistingTagError />;
	} else if ( ! accounts.length || isCreateAccount ) {
		viewComponent = <AccountCreate />;
	} else {
		viewComponent = <SetupForm finishSetup={ finishSetup } />;
	}

	return (
		<div className="googlesitekit-setup-module googlesitekit-setup-module--analytics">

			<div className="googlesitekit-setup-module__logo">
				<SvgIcon id="analytics" width="33" height="33" />
			</div>

			<h2 className="googlesitekit-heading-3 googlesitekit-setup-module__title">
				{ _x( 'Analytics', 'Service name', 'google-site-kit' ) }
			</h2>

			<ErrorNotice />

			{ viewComponent }
		</div>
	);
}

@@ -1277,14 +1277,8 @@
 () )
- %7C%7C %5B%5D
 ;%0A%09c
@@ -1751,24 +1751,141 @@
 hanges() );%0A
+%09const hasResolvedAccounts = useSelect( ( select ) =%3E select( STORE_NAME ).hasFinishedResolution( 'getAccounts' ) );%0A
 %09const isCre
@@ -1997,16 +1997,41 @@
 Changes 
+%7C%7C ! hasResolvedAccounts 
 ) %7B%0A%09%09vi
@@ -2185,44 +2185,77 @@
 f ( 
-! accounts.length %7C%7C isCreateAccount
+isCreateAccount %7C%7C ( Array.isArray( accounts ) && ! accounts.length )
  ) %7B

Update logic for setup view component to prevent flashes.