SheepTester/scratch-gui

Cannot load projects if current project uses cloud variables

SheepTester opened this issue · 0 comments

ref: adam on instagram

gui  TypeError: Cannot create property 'onclose' on boolean 'true'
    at CloudProvider.value (gui.min.js:1)
    at n.value (gui.min.js:1)
    at n.value (gui.min.js:1)
    at n.e (lib.min.js:12)
    at n.r.emit (lib.min.js:24)
    at t.<anonymous> (lib.min.js:157)
    at t.r.emit (lib.min.js:24)
    at t.value (lib.min.js:83)
    at n.value (lib.min.js:157)
    at n.value (lib.min.js:157)

This sets connection to true, which is all fine and dandy because _openConnection isn't called so no properties are being set on it (reading properties of true is fine though).

this.connection = true;

However, there are two cases where properties will still get set on true. When changing the cloud IP via special cloud behaviours:

if (this.connection) {
this.connection.onclose = () => {};
this.connection.onerror = () => {};
this.connection.close();
}

and when closing the connection:

if (this.connection &&
this.connection.readyState !== WebSocket.CLOSING &&
this.connection.readyState !== WebSocket.CLOSED) {
log.info('Request close cloud connection without reconnecting');
// Remove listeners, after this point we do not want to react to connection updates
this.connection.onclose = () => {};
this.connection.onerror = () => {};
this.connection.close();
}

The latter only happens when there's already a project using cloud variables, so when you load a new project, I guess it first requests to close the connection, and an error is thrown preventing the new project from loading

And of course, this requires that the cloud host remains unset