Skip to content

Commit

Permalink
Drop Support for Safari 15.x
Browse files Browse the repository at this point in the history
Changing our support to only cover the last two major safari versions on
OSX as our stats show that this will cover our users and we can move
more quickly to some modern Javascript and improve performance for
everyone else by not including dead code.

This allows us to drop our CRYPTO.randomUUID polyfill as it is supported
in Safari 16+.
  • Loading branch information
jrjohnson committed Aug 22, 2024
1 parent 42d0438 commit f2f8b41
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 78 deletions.
2 changes: 1 addition & 1 deletion packages/frontend/config/targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (isCI || isProduction) {
browsers.push('last 3 edge versions');
browsers.push('firefox esr'); //sometimes points to the last 2 ESR releases when they overlap
browsers.push('last 2 iOS major versions');
browsers.push('last 3 safari major versions');
browsers.push('last 2 safari major versions');
browsers.push('last 3 ChromeAndroid versions');
browsers.push('last 3 Chrome versions');
}
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/testem.browserstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const BrowserStackLaunchers = {
'--os',
'OS X',
'--osv',
'Monterey',
'Ventura',
'--b',
'safari',
'--bv',
'latest', // Will always be 15.x on Monterey
'latest', // Will always be 16.x on Ventura
...defaultArgs,
],
protocol: 'browser',
Expand Down
69 changes: 1 addition & 68 deletions packages/ilios-common/addon/utils/load-polyfills.js
Original file line number Diff line number Diff line change
@@ -1,68 +1 @@
export async function loadPolyfills() {
//we need CRYPTO.randomUUID until we drop support for Safari 15.x
installUUIDPolyfill();
}

function installUUIDPolyfill() {
const CRYPTO = window.crypto;

if (!CRYPTO.randomUUID) {
// we might be able to optimize this by requesting more bytes than we need at a time
const rng = function () {
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
let rnds8 = new Uint8Array(16);

if (!CRYPTO.getRandomValues) {
throw new Error(`Unable to generate bytes for UUID`);
}

return CRYPTO.getRandomValues ? CRYPTO.getRandomValues(rnds8) : CRYPTO.randomFillSync(rnds8);
};

/*
* Convert array of 16 byte values to UUID string format of the form:
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
*/
const byteToHex = [];
for (let i = 0; i < 256; ++i) {
byteToHex[i] = (i + 0x100).toString(16).substr(1);
}

const bytesToUuid = function (buf) {
let bth = byteToHex;
// join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
return [
bth[buf[0]],
bth[buf[1]],
bth[buf[2]],
bth[buf[3]],
'-',
bth[buf[4]],
bth[buf[5]],
'-',
bth[buf[6]],
bth[buf[7]],
'-',
bth[buf[8]],
bth[buf[9]],
'-',
bth[buf[10]],
bth[buf[11]],
bth[buf[12]],
bth[buf[13]],
bth[buf[14]],
bth[buf[15]],
].join('');
};

CRYPTO.randomUUID = function uuidv4() {
let rnds = rng();

// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
rnds[6] = (rnds[6] & 0x0f) | 0x40;
rnds[8] = (rnds[8] & 0x3f) | 0x80;

return bytesToUuid(rnds);
};
}
}
export async function loadPolyfills() {}
4 changes: 2 additions & 2 deletions packages/lti-course-manager/testem.browserstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const BrowserStackLaunchers = {
'--os',
'OS X',
'--osv',
'Monterey',
'Ventura',
'--b',
'safari',
'--bv',
'latest', // Will always be 15.x on Monterey
'latest', // Will always be 16.x on Ventura
...defaultArgs,
],
protocol: 'browser',
Expand Down
4 changes: 2 additions & 2 deletions packages/lti-dashboard/testem.browserstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const BrowserStackLaunchers = {
'--os',
'OS X',
'--osv',
'Monterey',
'Ventura',
'--b',
'safari',
'--bv',
'latest', // Will always be 15.x on Monterey
'latest', // Will always be 16.x on Ventura
...defaultArgs,
],
protocol: 'browser',
Expand Down
2 changes: 1 addition & 1 deletion packages/test-app/config/targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (isCI || isProduction) {
browsers.push('last 3 edge versions');
browsers.push('firefox esr'); //sometimes points to the last 2 ESR releases when they overlap
browsers.push('last 2 iOS major versions');
browsers.push('last 3 safari major versions');
browsers.push('last 2 safari major versions');
browsers.push('last 3 ChromeAndroid versions');
browsers.push('last 3 Chrome versions');
}
Expand Down
4 changes: 2 additions & 2 deletions packages/test-app/testem.browserstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const BrowserStackLaunchers = {
'--os',
'OS X',
'--osv',
'Monterey',
'Ventura',
'--b',
'safari',
'--bv',
'latest', // Will always be 15.x on Monterey
'latest', // Will always be 16.x on Ventura
...defaultArgs,
],
protocol: 'browser',
Expand Down

0 comments on commit f2f8b41

Please sign in to comment.