Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@
"@isomorphic-git/lightning-fs": "patches/@isomorphic-git__lightning-fs.patch",
"scratch-parser": "patches/scratch-parser.patch",
"@turbowarp/scratch-svg-renderer": "patches/@turbowarp__scratch-svg-renderer.patch",
"rotur-sdk@2.5.2": "patches/rotur-sdk@2.5.2.patch"
"rotur-sdk@2.5.2": "patches/rotur-sdk@2.5.2.patch",
"@isomorphic-git/idb-keyval": "patches/@isomorphic-git__idb-keyval.patch"
},
"allowUnusedPatches": true
},
Expand Down
142 changes: 142 additions & 0 deletions patches/@isomorphic-git__idb-keyval.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
diff --git a/dist/idb-keyval-cjs.js b/dist/idb-keyval-cjs.js
index d8b578d3e669600ab0dc84248d42609454de6abf..0f646c6cc6a25bf76691bbc83f856dfec930b7a1 100644
--- a/dist/idb-keyval-cjs.js
+++ b/dist/idb-keyval-cjs.js
@@ -13,32 +13,52 @@ class Store {
if (this._dbp) {
return;
}
- this._dbp = new Promise((resolve, reject) => {
+ const dbp = this._dbp = new Promise((resolve, reject) => {
const openreq = indexedDB.open(this._dbName);
openreq.onerror = () => reject(openreq.error);
- openreq.onsuccess = () => resolve(openreq.result);
+ openreq.onsuccess = () => {
+ openreq.result.onclose = () => this._forget(dbp);
+ resolve(openreq.result);
+ };
// First time setup: create an empty object store
openreq.onupgradeneeded = () => {
openreq.result.createObjectStore(this._storeName);
};
});
+ dbp.catch(() => this._forget(dbp));
}
- _withIDBStore(type, callback) {
- this._init();
- return this._dbp.then(db => new Promise((resolve, reject) => {
- const transaction = db.transaction(this.storeName, type);
- transaction.oncomplete = () => resolve();
- transaction.onabort = transaction.onerror = () => reject(transaction.error);
- callback(transaction.objectStore(this.storeName));
- }));
+ _forget(dbp) {
+ if (this._dbp === dbp) {
+ this._dbp = undefined;
+ }
}
- _close() {
+ _withIDBStore(type, callback, reopened = false) {
this._init();
- return this._dbp.then(db => {
- db.close();
- this._dbp = undefined;
+ const dbp = this._dbp;
+ return dbp.then(db => {
+ let transaction;
+ try {
+ transaction = db.transaction(this.storeName, type);
+ } catch (error) {
+ if (reopened || error.name !== 'InvalidStateError') throw error;
+ this._forget(dbp);
+ return this._withIDBStore(type, callback, true);
+ }
+ return new Promise((resolve, reject) => {
+ transaction.oncomplete = () => resolve();
+ transaction.onabort = transaction.onerror = () => reject(transaction.error);
+ callback(transaction.objectStore(this.storeName));
+ });
});
}
+ _close() {
+ const dbp = this._dbp;
+ this._dbp = undefined;
+ if (!dbp) {
+ return Promise.resolve();
+ }
+ return dbp.then(db => db.close(), () => {});
+ }
}
let store;
function getDefaultStore() {
diff --git a/dist/idb-keyval.mjs b/dist/idb-keyval.mjs
index 295ef23c5e1c0e6fc70232ef3da7277a2dc01b08..07c6e03c5b3344f89b38a4f06d53f74e650a23da 100644
--- a/dist/idb-keyval.mjs
+++ b/dist/idb-keyval.mjs
@@ -9,32 +9,52 @@ class Store {
if (this._dbp) {
return;
}
- this._dbp = new Promise((resolve, reject) => {
+ const dbp = this._dbp = new Promise((resolve, reject) => {
const openreq = indexedDB.open(this._dbName);
openreq.onerror = () => reject(openreq.error);
- openreq.onsuccess = () => resolve(openreq.result);
+ openreq.onsuccess = () => {
+ openreq.result.onclose = () => this._forget(dbp);
+ resolve(openreq.result);
+ };
// First time setup: create an empty object store
openreq.onupgradeneeded = () => {
openreq.result.createObjectStore(this._storeName);
};
});
+ dbp.catch(() => this._forget(dbp));
}
- _withIDBStore(type, callback) {
- this._init();
- return this._dbp.then(db => new Promise((resolve, reject) => {
- const transaction = db.transaction(this.storeName, type);
- transaction.oncomplete = () => resolve();
- transaction.onabort = transaction.onerror = () => reject(transaction.error);
- callback(transaction.objectStore(this.storeName));
- }));
+ _forget(dbp) {
+ if (this._dbp === dbp) {
+ this._dbp = undefined;
+ }
}
- _close() {
+ _withIDBStore(type, callback, reopened = false) {
this._init();
- return this._dbp.then(db => {
- db.close();
- this._dbp = undefined;
+ const dbp = this._dbp;
+ return dbp.then(db => {
+ let transaction;
+ try {
+ transaction = db.transaction(this.storeName, type);
+ } catch (error) {
+ if (reopened || error.name !== 'InvalidStateError') throw error;
+ this._forget(dbp);
+ return this._withIDBStore(type, callback, true);
+ }
+ return new Promise((resolve, reject) => {
+ transaction.oncomplete = () => resolve();
+ transaction.onabort = transaction.onerror = () => reject(transaction.error);
+ callback(transaction.objectStore(this.storeName));
+ });
});
}
+ _close() {
+ const dbp = this._dbp;
+ this._dbp = undefined;
+ if (!dbp) {
+ return Promise.resolve();
+ }
+ return dbp.then(db => db.close(), () => {});
+ }
}
let store;
function getDefaultStore() {
80 changes: 50 additions & 30 deletions patches/@isomorphic-git__lightning-fs.patch
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
diff --git a/src/DefaultBackend.js b/src/DefaultBackend.js
index d0563618bc975277ee39193858534a294892e6ce..e3ff3efa6a0c9840875dd7c6834d5349edeb4394 100644
index d0563618bc975277ee39193858534a294892e6ce..404899955f70bc35d7f3e0e6c51011cf8fc3d158 100644
--- a/src/DefaultBackend.js
+++ b/src/DefaultBackend.js
@@ -6,7 +6,6 @@ const { ENOENT, ENOTEMPTY, ETIMEDOUT } = require("./errors.js");
@@ -6,14 +6,13 @@ const { ENOENT, ENOTEMPTY, ETIMEDOUT } = require("./errors.js");
const IdbBackend = require("./IdbBackend.js");
const HttpBackend = require("./HttpBackend.js")
const Mutex = require("./Mutex.js");
-const Mutex2 = require("./Mutex2.js");

const path = require("./path.js");

module.exports = class DefaultBackend {
constructor() {
this.saveSuperblock = debounce(() => {
- this.flush();
+ this.flush().catch(err => console.warn(err));
}, 500);
}
async init (name, {
@@ -28,7 +27,11 @@ module.exports = class DefaultBackend {
} = {}) {
this._name = name
Expand All @@ -23,32 +31,44 @@ index d0563618bc975277ee39193858534a294892e6ce..e3ff3efa6a0c9840875dd7c6834d5349
this._cache = new CacheFS(name);
this._opts = { wipe, url };
this._needsWipe = !!wipe;
diff --git a/src/IdbBackend.js b/src/IdbBackend.js
index c7af775e6e5e3a338256d7da872e05465b95b437..e51a3a36c7d785c7582a7a2c03189f0cb861bf45 100644
--- a/src/IdbBackend.js
+++ b/src/IdbBackend.js
@@ -5,6 +5,11 @@ module.exports = class IdbBackend {
this._database = dbname;
this._storename = storename;
this._store = new idb.Store(this._database, this._storename);
+ // idb-keyval opens the database in the constructor and leaves the promise
+ // unhandled until the first operation. Safari private browsing and sandboxed
+ // frames reject it, which surfaced as unhandled rejections. Operations still
+ // chain from this promise and report the error to their callers.
+ this._store._dbp.catch(() => {});
}
saveSuperblock(superblock) {
return idb.set("!root", superblock, this._store);
diff --git a/src/Mutex.js b/src/Mutex.js
index d7df3579919eb4e3238fe0fdcbad73fb265b3c1b..75c9dd82763e672e3355c616936ab3c7c6d790ab 100644
--- a/src/Mutex.js
+++ b/src/Mutex.js
@@ -8,6 +8,8 @@ module.exports = class Mutex {
this._database = dbname
this._storename = storename
this._store = new idb.Store(this._database, this._storename)
+ // See IdbBackend: operations still receive the error.
+ this._store._dbp.catch(() => {})
this._lock = null
diff --git a/src/PromisifiedFS.js b/src/PromisifiedFS.js
index aaa6984556a2ecde5816efdd1ae280f318150312..04cc40ceaeaa47c7f5aa237375463f51906b68a4 100644
--- a/src/PromisifiedFS.js
+++ b/src/PromisifiedFS.js
@@ -121,7 +121,9 @@ module.exports = class PromisifiedFS {
if (mutating) this._backend.saveSuperblock() // this is debounced
if (this._operations.size === 0) {
if (!this._deactivationTimeout) clearTimeout(this._deactivationTimeout)
- this._deactivationTimeout = setTimeout(this._deactivate.bind(this), 500)
+ this._deactivationTimeout = setTimeout(() => {
+ this._deactivate().catch(err => console.warn(err))
+ }, 500)
}
}
}
@@ -136,7 +138,11 @@ module.exports = class PromisifiedFS {
if (this._deactivationPromise) await this._deactivationPromise
this._deactivationPromise = null
if (!this._activationPromise) {
- this._activationPromise = this._backend.activate ? this._backend.activate() : Promise.resolve();
+ const activation = this._backend.activate ? this._backend.activate() : Promise.resolve();
+ this._activationPromise = activation
+ activation.catch(() => {
+ if (this._activationPromise === activation) this._activationPromise = null
+ })
}
await this._activationPromise
}
async has ({ margin = 2000 } = {}) {
@@ -144,7 +150,11 @@ module.exports = class PromisifiedFS {
if (this._activationPromise) await this._activationPromise

if (!this._deactivationPromise) {
- this._deactivationPromise = this._backend.deactivate ? this._backend.deactivate() : Promise.resolve();
+ const deactivation = this._backend.deactivate ? this._backend.deactivate() : Promise.resolve();
+ this._deactivationPromise = deactivation
+ deactivation.catch(() => {
+ if (this._deactivationPromise === deactivation) this._deactivationPromise = null
+ })
}
this._activationPromise = null
if (this._gracefulShutdownResolve) this._gracefulShutdownResolve()
13 changes: 8 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions src/addons/addons/folders/userscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ export default async function ({ addon, console, msg }) {
};

const getBackpackFromElement = (el) => {
let fiber = el[reactInternalKey];
let fiber = el[addon.tab.traps.getInternalKey(el)];
while (fiber) {
const instance = fiber.stateNode;
if (instance && typeof instance.handleDrop === "function" && typeof instance.getContents === "function") {
return instance;
}
fiber = fiber.return;
}
throw new Error("cannot find Backpack");
return null;
};

const clamp = (n, min, max) => {
Expand Down Expand Up @@ -1305,8 +1305,14 @@ export default async function ({ addon, console, msg }) {
if (!backpackContainer) {
return;
}
document.removeEventListener("click", clickListener, true);
const backpackInstance = getBackpackFromElement(backpackContainer);
if (!backpackInstance) {
return;
}
document.removeEventListener("click", clickListener, true);
if (typeof backpackInstance.constructor.prototype.sa_loadNextItem === "function") {
return;
}
verifyBackpack(backpackInstance);
patchBackpack(backpackInstance);
});
Expand Down
9 changes: 8 additions & 1 deletion src/components/spotlight/spotlight.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export default function NativeSpotlight ({vm, locale, activeTabIndex, isPlayerOn
let selectedPreviewIdx = 0;
let blockTypes = null;
let indexedTargetId = null;
let indexedVariablesKey = null;
let limited = false;

let allowMenuClose = true;
Expand Down Expand Up @@ -337,7 +338,11 @@ export default function NativeSpotlight ({vm, locale, activeTabIndex, isPlayerOn
popupRoot.style.display = '';
popupInput.focus();

if (blockTypes && indexedTargetId === (vm.editingTarget && vm.editingTarget.id)) {
if (
blockTypes &&
indexedTargetId === (vm.editingTarget && vm.editingTarget.id) &&
indexedVariablesKey === BlockTypeInfo.getVariablesKey(workspace)
) {
doPerformSearch();
return;
}
Expand All @@ -361,6 +366,7 @@ export default function NativeSpotlight ({vm, locale, activeTabIndex, isPlayerOn
try {
blockTypes = BlockTypeInfo.getBlocks(Blockly, vm, workspace, msg);
indexedTargetId = vm.editingTarget && vm.editingTarget.id;
indexedVariablesKey = BlockTypeInfo.getVariablesKey(workspace);

if (!blockTypes || blockTypes.length === 0) {
console.warn('Spotlight: No block types available, showing empty search');
Expand Down Expand Up @@ -836,6 +842,7 @@ export default function NativeSpotlight ({vm, locale, activeTabIndex, isPlayerOn
const invalidateIndex = () => {
blockTypes = null;
indexedTargetId = null;
indexedVariablesKey = null;
querier.clearWorkspaceIndex();
};
vm.on('EXTENSION_ADDED', invalidateIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/containers/sound-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ const mapStateToProps = (state, {soundIndex}) => {
// A sound whose asset failed to load never gets a soundId, so the audio
// engine has no player for it and getSoundBuffer returns null. Render the
// editor with empty data instead of crashing.
const audioBuffer = state.scratchGui.vm.getSoundBuffer(index);
const audioBuffer = sound ? state.scratchGui.vm.getSoundBuffer(index) : null;
return {
isStereo: audioBuffer ? audioBuffer.numberOfChannels !== 1 : false,
duration: sound && sound.rate ? sound.sampleCount / sound.rate : 0,
Expand Down
Loading
Loading