1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Fixes #4098: Fix crash due to React when trying to upgrade sync target

This commit is contained in:
Laurent Cozic 2020-11-19 16:38:44 +00:00
parent 30913a5d58
commit 65962e26ce
4 changed files with 24 additions and 3 deletions

View File

@ -15,7 +15,6 @@ const { render } = require('react-dom');
const { connect, Provider } = require('react-redux');
const Setting = require('@joplin/lib/models/Setting').default;
const shim = require('@joplin/lib/shim').default;
shim.setReact(React);
const { ImportScreen } = require('./ImportScreen.min.js');
const { ResourceScreen } = require('./ResourceScreen.js');
const { Navigator } = require('./Navigator.min.js');

View File

@ -27,6 +27,7 @@ const { shimInit } = require('@joplin/lib/shim-init-node.js');
const EncryptionService = require('@joplin/lib/services/EncryptionService');
const bridge = require('electron').remote.require('./bridge').default;
const { FileApiDriverLocal } = require('@joplin/lib/file-api-driver-local.js');
const React = require('react');
if (bridge().env() === 'dev') {
const newConsole = function(oldConsole) {
@ -86,7 +87,7 @@ try {
keytar = null;
}
shimInit(null, keytar);
shimInit(null, keytar, React);
// Disable drag and drop of links inside application (which would
// open it as if the whole app was a browser)

View File

@ -51,7 +51,7 @@ const gunzipFile = function(source, destination) {
});
};
function shimInit(sharp = null, keytar = null) {
function shimInit(sharp = null, keytar = null, React = null) {
keytar = (shim.isWindows() || shim.isMac()) && !shim.isPortable() ? keytar : null;
shim.fsDriver = () => {
@ -67,6 +67,12 @@ function shimInit(sharp = null, keytar = null) {
return shim.fsDriver_;
};
if (React) {
shim.react = () => {
return React;
};
}
shim.randomBytes = async count => {
const buffer = require('crypto').randomBytes(count);
return Array.from(buffer);

View File

@ -1,6 +1,21 @@
import { ResourceEntity } from './services/database/types';
let isTestingEnv_ = false;
// We need to ensure that there's only one instance of React being used by
// all the packages. In particular, the lib might need React to define
// generic hooks, but it shouldn't have React in its dependencies as that
// would cause the following error:
//
// https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react
//
// So instead, the **applications** include React as a dependency, then
// pass it to any other packages using the shim. Essentially, only one
// package should require React, and in our case that should be one of the
// applications (app-desktop, app-mobile, etc.) since we are sure they
// won't be dependency to other packages (unlike the lib which can be
// included anywhere).
let react_: any = null;
const shim = {