diff --git a/package.json b/package.json
index a2babc31c3f..5aba44a715c 100644
--- a/package.json
+++ b/package.json
@@ -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
},
diff --git a/patches/@isomorphic-git__idb-keyval.patch b/patches/@isomorphic-git__idb-keyval.patch
new file mode 100644
index 00000000000..489b2b97779
--- /dev/null
+++ b/patches/@isomorphic-git__idb-keyval.patch
@@ -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() {
diff --git a/patches/@isomorphic-git__lightning-fs.patch b/patches/@isomorphic-git__lightning-fs.patch
index b21176a6d18..a735b432f51 100644
--- a/patches/@isomorphic-git__lightning-fs.patch
+++ b/patches/@isomorphic-git__lightning-fs.patch
@@ -1,8 +1,8 @@
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");
@@ -10,6 +10,14 @@ index d0563618bc975277ee39193858534a294892e6ce..e3ff3efa6a0c9840875dd7c6834d5349
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
@@ -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()
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 535659d5171..ff3f8fd2819 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -8,8 +8,11 @@ overrides:
cheerio: 1.0.0-rc.12
patchedDependencies:
+ '@isomorphic-git/idb-keyval':
+ hash: 15c74dd5ecbe503575c9e211bd71428ef95190ac599be6398519cb2a7cd2a255
+ path: patches/@isomorphic-git__idb-keyval.patch
'@isomorphic-git/lightning-fs':
- hash: 3918c5bc950ffdc268e7fa966eadf53e46df0c4efa8e3988911b315515322336
+ hash: 456a42c5e3dc06762bd6d34af7c52f1270b3dd2d1e77cc00c70642333cdd10bc
path: patches/@isomorphic-git__lightning-fs.patch
'@turbowarp/scratch-svg-renderer':
hash: 81a01d6d472570d53eec593be679e84867db1ba1410f5ef084d5c404068481b9
@@ -30,7 +33,7 @@ importers:
version: 0.0.7
'@isomorphic-git/lightning-fs':
specifier: ^4.6.2
- version: 4.6.2(patch_hash=3918c5bc950ffdc268e7fa966eadf53e46df0c4efa8e3988911b315515322336)
+ version: 4.6.2(patch_hash=456a42c5e3dc06762bd6d34af7c52f1270b3dd2d1e77cc00c70642333cdd10bc)
'@microbit/microbit-universal-hex':
specifier: 0.2.2
version: 0.2.2(tslib@2.8.1)
@@ -7373,11 +7376,11 @@ snapshots:
'@humanwhocodes/object-schema@2.0.3': {}
- '@isomorphic-git/idb-keyval@3.3.2': {}
+ '@isomorphic-git/idb-keyval@3.3.2(patch_hash=15c74dd5ecbe503575c9e211bd71428ef95190ac599be6398519cb2a7cd2a255)': {}
- '@isomorphic-git/lightning-fs@4.6.2(patch_hash=3918c5bc950ffdc268e7fa966eadf53e46df0c4efa8e3988911b315515322336)':
+ '@isomorphic-git/lightning-fs@4.6.2(patch_hash=456a42c5e3dc06762bd6d34af7c52f1270b3dd2d1e77cc00c70642333cdd10bc)':
dependencies:
- '@isomorphic-git/idb-keyval': 3.3.2
+ '@isomorphic-git/idb-keyval': 3.3.2(patch_hash=15c74dd5ecbe503575c9e211bd71428ef95190ac599be6398519cb2a7cd2a255)
isomorphic-textencoder: 1.0.1
just-debounce-it: 1.1.0
just-once: 1.1.0
diff --git a/src/addons/addons/folders/userscript.js b/src/addons/addons/folders/userscript.js
index 196c2af3092..1564347d6a6 100644
--- a/src/addons/addons/folders/userscript.js
+++ b/src/addons/addons/folders/userscript.js
@@ -110,7 +110,7 @@ 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") {
@@ -118,7 +118,7 @@ export default async function ({ addon, console, msg }) {
}
fiber = fiber.return;
}
- throw new Error("cannot find Backpack");
+ return null;
};
const clamp = (n, min, max) => {
@@ -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);
});
diff --git a/src/components/spotlight/spotlight.jsx b/src/components/spotlight/spotlight.jsx
index 60150a46e6f..5255660d66a 100644
--- a/src/components/spotlight/spotlight.jsx
+++ b/src/components/spotlight/spotlight.jsx
@@ -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;
@@ -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;
}
@@ -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');
@@ -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);
diff --git a/src/containers/sound-editor.jsx b/src/containers/sound-editor.jsx
index bb2726baf51..d7d3f4201be 100644
--- a/src/containers/sound-editor.jsx
+++ b/src/containers/sound-editor.jsx
@@ -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,
diff --git a/src/lib/api/local-backpack.js b/src/lib/api/local-backpack.js
index e6f410c32f6..10ff67931e0 100644
--- a/src/lib/api/local-backpack.js
+++ b/src/lib/api/local-backpack.js
@@ -89,8 +89,12 @@ const openDB = () => new Promise((resolve, reject) => {
};
request.onsuccess = event => {
- _db = event.target.result;
- resolve(_db);
+ const db = event.target.result;
+ db.onclose = () => {
+ if (_db === db) _db = null;
+ };
+ _db = db;
+ resolve(db);
};
request.onerror = event => {
@@ -98,14 +102,25 @@ const openDB = () => new Promise((resolve, reject) => {
};
});
+const openTransaction = async mode => {
+ const db = await openDB();
+ try {
+ return db.transaction(STORE_NAME, mode);
+ } catch (error) {
+ if (error.name !== 'InvalidStateError') throw error;
+ if (_db === db) _db = null;
+ const reopened = await openDB();
+ return reopened.transaction(STORE_NAME, mode);
+ }
+};
+
const getBackpackContents = async ({
limit,
offset
}) => {
- const db = await openDB();
+ const transaction = await openTransaction('readonly');
return new Promise((resolve, reject) => {
- const transaction = db.transaction(STORE_NAME, 'readonly');
- transaction.onerror = event => {
+ transaction.onerror = transaction.onabort = event => {
reject(new Error(`Getting contents: ${event.target.error}`));
};
const store = transaction.objectStore(STORE_NAME);
@@ -141,10 +156,9 @@ const saveBackpackObject = async ({
// User interaction -- fine to show a permission dialog
requestPersistentStorage();
- const db = await openDB();
+ const transaction = await openTransaction('readwrite');
return new Promise((resolve, reject) => {
- const transaction = db.transaction(STORE_NAME, 'readwrite');
- transaction.onerror = event => {
+ transaction.onerror = transaction.onabort = event => {
reject(new Error(`Sving object: ${event.target.error}`));
};
const store = transaction.objectStore(STORE_NAME);
@@ -170,10 +184,9 @@ const deleteBackpackObject = async ({
id
}) => {
id = +id;
- const db = await openDB();
+ const transaction = await openTransaction('readwrite');
return new Promise((resolve, reject) => {
- const transaction = db.transaction(STORE_NAME, 'readwrite');
- transaction.onerror = event => {
+ transaction.onerror = transaction.onabort = event => {
reject(new Error(`Deleting object: ${event.target.error}`));
};
const store = transaction.objectStore(STORE_NAME);
@@ -190,10 +203,9 @@ const updateBackpackObject = async ({
name
}) => {
id = +id;
- const db = await openDB();
+ const transaction = await openTransaction('readwrite');
return new Promise((resolve, reject) => {
- const transaction = db.transaction(STORE_NAME, 'readwrite');
- transaction.onerror = event => {
+ transaction.onerror = transaction.onabort = event => {
reject(new Error(`Updating object: ${event.target.error}`));
};
const store = transaction.objectStore(STORE_NAME);
diff --git a/src/lib/collaboration/links.js b/src/lib/collaboration/links.js
index fe161d3bd13..46aace52fb5 100644
--- a/src/lib/collaboration/links.js
+++ b/src/lib/collaboration/links.js
@@ -2,6 +2,7 @@ import Emitter from './emitter.js';
import {encodeFrames, FrameDecoder, bytesToBase64, base64ToBytes} from './wire.js';
const RAW_SERIALIZATION = 'raw';
+const LEGACY_SERIALIZATION = 'binary';
const RELAY_MARK = 'mw-relay-1';
// Used when the browser does not report the SCTP message limit.
const DEFAULT_FRAME_LIMIT = 16 * 1024;
@@ -227,6 +228,7 @@ class RelayLink extends Link {
}
export {
+ LEGACY_SERIALIZATION,
RAW_SERIALIZATION,
RELAY_MARK,
DEFAULT_FRAME_LIMIT,
diff --git a/src/lib/collaboration/transport.js b/src/lib/collaboration/transport.js
index cfb045244d9..8cbaf4a977e 100644
--- a/src/lib/collaboration/transport.js
+++ b/src/lib/collaboration/transport.js
@@ -2,7 +2,7 @@ import PeerModule from 'peerjs';
import {resolvePeerConstructor} from './peer-constructor.js';
import Emitter from './emitter.js';
import {validateEnvelope, makeCtrl, KIND, CTRL, PROTOCOL_VERSION} from './protocol.js';
-import {DirectLink, RelayLink, RAW_SERIALIZATION, RELAY_MARK} from './links.js';
+import {DirectLink, RelayLink, LEGACY_SERIALIZATION, RAW_SERIALIZATION, RELAY_MARK} from './links.js';
import {APP_NAME} from '../constants/brand.js';
const DEFAULT_PEER_CONFIG = {
@@ -827,7 +827,8 @@ class Transport extends Emitter {
}
_wireConnection (conn) {
- if (this.destroyed) {
+ if (this.destroyed ||
+ (conn.serialization !== RAW_SERIALIZATION && conn.serialization !== LEGACY_SERIALIZATION)) {
conn.close();
return;
}
diff --git a/src/lib/components/tw-state-manager-hoc.jsx b/src/lib/components/tw-state-manager-hoc.jsx
index 2997917ad17..882b77d2195 100644
--- a/src/lib/components/tw-state-manager-hoc.jsx
+++ b/src/lib/components/tw-state-manager-hoc.jsx
@@ -32,6 +32,7 @@ import CollaborationService from '../collaboration/index.js';
import {setSearchParams} from '../utils/navigation';
import {defaultStageSize} from '../../reducers/custom-stage-size';
import {openSimpleDialog} from '../../reducers/modals';
+import {showStandardAlert} from '../../reducers/alerts';
const USERNAME_KEY = 'tw:username';
@@ -403,7 +404,10 @@ const TWStateManager = function (WrappedComponent) {
}
for (const extension of urlParams.getAll('extension')) {
- this.props.vm.extensionManager.loadExtensionURL(extension);
+ Promise.resolve(this.props.vm.extensionManager.loadExtensionURL(extension)).catch(error => {
+ log.error(`Could not load extension from URL parameter: ${extension}`, error);
+ this.props.onExtensionLoadError();
+ });
}
// Handle room codes for automatic collaboration
@@ -699,6 +703,7 @@ const TWStateManager = function (WrappedComponent) {
onSetCollaborationRoomId,
onSetCollaborationInvite,
onOpenCollaborationModal,
+ onExtensionLoadError,
reduxProjectId,
routingStyle,
username,
@@ -748,6 +753,7 @@ const TWStateManager = function (WrappedComponent) {
onSetCollaborationRoomId: PropTypes.func,
onSetCollaborationInvite: PropTypes.func,
onOpenCollaborationModal: PropTypes.func,
+ onExtensionLoadError: PropTypes.func,
openSimpleDialog: PropTypes.func.isRequired,
confirmWithMessage: PropTypes.func,
reduxProjectId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
@@ -785,6 +791,7 @@ const TWStateManager = function (WrappedComponent) {
onSetCollaborationRoomId: roomId => dispatch(setCollaborationRoomId(roomId)),
onSetCollaborationInvite: invite => dispatch(setCollaborationInvite(invite)),
onOpenCollaborationModal: () => dispatch(openCollaborationModal()),
+ onExtensionLoadError: () => dispatch(showStandardAlert('extensionLoadError')),
openSimpleDialog: config => dispatch(openSimpleDialog(config))
});
return connect(
diff --git a/src/lib/components/vm-listener-hoc.jsx b/src/lib/components/vm-listener-hoc.jsx
index dac9a5aa139..4d99f800253 100644
--- a/src/lib/components/vm-listener-hoc.jsx
+++ b/src/lib/components/vm-listener-hoc.jsx
@@ -10,7 +10,7 @@ import {updateBlockDrag} from '../../reducers/block-drag';
import {updateMonitors} from '../../reducers/monitors';
import {setProjectChanged, setProjectUnchanged} from '../../reducers/project-changed';
import {setRunningState, setTurboState, setStartedState} from '../../reducers/vm-status';
-import {showExtensionAlert} from '../../reducers/alerts';
+import {showExtensionAlert, showStandardAlert} from '../../reducers/alerts';
import {updateMicIndicator} from '../../reducers/mic-indicator';
import {
setFramerateState,
@@ -118,6 +118,7 @@ const vmListenerHOC = function (WrappedComponent) {
this.props.vm.on('RUNTIME_STOPPED', this.props.onRuntimeStopped);
this.props.vm.on('PROJECT_START', this.props.onGreenFlag);
this.props.vm.on('PERIPHERAL_CONNECTION_LOST_ERROR', this.props.onShowExtensionAlert);
+ this.props.vm.on('EXTENSION_LOAD_ERROR', this.props.onExtensionLoadError);
this.props.vm.on('MIC_LISTENING', this.props.onMicListeningUpdate);
this.props.vm.on('MIC_LISTENING', this.props.onMicListeningUpdate);
// tw: add handlers for our events
@@ -169,6 +170,7 @@ const vmListenerHOC = function (WrappedComponent) {
this.props.vm.off('RUNTIME_STOPPED', this.props.onRuntimeStopped);
this.props.vm.off('PROJECT_START', this.props.onGreenFlag);
this.props.vm.off('PERIPHERAL_CONNECTION_LOST_ERROR', this.props.onShowExtensionAlert);
+ this.props.vm.off('EXTENSION_LOAD_ERROR', this.props.onExtensionLoadError);
this.props.vm.off('MIC_LISTENING', this.props.onMicListeningUpdate);
this.props.vm.off('MIC_LISTENING', this.props.onMicListeningUpdate);
this.props.vm.off('HAS_CLOUD_DATA_UPDATE', this.handleCloudDataUpdate);
@@ -330,6 +332,7 @@ const vmListenerHOC = function (WrappedComponent) {
onCompileError,
onClearCompileErrors,
onShowExtensionAlert,
+ onExtensionLoadError,
/* eslint-enable no-unused-vars */
...props
} = this.props;
@@ -353,6 +356,7 @@ const vmListenerHOC = function (WrappedComponent) {
onRuntimeStarted: PropTypes.func.isRequired,
onRuntimeStopped: PropTypes.func.isRequired,
onShowExtensionAlert: PropTypes.func.isRequired,
+ onExtensionLoadError: PropTypes.func.isRequired,
onTargetsUpdate: PropTypes.func.isRequired,
onTurboModeOff: PropTypes.func.isRequired,
onTurboModeOn: PropTypes.func.isRequired,
@@ -447,6 +451,7 @@ const vmListenerHOC = function (WrappedComponent) {
onShowExtensionAlert: data => {
dispatch(showExtensionAlert(data));
},
+ onExtensionLoadError: () => dispatch(showStandardAlert('extensionLoadError')),
onMicListeningUpdate: listening => {
dispatch(updateMicIndicator(listening));
}
diff --git a/src/lib/error-reporter.js b/src/lib/error-reporter.js
index 1baf310fb9e..c128e8cc337 100644
--- a/src/lib/error-reporter.js
+++ b/src/lib/error-reporter.js
@@ -59,9 +59,23 @@ const isCrawler = () => {
const BROWSER_EXTENSION_FRAME = /(?:chrome|moz|safari|safari-web)-extension:\/\//;
+const ERROR_PREFIX = /^(?:Uncaught\s+)?(?:[A-Za-z]*Error:\s*)?/;
+
+const withoutErrorPrefixes = message => {
+ let text = message;
+ let previous;
+ do {
+ previous = text;
+ text = text.replace(ERROR_PREFIX, '');
+ } while (text !== previous);
+ return text;
+};
+
+const SANDBOXED_EXTENSION_ERROR = /^(?:[A-Za-z]*Error:\s*)+Uncaught\s/;
+
const isUnactionable = (message, stack) => {
- if (message === 'Script error.') return true;
- if (/^(?:(?:ReferenceError:\s*)?unsandboxed is not defined|Can't find variable: unsandboxed)$/i.test(message)) return true;
+ if (withoutErrorPrefixes(message) === 'Script error.') return true;
+ if (/unsandboxed/i.test(message) || SANDBOXED_EXTENSION_ERROR.test(message)) return true;
const frames = String(stack || '')
.split('\n')
.filter(line => /:\d+:\d+\)?\s*$/.test(line));
@@ -101,6 +115,24 @@ const isProjectScriptError = (name, stack) => (
// NetworkError is a transport failure with no stack, so nothing in it can be acted on.
const BROWSER_REFUSAL = /^(NotAllowedError|NetworkError)$/;
+const BROWSER_NOISE = /window\.ethereum|^Can't find variable: EmptyRanges$|lock the pointer|pointer lock/i;
+const DETACHED_NODE = /(?:removeChild|insertBefore).*not a child of this node/;
+
+const isMachineTranslated = () => {
+ try {
+ return /\btranslated-(?:ltr|rtl)\b/.test(document.documentElement.className);
+ } catch (e) {
+ return false;
+ }
+};
+
+const isOutsideMistWarp = (message, name, stack, kind) => (
+ BROWSER_NOISE.test(message) ||
+ name === 'AbortError' ||
+ (kind === 'rejection' && message === 'Unhandled promise rejection' && !stack) ||
+ (DETACHED_NODE.test(message) && isMachineTranslated())
+);
+
export const reportSiteError = ({message, stack = '', kind = 'uncaught', url = '', projectId = '', componentStack = '', name = ''}) => {
try {
const text = String(message || '').trim();
@@ -108,6 +140,7 @@ export const reportSiteError = ({message, stack = '', kind = 'uncaught', url = '
if (isBenignResizeObserverLoop(text, stack)) return;
if (isUnactionable(text, stack) || isCrawler() || isRehostedCopy()) return;
if (isProjectScriptError(name, stack) || BROWSER_REFUSAL.test(String(name || ''))) return;
+ if (isOutsideMistWarp(text, name, stack, kind)) return;
const href = String(url || window.location.href || '').slice(0, 2000);
if (href.includes('/errors')) return;
const signature = `${text.slice(0, 200)}|${href.slice(0, 200)}|${String(stack).slice(0, 200)}`;
diff --git a/src/lib/lazy-with-retry.js b/src/lib/lazy-with-retry.js
index 3c77d5234f1..57dc2520f30 100644
--- a/src/lib/lazy-with-retry.js
+++ b/src/lib/lazy-with-retry.js
@@ -41,12 +41,16 @@ export const retryableLazy = load => {
// Community page navigation can recover from assets removed by a deployment.
// Do not use this for editor imports, where a reload could discard project edits.
+const RELOAD_COOLDOWN = 60 * 1000;
+
export const reloadStalePage = (error, browser = window) => {
if (!isChunkLoadError(error)) return false;
try {
const key = `mw:chunk-reload:${BUILD_ID}`;
- if (browser.sessionStorage.getItem(key)) return false;
- browser.sessionStorage.setItem(key, '1');
+ const now = Date.now();
+ const last = Number(browser.sessionStorage.getItem(key));
+ if (last && now - last < RELOAD_COOLDOWN) return false;
+ browser.sessionStorage.setItem(key, String(now));
browser.location.reload();
return true;
} catch (e) {
@@ -56,6 +60,6 @@ export const reloadStalePage = (error, browser = window) => {
};
export const lazyWithReload = load => lazy(() => importWithRetry(load).catch(error => {
- reloadStalePage(error);
+ if (reloadStalePage(error)) return new Promise(() => {});
throw error;
}));
diff --git a/src/lib/originchats/signing.js b/src/lib/originchats/signing.js
index 8f9137017dc..72a1639cbd4 100644
--- a/src/lib/originchats/signing.js
+++ b/src/lib/originchats/signing.js
@@ -1,4 +1,5 @@
import {ensureScopes, getRotur} from '../rotur/client.js';
+import {isCancelled} from '../rotur/oauth.js';
import {signContent} from './device-key.js';
const SIGNING_SCOPE = 'signing:keys';
@@ -28,7 +29,11 @@ const signingStatus = async capabilities => {
};
const requestSigningPermission = async () => {
- await ensureScopes([SIGNING_SCOPE], {prompt: true});
+ try {
+ await ensureScopes([SIGNING_SCOPE], {prompt: true});
+ } catch (error) {
+ if (!isCancelled(error)) throw error;
+ }
return scopeGranted();
};
diff --git a/src/lib/rotur/oauth.js b/src/lib/rotur/oauth.js
index cbf20e47e4e..21f9d306355 100644
--- a/src/lib/rotur/oauth.js
+++ b/src/lib/rotur/oauth.js
@@ -39,6 +39,8 @@ const configure = options => Object.assign(config, options);
const oauthError = (code, message, extra) => Object.assign(new Error(message), {code}, extra);
+const isCancelled = error => Boolean(error) && (error.code === 'closed' || error.code === 'access_denied');
+
const base64url = bytes => btoa(String.fromCharCode(...bytes))
.replace(/\+/g, '-')
.replace(/\//g, '_')
@@ -374,6 +376,7 @@ export {
completeRedirect,
configure,
getAccessToken,
+ isCancelled,
onSessionChange,
readSession,
signIn,
diff --git a/src/lib/spotlight/BlockTypeInfo.js b/src/lib/spotlight/BlockTypeInfo.js
index f6ff194151b..5ec31ad2a54 100644
--- a/src/lib/spotlight/BlockTypeInfo.js
+++ b/src/lib/spotlight/BlockTypeInfo.js
@@ -368,6 +368,17 @@ export class BlockTypeInfo {
};
}
+ /**
+ * Identifies the variables, lists and broadcasts the enumerated dropdowns were built from.
+ * @param {*} workspace The workspace to describe
+ * @returns {string} A key that changes whenever one is created, deleted or renamed
+ */
+ static getVariablesKey (workspace) {
+ return workspace.getAllVariables()
+ .map(variable => `${variable.type}\u0000${variable.getId()}\u0000${variable.name}`)
+ .join('\u0000');
+ }
+
/**
* Enumerates all the different types of blocks, given a workspace.
* @param {Blockly} Blockly The Blockly instance
diff --git a/src/lib/utils/tw-polyfill.js b/src/lib/utils/tw-polyfill.js
index e82a6dcd701..f244dd5a57b 100644
--- a/src/lib/utils/tw-polyfill.js
+++ b/src/lib/utils/tw-polyfill.js
@@ -52,3 +52,11 @@ if (!Object.fromEntries) {
return object;
};
}
+
+if (typeof Object.hasOwn !== 'function') {
+ Object.defineProperty(Object, 'hasOwn', {
+ value: (object, property) => Object.prototype.hasOwnProperty.call(object, property),
+ configurable: true,
+ writable: true
+ });
+}
diff --git a/src/packager/common/idb.js b/src/packager/common/idb.js
index 2e6e78c017b..c55bdc0c5e1 100644
--- a/src/packager/common/idb.js
+++ b/src/packager/common/idb.js
@@ -83,8 +83,16 @@ class Database {
}
async createTransaction (readwrite) {
- const db = await this.open();
- const transaction = db.transaction(this.storeName, readwrite);
+ let db = await this.open();
+ let transaction;
+ try {
+ transaction = db.transaction(this.storeName, readwrite);
+ } catch (e) {
+ if (e.name !== 'InvalidStateError') throw e;
+ if (this.db === db) this.db = null;
+ db = await this.open();
+ transaction = db.transaction(this.storeName, readwrite);
+ }
const store = transaction.objectStore(this.storeName);
return {
db,
diff --git a/src/packager/packager/web/cache.js b/src/packager/packager/web/cache.js
index 333402c54b8..882923848e7 100644
--- a/src/packager/packager/web/cache.js
+++ b/src/packager/packager/web/cache.js
@@ -39,7 +39,15 @@ const removeExtraneous = async () => {
});
};
+let cleanupStarted = false;
+
const get = async (asset) => {
+ if (!cleanupStarted) {
+ cleanupStarted = true;
+ removeExtraneous().catch((err) => {
+ console.warn(err);
+ });
+ }
const {transaction, store} = await db.createTransaction('readonly');
return new Promise((resolve, reject) => {
Database.setTransactionErrorHandler(transaction, reject);
@@ -73,8 +81,6 @@ const set = async (asset, content) => {
const resetAll = () => db.deleteEverything();
-removeExtraneous();
-
export default {
get,
set,
diff --git a/src/playground/embed-storage-shim.js b/src/playground/embed-storage-shim.js
index b175e636b08..6ad8021bab9 100644
--- a/src/playground/embed-storage-shim.js
+++ b/src/playground/embed-storage-shim.js
@@ -1,3 +1,4 @@
+import '../lib/utils/tw-polyfill';
import * as fakeIndexedDB from 'fake-indexeddb';
const originOf = url => {
diff --git a/test/unit/collaboration/transport.test.js b/test/unit/collaboration/transport.test.js
index 77332670970..e8866b4649f 100644
--- a/test/unit/collaboration/transport.test.js
+++ b/test/unit/collaboration/transport.test.js
@@ -809,6 +809,20 @@ describe('older clients', () => {
expect(conn.frames).toEqual([]);
transport.destroy();
});
+
+ test('a channel no MistWarp client opens is closed before it can deliver data', async () => {
+ const {transport, peers} = makeTransport();
+ const hosted = transport.host('room1');
+ peers[0].simulateOpen();
+ await hosted;
+ const connected = jest.fn();
+ transport.on('peer-connected', connected);
+ const conn = peers[0].simulateIncomingConnection('stranger', {serialization: 'json'});
+ expect(conn.closed).toBe(true);
+ conn.simulateOpen();
+ expect(connected).not.toHaveBeenCalled();
+ transport.destroy();
+ });
});
describe('connection lifecycle regressions', () => {
diff --git a/test/unit/containers/sound-editor.test.jsx b/test/unit/containers/sound-editor.test.jsx
index f7fa2814ada..24c12c7d43a 100644
--- a/test/unit/containers/sound-editor.test.jsx
+++ b/test/unit/containers/sound-editor.test.jsx
@@ -311,6 +311,19 @@ describe('Sound Editor Container', () => {
expect(editor.submitNewSamples).not.toHaveBeenCalled();
});
+ test('renders without a buffer when the sprite has no sound at its index', () => {
+ vm.editingTarget.sprite.sounds = [];
+ vm.getSoundBuffer = jest.fn(index => vm.editingTarget.sprite.sounds[index].soundId);
+ const wrapper = mountWithIntl(
+