Skip to content

Commit 9f27685

Browse files
committed
Polyfill Intl.Segmenter
This fixes Element on older versions of Firefox by adding a Polyfill for Intl.Segmenter. The Polyfill is conditionally imported so it only inflates the initial bundle size by about 100 bytes. On browsers that need it, the polyfill is quite large at 317Kb. Users on these browser will still see the 'unsupported browser' screen, but will be able to click through to use the app anyway. This keeps the Intl.Segmenter modernizr check but this would also happen due to #27674
1 parent 1f4006a commit 9f27685

File tree

3 files changed

+38
-31
lines changed

3 files changed

+38
-31
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"@types/react": "17.0.80"
7272
},
7373
"dependencies": {
74+
"@formatjs/intl-segmenter": "^11.5.7",
7475
"@matrix-org/react-sdk-module-api": "^2.3.0",
7576
"jsrsasign": "^11.0.0",
7677
"katex": "^0.16.0",

src/vector/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ limitations under the License.
1919
*/
2020

2121
import { logger } from "matrix-js-sdk/src/logger";
22+
import { shouldPolyfill as shouldPolyFillIntlSegmenter } from "@formatjs/intl-segmenter/should-polyfill";
2223

2324
// These are things that can run before the skin loads - be careful not to reference the react-sdk though.
2425
import { parseQsFromFragment } from "./url_utils";
@@ -77,6 +78,8 @@ function checkBrowserFeatures(): boolean {
7778
// ES2024: https://402.ecma-international.org/9.0/#sec-intl.segmenter
7879
// The built-in modernizer 'intl' check only checks for the presence of the Intl object, not the Segmenter,
7980
// and older Firefox has the former but not the latter, so we add our own.
81+
// This is polyfilled now, but we still want to show the warning because we want to remove the polyfill
82+
// at some point.
8083
window.Modernizr.addTest("intlsegmenter", () => typeof window.Intl?.Segmenter === "function");
8184

8285
// Basic test for WebAssembly support. We could also try instantiating a simple module,
@@ -112,6 +115,10 @@ const supportedBrowser = checkBrowserFeatures();
112115
// the browser to use as much parallelism as it can.
113116
// Load parallelism is based on research in https://github.com/element-hq/element-web/issues/12253
114117
async function start(): Promise<void> {
118+
if (shouldPolyFillIntlSegmenter()) {
119+
await import(/* webpackChunkName: "intl-segmenter-polyfill" */ "@formatjs/intl-segmenter/polyfill-force");
120+
}
121+
115122
// load init.ts async so that its code is not executed immediately and we can catch any exceptions
116123
const {
117124
rageshakePromise,
@@ -132,6 +139,8 @@ async function start(): Promise<void> {
132139
"./init"
133140
);
134141

142+
// Now perform the next stage of initialisation. This has its own try/catch in which we render
143+
// a react error page on failure.
135144
try {
136145
// give rageshake a chance to load/fail, we don't actually assert rageshake loads, we allow it to fail if no IDB
137146
await settled(rageshakePromise);

yarn.lock

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,30 @@
15361536
resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.4.tgz#1d459cee5031893a08a0e064c406ad2130cced7c"
15371537
integrity sha512-dWO2pw8hhi+WrXq1YJy2yCuWoL20PddgGaqTgVe4cOS9Q6qklXCiA1tJEqX6BEwRNSCP84/afac9hd4MS+zEUA==
15381538

1539+
"@formatjs/[email protected]":
1540+
version "2.0.0"
1541+
resolved "https://registry.yarnpkg.com/@formatjs/ecma402-abstract/-/ecma402-abstract-2.0.0.tgz#39197ab90b1c78b7342b129a56a7acdb8f512e17"
1542+
integrity sha512-rRqXOqdFmk7RYvj4khklyqzcfQl9vEL/usogncBHRZfZBDOwMGuSRNFl02fu5KGHXdbinju+YXyuR+Nk8xlr/g==
1543+
dependencies:
1544+
"@formatjs/intl-localematcher" "0.5.4"
1545+
tslib "^2.4.0"
1546+
1547+
"@formatjs/[email protected]":
1548+
version "0.5.4"
1549+
resolved "https://registry.yarnpkg.com/@formatjs/intl-localematcher/-/intl-localematcher-0.5.4.tgz#caa71f2e40d93e37d58be35cfffe57865f2b366f"
1550+
integrity sha512-zTwEpWOzZ2CiKcB93BLngUX59hQkuZjT2+SAQEscSm52peDW/getsawMcWF1rGRpMCX6D7nSJA3CzJ8gn13N/g==
1551+
dependencies:
1552+
tslib "^2.4.0"
1553+
1554+
"@formatjs/intl-segmenter@^11.5.7":
1555+
version "11.5.7"
1556+
resolved "https://registry.yarnpkg.com/@formatjs/intl-segmenter/-/intl-segmenter-11.5.7.tgz#c9fcb94d4690372d3ccd609ce1490910b582af78"
1557+
integrity sha512-MPvUKOURPY1aHc/d3YtLKp4hamrJtdBRc/AZVt9zRitrNeRszSwpIIYDHka9chQJTRIJlIfS4S9FGMdA1PE3Xw==
1558+
dependencies:
1559+
"@formatjs/ecma402-abstract" "2.0.0"
1560+
"@formatjs/intl-localematcher" "0.5.4"
1561+
tslib "^2.4.0"
1562+
15391563
"@humanwhocodes/config-array@^0.11.14":
15401564
version "0.11.14"
15411565
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b"
@@ -7915,7 +7939,6 @@ [email protected]:
79157939

79167940
"matrix-js-sdk@github:matrix-org/matrix-js-sdk#develop":
79177941
version "34.0.0"
7918-
uid "94e393c9a619b5d7427ff4103128521229ad4f6c"
79197942
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/94e393c9a619b5d7427ff4103128521229ad4f6c"
79207943
dependencies:
79217944
"@babel/runtime" "^7.12.5"
@@ -7942,7 +7965,6 @@ matrix-mock-request@^2.5.0:
79427965

79437966
"matrix-react-sdk@github:matrix-org/matrix-react-sdk#develop":
79447967
version "3.101.0"
7945-
uid "19f9f9856451a8e4cce6d313d19ca8aed4b5d6b4"
79467968
resolved "https://codeload.github.com/matrix-org/matrix-react-sdk/tar.gz/19f9f9856451a8e4cce6d313d19ca8aed4b5d6b4"
79477969
dependencies:
79487970
"@babel/runtime" "^7.12.5"
@@ -10474,16 +10496,7 @@ string-replace-loader@3:
1047410496
loader-utils "^2.0.0"
1047510497
schema-utils "^3.0.0"
1047610498

10477-
"string-width-cjs@npm:string-width@^4.2.0":
10478-
version "4.2.3"
10479-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
10480-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
10481-
dependencies:
10482-
emoji-regex "^8.0.0"
10483-
is-fullwidth-code-point "^3.0.0"
10484-
strip-ansi "^6.0.1"
10485-
10486-
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
10499+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
1048710500
version "4.2.3"
1048810501
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1048910502
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -10569,14 +10582,7 @@ string_decoder@~1.1.1:
1056910582
dependencies:
1057010583
safe-buffer "~5.1.0"
1057110584

10572-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
10573-
version "6.0.1"
10574-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
10575-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
10576-
dependencies:
10577-
ansi-regex "^5.0.1"
10578-
10579-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
10585+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1058010586
version "6.0.1"
1058110587
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1058210588
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -11046,7 +11052,7 @@ tsconfig-paths@^3.15.0:
1104611052
minimist "^1.2.6"
1104711053
strip-bom "^3.0.0"
1104811054

11049-
tslib@^2.0.0, tslib@^2.0.3, tslib@^2.1.0:
11055+
tslib@^2.0.0, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.4.0:
1105011056
version "2.6.3"
1105111057
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0"
1105211058
integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==
@@ -11675,7 +11681,7 @@ word-wrap@^1.2.5:
1167511681
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
1167611682
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==
1167711683

11678-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
11684+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1167911685
version "7.0.0"
1168011686
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1168111687
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -11693,15 +11699,6 @@ wrap-ansi@^6.2.0:
1169311699
string-width "^4.1.0"
1169411700
strip-ansi "^6.0.0"
1169511701

11696-
wrap-ansi@^7.0.0:
11697-
version "7.0.0"
11698-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
11699-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
11700-
dependencies:
11701-
ansi-styles "^4.0.0"
11702-
string-width "^4.1.0"
11703-
strip-ansi "^6.0.0"
11704-
1170511702
wrap-ansi@^8.1.0:
1170611703
version "8.1.0"
1170711704
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)