Skip to content

Commit

Permalink
replace usage of structuredClone with JSON dupe.
Browse files Browse the repository at this point in the history
i've had a report of `structuredClone` being `undefined` which means some browsers do not support it.
while likely less optimized, `JSON.parse(JSON.stringify(data))` will do the trick and allow people to use the website with prior unsupported browsers.
  • Loading branch information
SeymourSchlong committed Jun 14, 2024
1 parent 89695d3 commit 6fc9ae3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const load = () => {

const params = new URLSearchParams(window.location.search);

const makeClone = (data) => {
return JSON.parse(JSON.stringify(data));
}

const loadedLanguage = () => {
// Languages here include a space between the titles
const isSpaceLang = () => {
Expand Down Expand Up @@ -798,7 +802,7 @@ const load = () => {
loadTagData();

const tagClone = {};
Object.assign(tagClone, structuredClone(tag));
Object.assign(tagClone, makeClone(tag));

tagClone.banner = banners[tagClone.banner].file;
if (tagClone.banner.startsWith('data:')) tagClone.banner = './assets/banners/Npl_Tutorial00';
Expand All @@ -824,7 +828,7 @@ const load = () => {
loadTagData();

const tagClone = {};
Object.assign(tagClone, structuredClone(tag));
Object.assign(tagClone, makeClone(tag));

tagClone.banner = banners[tagClone.banner].file;
if (tagClone.banner.startsWith('data:')) tagClone.banner = './assets/banners/Npl_Tutorial00';
Expand Down Expand Up @@ -858,7 +862,7 @@ const load = () => {
const loadSelected = (i) => {
loadTagData();

Object.assign(tag, structuredClone(saved[i]));
Object.assign(tag, makeClone(saved[i]));

const nameColour = tag.colour;

Expand Down Expand Up @@ -1455,7 +1459,7 @@ const load = () => {
return res.json();
}).then(data => {
Object.assign(lang, data);
Object.assign(assetIDs.lang, structuredClone(data));
Object.assign(assetIDs.lang, makeClone(data));
loadedLanguage();
}).catch(err => {
alert(`Something went wrong when loading...\n\nIf this problem keeps occurring, contact @spaghettitron on Twitter!\n\n${err.stack}`);
Expand Down

0 comments on commit 6fc9ae3

Please sign in to comment.