Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix polyfills working incorrectly on Edge #2743

Merged
merged 1 commit into from
Jul 13, 2020

Conversation

chrisgzf
Copy link
Member

@chrisgzf chrisgzf commented Jul 12, 2020

Context

Users who use the non-Chromium Edge were reporting that they were seeing a white-screen of death when loading NUSMods, caused by:
image

Which is caused by:
image

PersistGate from one of our deps, redux-persist uses Promise.prototype.finally which somehow isn't supported on Edge.

But no, the story doesn't end here.

Promise.prototype.finally actually IS SUPPORTED by Edge. Except that there is some oddity with our polyfill library core-js or with Edge that causes it to fail Promise feature detection, and Promise is entirely polyfilled incorrectly by core-js on Edge, causing the native implementation of finally to be gone.

To resolve this, we polyfill finally.

Implementation

Tried 3 methods

  1. Add require.resolve('redux-persist/integration/react') to the list of files transpiled by Babel. This should make a lot of sense, but somehow core-js has issues with adding polyfills to deps. ❌
  2. Change useBuiltIns: usage to useBuiltIns: entry in Babel's config, so that it adds every single stable polyfill from core-js to every file. Works great, but greatly increases the bundle size (+13 KB), see WIP Promise.prototype.finally polyfill #2741. ✅
  3. Just import the polyfill directly. Works great! Minimal bundle size increase! (In fact, it decreased??) ✅ ✅ ✅

Screenshot 2020-07-13 at 3 25 44 AM

Tested on Edge 44.17763.1.0 (which is from donkey years ago).

Other Information

Congrats to the 70 people who use Edge! 🥴 🤢 🤮 You can now use NUSMods again!

image

@codecov
Copy link

codecov bot commented Jul 12, 2020

Codecov Report

Merging #2743 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2743   +/-   ##
=======================================
  Coverage   45.95%   45.95%           
=======================================
  Files         248      248           
  Lines        5273     5273           
  Branches     1222     1222           
=======================================
  Hits         2423     2423           
  Misses       2850     2850           
Impacted Files Coverage Δ
website/src/entry/main.tsx 0.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d56881...09ca440. Read the comment docs.

@nusmods-deploy-bot
Copy link

nusmods-deploy-bot bot commented Jul 12, 2020

@chrisgzf chrisgzf changed the title WIP Fix polyfills working incorrectly on Edge Fix polyfills working incorrectly on Edge Jul 12, 2020
@@ -7,6 +7,11 @@ import { hot } from 'react-hot-loader/root';
import { BrowserRouter as Router } from 'react-router-dom';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';
import 'core-js/es/promise/finally';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this order correct? I think the polyfill should go as early as possible, since you are importing for side-effect here. Technically from the stacktrace it looks like the error would only manifest on mount, but for safety polyfills should be loaded as early as possible since the other modules can also have side effect / call the polyfilled methods during init

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also another nit - comments usually go above the line they are commenting on, not below

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e28803a!

@ZhangYiJiang
Copy link
Member

Also good job sleuthing out this solution!

@ZhangYiJiang
Copy link
Member

Also I think Packtracker has the same issue as the other GitHub apps in that it has issue with PRs from forks, which is rather annoying :( Thanks for manually validating the size issue

@ZhangYiJiang ZhangYiJiang mentioned this pull request Jul 12, 2020
@taneliang
Copy link
Member

Wow great work @chrisgzf!

@ZhangYiJiang
Copy link
Member

Sorry, one last issue - the polyfill added in the wrong file - App.tsx is not the entry point. It should be main.ts. You can put it right after where we import Sentry, here - https://github.com/nusmodifications/nusmods/blob/master/website/src/entry/main.tsx#L3

@chrisgzf
Copy link
Member Author

@ZhangYiJiang fixed in 09ca440!

@ZhangYiJiang ZhangYiJiang merged commit eb521e6 into nusmodifications:master Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants