Skip to content

Commit 178da20

Browse files
ockhamjsnajdr
authored andcommitted
Boot: Don't render empty Layout (#26944)
* Boot: Don't render empty Layout * Framework: Don't auto-inject page.js' onClick handler * Layout: Manually add page.js' onClick handler * Install the page.clickHandler on the root layout element * Render empty layout for logged out home page Makes e2e tests happy, should eventually be replaced with some more systematic approach to how to handle logged-out pages and redirects to login page. Co-authored-by: ockham Co-authored-by: jsnajdr
1 parent 65d2764 commit 178da20

File tree

4 files changed

+39
-51
lines changed

4 files changed

+39
-51
lines changed

client/boot/app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const boot = currentUser => {
3333
setupMiddlewares( currentUser, reduxStore );
3434
invoke( project, 'setupMiddlewares', currentUser, reduxStore );
3535
detectHistoryNavigation.start();
36-
page.start( { decodeURLComponents: false } );
36+
page.start( { click: false, decodeURLComponents: false } );
3737
} );
3838
};
3939

client/boot/common.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { getSections } from 'sections-helper';
2626
import { checkFormHandler } from 'lib/protect-form';
2727
import notices from 'notices';
2828
import authController from 'auth/controller';
29+
import { makeLayout, render as clientRender } from 'controller';
2930

3031
const debug = debugFactory( 'calypso' );
3132

@@ -102,9 +103,10 @@ const loggedOutMiddleware = currentUser => {
102103
}
103104
} );
104105
} else if ( config.isEnabled( 'devdocs/redirect-loggedout-homepage' ) ) {
105-
page( '/', () => {
106-
page.redirect( '/devdocs/start' );
107-
} );
106+
page( '/', '/devdocs/start' );
107+
} else {
108+
// render an empty layout with masterbar links for logged-out home page
109+
page( '/', makeLayout, clientRender );
108110
}
109111

110112
const validSections = getSections().reduce( ( acc, section ) => {

client/boot/project/wordpress-com.js

+25-46
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* External dependencies
44
*/
55
import { startsWith } from 'lodash';
6-
import React from 'react';
7-
import ReactDom from 'react-dom';
86
import store from 'store';
97
import page from 'page';
108
import debugFactory from 'debug';
@@ -31,22 +29,9 @@ import { setNextLayoutFocus, activateNextLayoutFocus } from 'state/ui/layout-foc
3129
import Logger from 'lib/catch-js-errors';
3230
import setupMySitesRoute from 'my-sites';
3331
import setupGlobalKeyboardShortcuts from 'lib/keyboard-shortcuts/global';
34-
import * as controller from 'controller';
3532

3633
const debug = debugFactory( 'calypso' );
3734

38-
function renderLayout( reduxStore ) {
39-
const Layout = controller.ReduxWrappedLayout;
40-
41-
const layoutElement = React.createElement( Layout, {
42-
store: reduxStore,
43-
} );
44-
45-
ReactDom.render( layoutElement, document.getElementById( 'wpcom' ) );
46-
47-
debug( 'Main layout rendered.' );
48-
}
49-
5035
export const configureReduxStore = ( currentUser, reduxStore ) => {
5136
debug( 'Executing WordPress.com configure Redux store.' );
5237

@@ -74,38 +59,32 @@ export function setupMiddlewares( currentUser, reduxStore ) {
7459
analytics.setSuperProps( superProps );
7560
}
7661

77-
// Render Layout only for non-isomorphic sections.
78-
// Isomorphic sections will take care of rendering their Layout last themselves.
79-
if ( ! document.getElementById( 'primary' ) ) {
80-
renderLayout( reduxStore );
81-
82-
if ( config.isEnabled( 'catch-js-errors' ) ) {
83-
const errorLogger = new Logger();
84-
//Save errorLogger to a singleton for use in arbitrary logging.
85-
require( 'lib/catch-js-errors/log' ).registerLogger( errorLogger );
86-
//Save data to JS error logger
87-
errorLogger.saveDiagnosticData( {
88-
user_id: currentUser.get().ID,
89-
calypso_env: config( 'env_id' ),
90-
} );
91-
errorLogger.saveDiagnosticReducer( function() {
92-
const state = reduxStore.getState();
93-
return {
94-
blog_id: getSelectedSiteId( state ),
95-
calypso_section: getSectionName( state ),
96-
};
97-
} );
98-
errorLogger.saveDiagnosticReducer( () => ( { tests: getSavedVariations() } ) );
99-
analytics.on( 'record-event', ( eventName, eventProperties ) =>
100-
errorLogger.saveExtraData( { lastTracksEvent: eventProperties } )
62+
if ( config.isEnabled( 'catch-js-errors' ) && ! document.getElementById( 'primary' ) ) {
63+
const errorLogger = new Logger();
64+
//Save errorLogger to a singleton for use in arbitrary logging.
65+
require( 'lib/catch-js-errors/log' ).registerLogger( errorLogger );
66+
//Save data to JS error logger
67+
errorLogger.saveDiagnosticData( {
68+
user_id: currentUser.get().ID,
69+
calypso_env: config( 'env_id' ),
70+
} );
71+
errorLogger.saveDiagnosticReducer( function() {
72+
const state = reduxStore.getState();
73+
return {
74+
blog_id: getSelectedSiteId( state ),
75+
calypso_section: getSectionName( state ),
76+
};
77+
} );
78+
errorLogger.saveDiagnosticReducer( () => ( { tests: getSavedVariations() } ) );
79+
analytics.on( 'record-event', ( eventName, eventProperties ) =>
80+
errorLogger.saveExtraData( { lastTracksEvent: eventProperties } )
81+
);
82+
page( '*', function( context, next ) {
83+
errorLogger.saveNewPath(
84+
context.canonicalPath.replace( getSiteFragment( context.canonicalPath ), ':siteId' )
10185
);
102-
page( '*', function( context, next ) {
103-
errorLogger.saveNewPath(
104-
context.canonicalPath.replace( getSiteFragment( context.canonicalPath ), ':siteId' )
105-
);
106-
next();
107-
} );
108-
}
86+
next();
87+
} );
10988
}
11089

11190
// If `?sb` or `?sp` are present on the path set the focus of layout

client/layout/index.jsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import React, { Component } from 'react';
88
import { connect } from 'react-redux';
99
import classnames from 'classnames';
10+
import page from 'page';
1011

1112
/**
1213
* Internal dependencies
@@ -59,6 +60,11 @@ class Layout extends Component {
5960
colorSchemePreference: PropTypes.string,
6061
};
6162

63+
// Intercepts <a href> clicks in the document and passes them to the `page` router to handle.
64+
// If the link is internal to Calypso, the router will handle the navigation with `pushState`
65+
// instead of letting the browser reload the whole app by performing a classic navigation.
66+
pageClickHandler = e => page.clickHandler( e.nativeEvent );
67+
6268
render() {
6369
const sectionClass = classnames(
6470
'layout',
@@ -78,7 +84,8 @@ class Layout extends Component {
7884
} );
7985

8086
return (
81-
<div className={ sectionClass }>
87+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
88+
<div className={ sectionClass } onClick={ this.pageClickHandler }>
8289
<DocumentHead />
8390
<QuerySites primaryAndRecent />
8491
<QuerySites allSites />

0 commit comments

Comments
 (0)