Skip to content

Commit 68b6e0f

Browse files
committed
chore(perf): load LegalWithMarkdown lazily
1 parent 5e3506e commit 68b6e0f

4 files changed

Lines changed: 46 additions & 33 deletions

File tree

packages/fxa-settings/src/pages/Legal/Privacy/index.test.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import React from 'react';
66
import LegalPrivacy, { viewName } from '.';
7-
import { screen, fireEvent } from '@testing-library/react';
7+
import { screen, fireEvent, waitFor } from '@testing-library/react';
88
import { renderWithLocalizationProvider } from 'fxa-react/lib/test-utils/localizationProvider';
99
import { usePageViewEvent, logViewEvent } from '../../../lib/metrics';
1010
import { FluentBundle } from '@fluent/bundle';
@@ -40,13 +40,15 @@ describe('Legal/Privacy', () => {
4040
jest.clearAllMocks();
4141
});
4242

43-
it('renders as expected', () => {
43+
it('renders as expected', async () => {
4444
renderWithLocalizationProvider(<LegalPrivacy />);
45-
testAllL10n(screen, bundle);
45+
await waitFor(() => {
46+
testAllL10n(screen, bundle);
4647

47-
// renders if `markdown` is undefined
48-
screen.getByRole('heading', {
49-
name: 'Privacy Notice',
48+
// renders if `markdown` is undefined
49+
screen.getByRole('heading', {
50+
name: 'Privacy Notice',
51+
});
5052
});
5153
});
5254

packages/fxa-settings/src/pages/Legal/Privacy/index.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import React from 'react';
5+
import React, { lazy, Suspense } from 'react';
66
import { RouteComponentProps } from '@reach/router';
7-
import LegalWithMarkdown, {
8-
FetchLegalDoc,
9-
} from '../../../components/LegalWithMarkdown';
7+
import { FetchLegalDoc } from '../../../components/LegalWithMarkdown';
108
import { LegalDocFile } from '../../../lib/file-utils-legal';
9+
import LoadingSpinner from 'fxa-react/components/LoadingSpinner';
10+
11+
const LegalWithMarkdown = lazy(
12+
() => import('../../../components/LegalWithMarkdown')
13+
);
1114

1215
export const viewName = 'legal-privacy';
1316

@@ -21,12 +24,14 @@ const LegalPrivacy = ({
2124
fetchLegalDoc,
2225
}: LegalPrivacyProps & RouteComponentProps) => {
2326
return (
24-
<LegalWithMarkdown
25-
{...{ locale, fetchLegalDoc, viewName }}
26-
headingTextFtlId="legal-privacy-heading"
27-
headingText="Privacy Notice"
28-
legalDocFile={LegalDocFile.privacy}
29-
/>
27+
<Suspense fallback={<LoadingSpinner fullScreen />}>
28+
<LegalWithMarkdown
29+
{...{ locale, fetchLegalDoc, viewName }}
30+
headingTextFtlId="legal-privacy-heading"
31+
headingText="Privacy Notice"
32+
legalDocFile={LegalDocFile.privacy}
33+
/>
34+
</Suspense>
3035
);
3136
};
3237

packages/fxa-settings/src/pages/Legal/Terms/index.test.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import React from 'react';
66
import LegalTerms, { viewName } from '.';
7-
import { screen, fireEvent } from '@testing-library/react';
7+
import { screen, fireEvent, waitFor } from '@testing-library/react';
88
import { renderWithLocalizationProvider } from 'fxa-react/lib/test-utils/localizationProvider';
99
import { usePageViewEvent, logViewEvent } from '../../../lib/metrics';
1010
import { FluentBundle } from '@fluent/bundle';
@@ -40,13 +40,14 @@ describe('Legal/Terms', () => {
4040
jest.clearAllMocks();
4141
});
4242

43-
it('renders as expected', () => {
43+
it('renders as expected', async () => {
4444
renderWithLocalizationProvider(<LegalTerms />);
45-
testAllL10n(screen, bundle);
46-
47-
// renders if `markdown` is undefined
48-
screen.getByRole('heading', {
49-
name: 'Terms of Service',
45+
await waitFor(() => {
46+
testAllL10n(screen, bundle);
47+
// renders if `markdown` is undefined
48+
screen.getByRole('heading', {
49+
name: 'Terms of Service',
50+
});
5051
});
5152
});
5253

packages/fxa-settings/src/pages/Legal/Terms/index.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import React from 'react';
5+
import React, { lazy, Suspense } from 'react';
66
import { RouteComponentProps } from '@reach/router';
7-
import LegalWithMarkdown, {
8-
FetchLegalDoc,
9-
} from '../../../components/LegalWithMarkdown';
7+
import { FetchLegalDoc } from '../../../components/LegalWithMarkdown';
108
import { LegalDocFile } from '../../../lib/file-utils-legal';
9+
import LoadingSpinner from 'fxa-react/components/LoadingSpinner';
10+
11+
const LegalWithMarkdown = lazy(
12+
() => import('../../../components/LegalWithMarkdown')
13+
);
1114

1215
export const viewName = 'legal-terms';
1316

@@ -20,12 +23,14 @@ const LegalTerms = ({
2023
locale,
2124
fetchLegalDoc,
2225
}: LegalTermsProps & RouteComponentProps) => (
23-
<LegalWithMarkdown
24-
{...{ locale, fetchLegalDoc, viewName }}
25-
headingTextFtlId="legal-terms-heading"
26-
headingText="Terms of Service"
27-
legalDocFile={LegalDocFile.terms}
28-
/>
26+
<Suspense fallback={<LoadingSpinner fullScreen />}>
27+
<LegalWithMarkdown
28+
{...{ locale, fetchLegalDoc, viewName }}
29+
headingTextFtlId="legal-terms-heading"
30+
headingText="Terms of Service"
31+
legalDocFile={LegalDocFile.terms}
32+
/>
33+
</Suspense>
2934
);
3035

3136
export default LegalTerms;

0 commit comments

Comments
 (0)