Skip to content
Merged
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
3 changes: 1 addition & 2 deletions client/layout/masterbar/logged-in.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import Item from './item';
import Masterbar from './masterbar';
import { AgentsManagerIcon } from './masterbar-agents-manager/agents-manager-icon';
import { HelpCenterIcon } from './masterbar-help-center/help-center-icon';
import { MasterbarLaunchButton } from './masterbar-launch-button';
import Notifications from './masterbar-notifications/notifications-button';

class MasterbarLoggedIn extends Component {
Expand Down Expand Up @@ -618,7 +617,7 @@ class MasterbarLoggedIn extends Component {
return null;
}

return <MasterbarLaunchButton siteId={ siteId } />;
return <AsyncLoad require="./masterbar-launch-button" placeholder={ null } siteId={ siteId } />;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that AsyncLoad can't be server rendered, it's internal <Suspense> element can't be serialised by vanilla React. I merged #109543 to work around this issue for the help centre icon, but I think we could maybe do a "simpler" solution for the MasterbarLaunchButton?

The issue is that master-bar-launch-button.tsx imports lib/explat, which then sets up the anonId at the module level. No way of avoiding it once you've imported lib/explat.

This is some untested code. We could switch the useExperiment call in master-bar-launch-button.tsx out for a hook like this.

function useAsyncExperiment( experimentName: string ) {
	const [ result, setResult ] = useState( [ true, null ] );

	useEffect( () => {
		let isSubscribed = true;
		import ('calypso/lib/explat').then( ( { loadExperimentAssignment } ) => {
			if ( isSubscribed ) {
				loadExperimentAssignment( experimentName ).then( ( data ) => {
					if ( isSubscribed ) {
						setResult( [ false, data ] );
					}
				} );
			}
		} );
		return () => {
			isSubscribed = false;
		};
	}, [ experimentName ] );

	return result;
}

But even this might be more complicated than necessary. See question in the comment above.

}

renderProfileMenu() {
Expand Down
4 changes: 3 additions & 1 deletion client/layout/masterbar/masterbar-launch-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { launchSiteOrRedirectToLaunchSignupFlow } from 'calypso/state/sites/laun
import { getSite } from 'calypso/state/sites/selectors';
import Item from './item';

export const MasterbarLaunchButton = ( { siteId }: { siteId: number } ) => {
const MasterbarLaunchButton = ( { siteId }: { siteId: number } ) => {
const translate = useTranslate();
const dispatch = useDispatch();
const site = useSelector( ( state ) => getSite( state, siteId ) );
Expand Down Expand Up @@ -81,3 +81,5 @@ export const MasterbarLaunchButton = ( { siteId }: { siteId: number } ) => {
</>
);
};

export default MasterbarLaunchButton;
Loading