Skip to content

Commit 542b45e

Browse files
authored
Merge pull request #5396 from HSLdevcom/DT-6904
DT-6904 Remove support for server-side rendering
2 parents 9937e53 + 0720fff commit 542b45e

File tree

108 files changed

+525
-2915
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+525
-2915
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ ENV \
9797
# the --title option just sets the harmless property process.title
9898
# https://nodejs.org/api/cli.html#cli_title_title
9999
NODE_OPTS='--title=digitransit-ui' \
100-
RELAY_FETCH_TIMEOUT='' \
101100
WEBPACK_DEVTOOL=$WEBPACK_DEVTOOL \
102101
ASSET_URL='' \
103102
STATIC_MESSAGE_URL=''

app/action/CanceledLegsBarActions.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/app.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import RealTimeInformationStore from './store/RealTimeInformationStore';
1111
import TimeStore from './store/TimeStore';
1212
import MapLayerStore from './store/MapLayerStore';
1313
import GeoJsonStore from './store/GeoJsonStore';
14-
import CanceledLegsBarStore from './store/CanceledLegsBarStore';
1514
import ViaPointStore from './store/ViaPointStore';
1615
import UserStore from './store/UserStore';
1716
import FavouriteStore from './store/FavouriteStore';
@@ -34,7 +33,6 @@ export default config => {
3433
app.registerStore(TimeStore);
3534
app.registerStore(MapLayerStore);
3635
app.registerStore(GeoJsonStore);
37-
app.registerStore(CanceledLegsBarStore);
3836
app.registerStore(ViaPointStore);
3937
app.registerStore(UserStore);
4038
app.registerStore(FavouriteStore);
@@ -44,14 +42,11 @@ export default config => {
4442

4543
app.plug({
4644
name: 'extra-context-plugin',
47-
plugContext: options => {
48-
let { headers } = options;
45+
plugContext: () => {
4946
return {
5047
plugComponentContext: componentContext => {
5148
// eslint-disable-next-line no-param-reassign
5249
componentContext.config = config;
53-
// eslint-disable-next-line no-param-reassign
54-
componentContext.headers = headers;
5550
},
5651
plugActionContext: actionContext => {
5752
// eslint-disable-next-line no-param-reassign
@@ -61,19 +56,8 @@ export default config => {
6156
// eslint-disable-next-line no-param-reassign
6257
storeContext.config = config;
6358
},
64-
dehydrate() {
65-
return {
66-
headers,
67-
config,
68-
};
69-
},
70-
rehydrate(state) {
71-
({ config, headers } = state); // eslint-disable-line no-param-reassign
72-
},
7359
};
7460
},
75-
dehydrate: () => ({}),
76-
rehydrate: () => {},
7761
});
7862

7963
return app;

app/client.js

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import PropTypes from 'prop-types';
22
import React from 'react';
33
import ReactDOM from 'react-dom';
44
import BrowserProtocol from 'farce/BrowserProtocol';
5-
import createInitialFarceRouter from 'found/createInitialFarceRouter';
6-
import createFarceStore from 'found/createFarceStore';
5+
import createFarceRouter from 'found/createFarceRouter';
76
import makeRouteConfig from 'found/makeRouteConfig';
8-
import getStoreRenderArgs from 'found/getStoreRenderArgs';
97
import { Resolver } from 'found-relay';
108
import provideContext from 'fluxible-addons-react/provideContext';
119
import debug from 'debug';
@@ -16,7 +14,6 @@ import {
1614
errorMiddleware,
1715
cacheMiddleware,
1816
} from 'react-relay-network-modern';
19-
import RelayClientSSR from 'react-relay-network-modern-ssr/lib/client';
2017
import OfflinePlugin from 'offline-plugin/runtime';
2118
import { Helmet } from 'react-helmet';
2219
import { Environment, RecordSource, Store } from 'relay-runtime';
@@ -33,7 +30,6 @@ import ErrorBoundary from './component/ErrorBoundary';
3330
import oldParamParser from './util/oldParamParser';
3431
import { ClientProvider as ClientBreakpointProvider } from './util/withBreakpoint';
3532
import meta from './meta';
36-
import { isIOSApp } from './util/browser';
3733
import {
3834
initAnalyticsClientSide,
3935
addAnalyticsEvent,
@@ -49,9 +45,9 @@ import {
4945

5046
window.debug = debug; // Allow _debug.enable('*') in browser console
5147

52-
// TODO: this is an ugly hack, but required due to cyclical processing in app
53-
const { config } = window.state.context.plugins['extra-context-plugin'];
48+
const { config } = window;
5449
const app = appCreator(config);
50+
const context = app.createContext({ config });
5551

5652
const getParams = query => {
5753
if (!query) {
@@ -86,8 +82,6 @@ async function init() {
8682
await Promise.all(modules);
8783
}
8884

89-
const context = await app.rehydrate(window.state);
90-
9185
// Get additional feedIds and searchParams from localstorage
9286
if (config.mainMenu.countrySelection) {
9387
const selectedCountries = context.getStore('CountryStore').getCountries();
@@ -117,11 +111,6 @@ async function init() {
117111
}
118112
}
119113

120-
// eslint-disable-next-line no-underscore-dangle
121-
const relaySSRMiddleware = new RelayClientSSR(window.__RELAY_PAYLOADS__);
122-
123-
relaySSRMiddleware.debug = false;
124-
125114
// Query parameter is used instead of header because browsers send
126115
// OPTIONS queries where you can't define headers
127116
const queryParameters = config.hasAPISubscriptionQueryParameter
@@ -134,7 +123,6 @@ async function init() {
134123
.getLanguage();
135124

136125
const network = new RelayNetworkLayer([
137-
relaySSRMiddleware.getMiddleware(),
138126
cacheMiddleware({
139127
size: 200,
140128
ttl: 60 * 60 * 1000,
@@ -159,8 +147,6 @@ async function init() {
159147
store: new Store(new RecordSource()),
160148
});
161149

162-
environment.relaySSRMiddleware = relaySSRMiddleware;
163-
164150
setRelayEnvironment(environment);
165151

166152
const resolver = new Resolver(environment);
@@ -169,18 +155,7 @@ async function init() {
169155

170156
const historyProtocol = new BrowserProtocol();
171157

172-
const store = createFarceStore({
173-
historyProtocol,
174-
historyMiddlewares,
175-
routeConfig,
176-
});
177-
178-
await getStoreRenderArgs({
179-
store,
180-
resolver,
181-
});
182-
183-
const Router = await createInitialFarceRouter({
158+
const Router = await createFarceRouter({
184159
historyProtocol,
185160
historyMiddlewares,
186161
routeConfig,
@@ -237,17 +212,8 @@ async function init() {
237212
headers: PropTypes.objectOf(PropTypes.string),
238213
});
239214

240-
const root = document.getElementById('app');
241-
const { initialBreakpoint } = root.dataset;
242-
243-
// KLUDGE: SSR and CSR mismatch breaks the UI in iOS PWA mode
244-
// see: https://github.com/facebook/react/issues/11336
245-
if (isIOSApp) {
246-
root.innerHTML = '';
247-
}
248-
249215
const content = (
250-
<ClientBreakpointProvider serverGuessedBreakpoint={initialBreakpoint}>
216+
<ClientBreakpointProvider>
251217
<ContextProvider
252218
translations={translations}
253219
context={context.getComponentContext()}
@@ -271,8 +237,8 @@ async function init() {
271237
</ClientBreakpointProvider>
272238
);
273239

274-
ReactDOM.hydrate(content, root, () => {
275-
// Run only in production mode and when built in a docker container
240+
const rootNode = document.getElementById('app');
241+
ReactDOM.render(content, rootNode, () => {
276242
if (process.env.NODE_ENV === 'production' && BUILD_TIME !== 'unset') {
277243
OfflinePlugin.install({
278244
onUpdateReady: () => OfflinePlugin.applyUpdate(),

app/component/AppBar.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import DisruptionInfo from './DisruptionInfo';
99
import MainMenuContainer from './MainMenuContainer';
1010
import MessageBar from './MessageBar';
1111
import LogoSmall from './LogoSmall';
12-
import CanceledLegsBar from './CanceledLegsBar';
1312
import LoginButton from './LoginButton';
1413
import UserMenu from './UserMenu';
1514

@@ -45,7 +44,6 @@ export default function AppBar(
4544
<>
4645
{disruptionInfoOpen && <DisruptionInfo setOpen={toggleDisruptionInfo} />}
4746
{config.NODE_ENV !== 'test' && <MessageBar breakpoint={breakpoint} />}
48-
<CanceledLegsBar />
4947
<nav className={`top-bar ${breakpoint !== 'large' ? 'mobile' : ''}`}>
5048
<section className="title">
5149
<button

app/component/AppBarContainer.js

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import PropTypes from 'prop-types';
2-
import React, { useState, useEffect, Suspense, lazy } from 'react';
2+
import React from 'react';
33
import { matchShape, routerShape } from 'found';
44
import { FormattedMessage } from 'react-intl';
55
import getContext from 'recompose/getContext';
66
import connectToStores from 'fluxible-addons-react/connectToStores';
77
import withBreakpoint from '../util/withBreakpoint';
88
import { favouriteShape, userShape } from '../util/shapes';
9-
10-
const AppBar = lazy(() => import('./AppBar'));
11-
const AppBarHsl = lazy(() => import('./AppBarHsl'));
12-
const MessageBar = lazy(() => import('./MessageBar'));
9+
import AppBar from './AppBar';
10+
import AppBarHsl from './AppBarHsl';
11+
import MessageBar from './MessageBar';
1312

1413
const AppBarContainer = ({
1514
router,
@@ -23,16 +22,6 @@ const AppBarContainer = ({
2322
breakpoint,
2423
...args
2524
}) => {
26-
const [isClient, setClient] = useState(false);
27-
28-
useEffect(() => {
29-
// To prevent SSR from rendering something https://reactjs.org/docs/react-dom.html#hydrate
30-
setClient(true);
31-
});
32-
33-
if (!isClient) {
34-
return null;
35-
}
3625
return (
3726
<>
3827
<a
@@ -47,36 +36,31 @@ const AppBarContainer = ({
4736
</a>
4837
{style === 'hsl' ? (
4938
<div className="hsl-header-container" style={{ display: 'block' }}>
50-
<Suspense fallback="">
51-
<AppBarHsl user={user} lang={lang} favourites={favourites} />
52-
<MessageBar breakpoint={breakpoint} />
53-
</Suspense>
39+
<AppBarHsl user={user} lang={lang} favourites={favourites} />
40+
<MessageBar breakpoint={breakpoint} />
5441
</div>
5542
) : (
56-
<Suspense fallback="">
57-
<AppBar
58-
{...args}
59-
showLogo
60-
logo={logo}
61-
homeUrl={homeUrl}
62-
user={user}
63-
breakpoint={breakpoint}
64-
titleClicked={() =>
65-
router.push({
66-
...match.location,
67-
pathname: homeUrl,
68-
state: {
69-
...match.location.state,
70-
errorBoundaryKey:
71-
match.location.state &&
72-
match.location.state.errorBoundaryKey
73-
? match.location.state.errorBoundaryKey + 1
74-
: 1,
75-
},
76-
})
77-
}
78-
/>
79-
</Suspense>
43+
<AppBar
44+
{...args}
45+
showLogo
46+
logo={logo}
47+
homeUrl={homeUrl}
48+
user={user}
49+
breakpoint={breakpoint}
50+
titleClicked={() =>
51+
router.push({
52+
...match.location,
53+
pathname: homeUrl,
54+
state: {
55+
...match.location.state,
56+
errorBoundaryKey:
57+
match.location.state && match.location.state.errorBoundaryKey
58+
? match.location.state.errorBoundaryKey + 1
59+
: 1,
60+
},
61+
})
62+
}
63+
/>
8064
)}
8165
</>
8266
);

app/component/AppBarHsl.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/* eslint-disable camelcase */
22
import PropTypes from 'prop-types';
3-
import React, { useState, useEffect, useRef, lazy, Suspense } from 'react';
3+
import React, { useState, useEffect, useRef } from 'react';
44
import { intlShape } from 'react-intl';
55
import { matchShape } from 'found';
66
import { Helmet } from 'react-helmet';
7+
import SiteHeader from '@hsl-fi/site-header';
78
import { favouriteShape, configShape } from '../util/shapes';
89
import { clearOldSearches, clearFutureRoutes } from '../util/storeUtils';
910
import { getJson } from '../util/xhrPromise';
1011

11-
const SiteHeader = lazy(() => import('@hsl-fi/site-header'));
12-
1312
const clearStorages = context => {
1413
clearOldSearches(context);
1514
clearFutureRoutes(context);
@@ -127,20 +126,18 @@ const AppBarHsl = ({ lang, user, favourites }, context) => {
127126
</Helmet>
128127
)}
129128

130-
<Suspense fallback="">
131-
{!config.hideHeader && (
132-
<SiteHeader
133-
ref={siteHeaderRef}
134-
hslFiUrl={config.URL.ROOTLINK}
135-
lang={lang}
136-
{...userMenu}
137-
languageMenu={languages}
138-
banners={banners}
139-
suggestionsApiUrl={config.URL.HSL_FI_SUGGESTIONS}
140-
notificationApiUrls={notificationApiUrls}
141-
/>
142-
)}
143-
</Suspense>
129+
{!config.hideHeader && (
130+
<SiteHeader
131+
ref={siteHeaderRef}
132+
hslFiUrl={config.URL.ROOTLINK}
133+
lang={lang}
134+
{...userMenu}
135+
languageMenu={languages}
136+
banners={banners}
137+
suggestionsApiUrl={config.URL.HSL_FI_SUGGESTIONS}
138+
notificationApiUrls={notificationApiUrls}
139+
/>
140+
)}
144141
</>
145142
);
146143
};

app/component/BubbleDialog.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import { matchShape, routerShape } from 'found';
77

88
import Icon from './Icon';
99
import { getDialogState, setDialogState } from '../store/localStorage';
10-
import {
11-
getIsBrowser,
12-
isBrowser,
13-
isKeyboardSelectionEvent,
14-
} from '../util/browser';
10+
import { isKeyboardSelectionEvent } from '../util/browser';
1511
import withBreakpoint from '../util/withBreakpoint';
1612

1713
class BubbleDialog extends React.Component {
@@ -141,9 +137,6 @@ class BubbleDialog extends React.Component {
141137
}
142138

143139
render() {
144-
if (!isBrowser && !getIsBrowser()) {
145-
return null;
146-
}
147140
const { breakpoint, isFullscreenOnMobile } = this.props;
148141
const isFullscreen = breakpoint !== 'large' && isFullscreenOnMobile;
149142
return this.renderContainer(isFullscreen);

0 commit comments

Comments
 (0)