Skip to content

Commit 32e1117

Browse files
Merge pull request #476 from ibi-group/code-splitting
feat(icons): code split large icons
2 parents 0e73e55 + f4267e1 commit 32e1117

File tree

9 files changed

+81
-516
lines changed

9 files changed

+81
-516
lines changed

Diff for: __snapshots__/storybook.test.ts.snap

+31-420
Large diffs are not rendered by default.

Diff for: package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"workspaces": [
99
"packages/*"
1010
],
11+
"resolutions": {
12+
"react": "17.0.2"
13+
},
1114
"devDependencies": {
1215
"@babel/cli": "^7.10",
1316
"@babel/core": "^7.10",
@@ -67,8 +70,8 @@
6770
"nock": "^11.7.0",
6871
"prettier": "^1.19.1",
6972
"puppeteer": "^10.2.0",
70-
"react": "^16.14.0",
71-
"react-dom": "^16.14.0",
73+
"react": "^17.0.2",
74+
"react-dom": "^17.0.2",
7275
"react-intl": "^5.24.6",
7376
"react-test-renderer": "^16.14.0",
7477
"semantic-release": "^17.1.1",

Diff for: packages/core-utils/src/__tests__/__snapshots__/query-params.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ Array [
428428
Object {
429429
"applicable": [Function],
430430
"default": false,
431-
"icon": <ForwardRef />,
431+
"icon": <ForwardRef(Wheelchair) />,
432432
"label": "Prefer Wheelchair Accessible Routes",
433433
"name": "wheelchair",
434434
"routingTypes": Array [

Diff for: packages/icons/src/companies/index.js

+17-45
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
1-
import Biketown from "./biketown-icon";
2-
import Bird from "./bird-icon";
3-
import Bolt from "./bolt-icon";
4-
import BoltEu from "./bolt-eu-icon";
5-
import Car2go from "./car2go-icon";
6-
import Gruv from "./gruv-icon";
7-
import Hopr from "./hopr-icon";
8-
import Lime from "./lime-icon";
9-
import Lyft from "./lyft-icon";
10-
import Razor from "./razor-icon";
11-
import Reachnow from "./reachnow-icon";
12-
import Shared from "./shared-icon";
13-
import Spin from "./spin-icon";
14-
import Uber from "./uber-icon";
1+
/* eslint-disable import/prefer-default-export */
2+
import { lazy } from "react";
153

164
const companyLookup = {
17-
biketown: Biketown,
18-
bird: Bird,
19-
bolt: Bolt,
20-
boltEu: BoltEu,
21-
car2go: Car2go,
22-
gruv: Gruv,
23-
hopr: Hopr,
24-
lime: Lime,
25-
lyft: Lyft,
26-
razor: Razor,
27-
reachnow: Reachnow,
28-
shared: Shared,
29-
spin: Spin,
30-
uber: Uber
5+
biketown: lazy(() => import("./biketown-icon")),
6+
bird: lazy(() => import("./bird-icon")),
7+
bolt: lazy(() => import("./bolt-icon")),
8+
boltEu: lazy(() => import("./bolt-eu-icon")),
9+
car2go: lazy(() => import("./car2go-icon")),
10+
gruv: lazy(() => import("./gruv-icon")),
11+
hopr: lazy(() => import("./hopr-icon")),
12+
lime: lazy(() => import("./lime-icon")),
13+
lyft: lazy(() => import("./lime-icon")),
14+
razor: lazy(() => import("./razor-icon")),
15+
reachnow: lazy(() => import("./reachnow-icon")),
16+
shared: lazy(() => import("./shared-icon")),
17+
spin: lazy(() => import("./spin-icon")),
18+
uber: lazy(() => import("./uber-icon"))
3119
};
3220

3321
function getCompanyIcon(name) {
@@ -38,20 +26,4 @@ function getCompanyIcon(name) {
3826
return icon;
3927
}
4028

41-
export {
42-
Biketown,
43-
Bird,
44-
Bolt,
45-
BoltEu,
46-
Car2go,
47-
getCompanyIcon,
48-
Gruv,
49-
Hopr,
50-
Lime,
51-
Lyft,
52-
Razor,
53-
Reachnow,
54-
Shared,
55-
Spin,
56-
Uber
57-
};
29+
export { getCompanyIcon };

Diff for: packages/icons/src/index.js

+1-31
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,7 @@ const {
2525
ClassicWalk
2626
} = classic;
2727

28-
const {
29-
Biketown,
30-
Bird,
31-
Bolt,
32-
BoltEu,
33-
Car2go,
34-
getCompanyIcon,
35-
Gruv,
36-
Hopr,
37-
Lime,
38-
Lyft,
39-
Razor,
40-
Reachnow,
41-
Shared,
42-
Spin,
43-
Uber
44-
} = companies;
28+
const { getCompanyIcon } = companies;
4529

4630
const {
4731
CircleClockwise,
@@ -134,14 +118,9 @@ export {
134118
BikeLocker,
135119
BikeParking,
136120
BikeStaple,
137-
Biketown,
138-
Bird,
139-
Bolt,
140-
BoltEu,
141121
Bus,
142122
BusCircle,
143123
Car,
144-
Car2go,
145124
Circle,
146125
CircleClockwise,
147126
CircleCounterclockwise,
@@ -161,18 +140,14 @@ export {
161140
Feedback,
162141
Ferry,
163142
getCompanyIcon,
164-
Gruv,
165143
HardLeft,
166144
HardRight,
167145
Help,
168146
HelpSolid,
169-
Hopr,
170147
IconRenderer,
171148
Info,
172149
Left,
173150
LegIcon,
174-
Lime,
175-
Lyft,
176151
Map,
177152
MapMarker,
178153
MapMarkerSolid,
@@ -182,16 +157,12 @@ export {
182157
Parking,
183158
Phone,
184159
Plane,
185-
Razor,
186-
Reachnow,
187160
Refresh,
188161
Right,
189162
Schedule,
190-
Shared,
191163
SlightLeft,
192164
SlightRight,
193165
Snow,
194-
Spin,
195166
StandardBike,
196167
StandardBus,
197168
StandardGondola,
@@ -217,7 +188,6 @@ export {
217188
TripPlannerSolid,
218189
UTurnLeft,
219190
UTurnRight,
220-
Uber,
221191
Walk,
222192
Wes,
223193
WesCircle,

Diff for: packages/icons/src/leg-icon.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import coreUtils from "@opentripplanner/core-utils";
22
import PropTypes from "prop-types";
3-
import React from "react";
3+
import React, { Suspense } from "react";
44

55
import { getCompanyIcon as defaultGetCompanyIcon } from "./companies";
66

@@ -9,7 +9,12 @@ const LegIcon = ({ getCompanyIcon, leg, ModeIcon, ...props }) => {
99
// Check if the iconStr has a matching company icon. If so, return that.
1010
if (company && typeof getCompanyIcon === "function") {
1111
const CompanyIcon = getCompanyIcon(company);
12-
if (CompanyIcon) return <CompanyIcon {...props} />;
12+
if (CompanyIcon)
13+
return (
14+
<Suspense fallback={<span>{company}</span>}>
15+
<CompanyIcon {...props} />
16+
</Suspense>
17+
);
1318
}
1419
let iconStr = leg.mode;
1520
// Do this for P&R, K&R and TNC trips without company icon

Diff for: packages/trip-form/src/__mocks__/submode-options.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import React from "react";
33
// @ts-ignore FIXME: Create TypeScript types for the icons package.
44
import * as Icons from "@opentripplanner/icons";
55

6+
const UberIcon = Icons.getCompanyIcon("uber");
7+
68
const submodeOptions = [
79
{
810
id: "BUS",
@@ -29,7 +31,7 @@ const submodeOptions = [
2931
title: "Uber",
3032
text: (
3133
<span>
32-
<Icons.Uber /> Uber
34+
<UberIcon /> Uber
3335
</span>
3436
)
3537
}

Diff for: packages/trip-form/src/util.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import coreUtils from "@opentripplanner/core-utils";
22
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
33
// @ts-ignore FIXME: Create TypeScript types for the icons package.
44
import { getCompanyIcon } from "@opentripplanner/icons";
5-
import React from "react";
5+
import React, { Suspense } from "react";
66
import { IntlShape } from "react-intl";
77

88
// eslint-disable-next-line prettier/prettier
@@ -269,7 +269,9 @@ function getTransitCombinedModeOptions(
269269
selectedCompanies.includes(modeCompanyUpper)),
270270
text: (
271271
<span>
272-
<ModeIcon mode="TRANSIT" />+{finalIcon}
272+
<Suspense fallback={company || "Loading..."}>
273+
<ModeIcon mode="TRANSIT" />+{finalIcon}
274+
</Suspense>
273275
</span>
274276
),
275277
title: modeLabel
@@ -364,7 +366,9 @@ export function getCompaniesOptions(
364366
selected: selectedCompanies.includes(comp.id),
365367
text: (
366368
<span>
367-
{CompanyIcon && <CompanyIcon />} {comp.label}
369+
<Suspense fallback={comp.label || comp.id || "Loading"}>
370+
{CompanyIcon ? <CompanyIcon /> : comp.id }
371+
</Suspense>
368372
</span>
369373
),
370374
title: comp.label

Diff for: yarn.lock

+9-11
Original file line numberDiff line numberDiff line change
@@ -15028,15 +15028,14 @@ react-docgen@^5.0.0:
1502815028
node-dir "^0.1.10"
1502915029
strip-indent "^3.0.0"
1503015030

15031-
react-dom@^16.14.0:
15032-
version "16.14.0"
15033-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.14.0.tgz#7ad838ec29a777fb3c75c3a190f661cf92ab8b89"
15034-
integrity sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==
15031+
react-dom@^17.0.2:
15032+
version "17.0.2"
15033+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
15034+
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
1503515035
dependencies:
1503615036
loose-envify "^1.1.0"
1503715037
object-assign "^4.1.1"
15038-
prop-types "^15.6.2"
15039-
scheduler "^0.19.1"
15038+
scheduler "^0.20.2"
1504015039

1504115040
react-draggable@^4.4.3:
1504215041
version "4.4.3"
@@ -15277,14 +15276,13 @@ react-transition-group@^4.3.0:
1527715276
loose-envify "^1.4.0"
1527815277
prop-types "^15.6.2"
1527915278

15280-
react@^16.14.0:
15281-
version "16.14.0"
15282-
resolved "https://registry.yarnpkg.com/react/-/react-16.14.0.tgz#94d776ddd0aaa37da3eda8fc5b6b18a4c9a3114d"
15283-
integrity sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==
15279+
react@17.0.2, react@^17.0.2:
15280+
version "17.0.2"
15281+
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
15282+
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
1528415283
dependencies:
1528515284
loose-envify "^1.1.0"
1528615285
object-assign "^4.1.1"
15287-
prop-types "^15.6.2"
1528815286

1528915287
read-cmd-shim@^1.0.1:
1529015288
version "1.0.5"

0 commit comments

Comments
 (0)