Skip to content

Commit 53c77ca

Browse files
committed
Target modern browsers and drop redundant polyfills
Add a .browserslistrc with `defaults and supports es6-module` so Babel stops transpiling to ES5 and injecting core-js polyfills for features modern browsers support natively. This eliminates the legacy JavaScript reported by Lighthouse. Trim now-unneeded frontend polyfills: regenerator-runtime (native async/await), core-js feature imports, classlist.js (IE 11) and whatwg-fetch (native fetch). Keep intersection-observer (Safari iframe root-margin workaround) and scroll-timeline (not native in Safari). Refresh caniuse-lite.
1 parent f800761 commit 53c77ca

9 files changed

Lines changed: 31 additions & 50 deletions

File tree

.browserslistrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Pageflow targets modern browsers (ES modules, CSS custom properties),
2+
# so builds avoid ES5 transpilation and the corresponding core-js
3+
# polyfills. `defaults` on its own still includes browsers like Opera
4+
# Mini that force Babel into legacy output; intersecting it with
5+
# `supports es6-module` drops those while keeping the usual
6+
# market-share/recency floor.
7+
defaults and supports es6-module

entry_types/scrolled/package/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
"striptags": "^3.2.0",
3838
"use-context-selector": "^1.2.11",
3939
"video.js": "https://github.com/tf/video.js#pageflow-scrolled-8",
40-
"wavesurfer.js": "6.1.0",
41-
"whatwg-fetch": "^3.0.0"
40+
"wavesurfer.js": "6.1.0"
4241
},
4342
"peerDependencies": {
4443
"pageflow": "15.1.0",

entry_types/scrolled/package/spec/editor/controllers/PreviewMessageController-spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import {
1515
} from 'frontend/inlineEditing/postMessage';
1616
import {setupGlobals} from 'pageflow/testHelpers';
1717
import {normalizeSeed, factories, createIframeWindow, useFakeXhr} from 'support';
18+
import {enableFetchMocks} from 'jest-fetch-mock';
19+
20+
enableFetchMocks();
1821

1922
describe('PreviewMessageController', () => {
2023
beforeAll(() => editor.contentElementTypes.register('textBlock', {}));
@@ -51,10 +54,7 @@ describe('PreviewMessageController', () => {
5154

5255
it('sends REVIEW_STATE_RESET to iframe after READY when commenting enabled', () => {
5356
features.enable('frontend', ['commenting']);
54-
jest.spyOn(window, 'fetch').mockResolvedValue({
55-
ok: true,
56-
json: () => Promise.resolve({currentUser: {id: 1}, commentThreads: []})
57-
});
57+
fetch.mockResponse(JSON.stringify({currentUser: {id: 1}, commentThreads: []}));
5858

5959
const entry = factories.entry(ScrolledEntry, {}, {entryTypeSeed: normalizeSeed()});
6060
const iframeWindow = createIframeWindow();

entry_types/scrolled/package/spec/frontend/commenting/features/commentingBadges-spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import '@testing-library/jest-dom/extend-expect';
22
import {fireEvent, waitFor} from '@testing-library/react';
3+
import {enableFetchMocks} from 'jest-fetch-mock';
34

45
import {renderEntry, useCommentingPageObjects} from 'support/pageObjects/commenting';
56

7+
enableFetchMocks();
8+
69
describe('commenting badges', () => {
710
useCommentingPageObjects();
811

912
it('fetches threads from API and displays badge', async () => {
10-
jest.spyOn(window, 'fetch').mockResolvedValue({
11-
ok: true,
12-
json: () => Promise.resolve({
13-
currentUser: {id: 42, name: 'Alice'},
14-
commentThreads: [
15-
{id: 1, subjectType: 'ContentElement', subjectId: 1, comments: []}
16-
]
17-
})
18-
});
13+
fetch.mockResponse(JSON.stringify({
14+
currentUser: {id: 42, name: 'Alice'},
15+
commentThreads: [
16+
{id: 1, subjectType: 'ContentElement', subjectId: 1, comments: []}
17+
]
18+
}));
1919

2020
const entry = renderEntry({
2121
seed: {

entry_types/scrolled/package/src/editor/config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ import {BrowserNotSupportedView} from './views/BrowserNotSupportedView';
2626
editor.registerEntryType('scrolled', {
2727
entryModel: ScrolledEntry,
2828

29-
previewView(options) {
29+
// Defined as a plain function (not a concise method) because the core
30+
// editor constructs it with `new editor.entryType.previewView(...)`,
31+
// and concise methods are not constructable.
32+
previewView: function(options) {
3033
return new EntryPreviewView({
3134
...options,
3235
editor
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
import 'core-js/features/array/fill';
2-
import 'core-js/features/array/find';
3-
import 'core-js/features/array/from'
4-
import 'core-js/features/object/assign';
5-
import 'core-js/features/promise';
6-
import 'core-js/features/map';
7-
import 'core-js/features/string/starts-with';
8-
import 'core-js/features/set';
9-
import 'core-js/features/symbol';
10-
import 'core-js/features/symbol/iterator';
11-
12-
import 'regenerator-runtime/runtime.js';
13-
141
import {browser} from 'pageflow/frontend';
152

163
// Safari does not handle positive root margin correctly inside
@@ -21,9 +8,9 @@ if (browser.agent.matchesSafari() && window.parent !== window) {
218

229
require('intersection-observer');
2310

24-
// Make sure we're in a Browser-like environment before importing polyfills
25-
// This prevents `fetch()` from being imported in a Node test environment
11+
// Make sure we're in a Browser-like environment before importing the
12+
// polyfill. This prevents it from being imported in a Node test
13+
// environment.
2614
if (typeof window !== 'undefined') {
27-
require('whatwg-fetch');
2815
require('scroll-timeline');
2916
}

package/src/frontend/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import './polyfills';
21
import {Consent} from './Consent';
32

43
export {log, debugMode} from './base';

package/src/frontend/polyfills.js

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

yarn.lock

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4423,9 +4423,9 @@ caniuse-api@^3.0.0:
44234423
lodash.uniq "^4.5.0"
44244424

44254425
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001039, caniuse-lite@^1.0.30001580:
4426-
version "1.0.30001581"
4427-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001581.tgz#0dfd4db9e94edbdca67d57348ebc070dece279f4"
4428-
integrity sha512-whlTkwhqV2tUmP3oYhtNfaWGYHDdS3JYFQBKXxcUR9qqPWsRhFHhoISO2Xnl/g0xyKzht9mI1LZpiNWfMzHixQ==
4426+
version "1.0.30001805"
4427+
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001805.tgz"
4428+
integrity sha512-52noaS3DubycKSXaU30TwPGIp+POyQSUVa5jBEq3vkRkY0kjyb3LQgvhU6WGyCcyXqVLWO0Cw0Q6BSdD0kUfVA==
44294429

44304430
case-sensitive-paths-webpack-plugin@^2.4.0:
44314431
version "2.4.0"
@@ -13171,11 +13171,6 @@ whatwg-fetch@^0.9.0:
1317113171
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-0.9.0.tgz#0e3684c6cb9995b43efc9df03e4c365d95fd9cc0"
1317213172
integrity sha512-DIuh7/cloHxHYwS/oRXGgkALYAntijL63nsgMQsNSnBj825AysosAqA2ZbYXGRqpPRiNH7335dTqV364euRpZw==
1317313173

13174-
whatwg-fetch@^3.0.0:
13175-
version "3.0.0"
13176-
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb"
13177-
integrity sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q==
13178-
1317913174
whatwg-mimetype@^2.3.0:
1318013175
version "2.3.0"
1318113176
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"

0 commit comments

Comments
 (0)