Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

perf: dynamic imports for smaller bundle size

thecodrr12ba327b02e1
diff --git a/apps/web/package.json b/apps/web/package.json
index c7ad48125..8b156e614 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -22,8 +22,6 @@
"lzutf8": "^0.5.8",
"notes-core": "npm:@streetwriters/notesnook-core@latest",
"qclone": "^1.0.4",
- "quill": "https://github.com/thecodrr/quill.git#develop",
- "quill-magic-url": "^3.0.0",
"react": "^17.0.1",
"react-app-polyfill": "^2.0.0",
"react-dom": "^17.0.1",
diff --git a/apps/web/src/components/dialogs/recovery-key-dialog.js b/apps/web/src/components/dialogs/recovery-key-dialog.js
index dfb1f4354..1e58f9035 100644
--- a/apps/web/src/components/dialogs/recovery-key-dialog.js
+++ b/apps/web/src/components/dialogs/recovery-key-dialog.js
@@ -2,13 +2,15 @@ import React, { useEffect, useState } from "react";
import { Text, Flex, Button } from "rebass";
import Dialog, { showDialog } from "./dialog";
import { db } from "../../common";
-import { QRCode } from "react-qrcode-logo";
import Logo from "../../assets/notesnook-small.png";
import download from "../../utils/download";
import ClipboardJS from "clipboard";
import Config from "../../utils/config";
import { captureMessage } from "@sentry/react";
import { useStore as useUserStore } from "../../stores/user-store";
+import { Suspense } from "react";
+
+const QRCode = React.lazy(() => import("../../re-exports/react-qrcode-logo"));
function RecoveryKeyDialog(props) {
const [key, setKey] = useState();
@@ -34,7 +36,7 @@ function RecoveryKeyDialog(props) {
captureMessage("Error while copying text.");
});
return () => {
- clipboard.destroy();
+ clipboard?.destroy();
};
}, []);
@@ -65,13 +67,16 @@ function RecoveryKeyDialog(props) {
{key}
</Text>
<Flex justifyContent="space-around" alignItems="center">
- <QRCode
- value={key}
- logoImage={Logo}
- logoWidth={25}
- ecLevel={"M"}
- logoHeight={25}
- />
+ <Suspense fallback={<div />}>
+ <QRCode
+ value={key}
+ logoImage={Logo}
+ logoWidth={25}
+ ecLevel={"M"}
+ logoHeight={25}
+ />
+ </Suspense>
+
<Flex flexDirection="column">
<Button
data-clipboard-text={key}
diff --git a/apps/web/src/index.js b/apps/web/src/index.js
index 57f455952..4c5604de8 100644
--- a/apps/web/src/index.js
+++ b/apps/web/src/index.js
@@ -8,10 +8,12 @@ import { Integrations } from "@sentry/tracing";
import "./index.css";
import * as serviceWorker from "./serviceWorker";
import Modal from "react-modal";
-import App from "./App";
import { MotionConfig, AnimationFeature, GesturesFeature } from "framer-motion";
import Splash from "./views/splash";
import { getAppVersion } from "./utils/useVersion";
+import { Suspense } from "react";
+
+const App = React.lazy(() => import("./App"));
if (process.env.NODE_ENV === "production") {
console.log = () => {};
@@ -39,9 +41,11 @@ ReactDOM.render(
<Splash
onLoadingFinished={() => {
ReactDOM.render(
- <MotionConfig features={[AnimationFeature, GesturesFeature]}>
- <App />
- </MotionConfig>,
+ <Suspense fallback={<div />}>
+ <MotionConfig features={[AnimationFeature, GesturesFeature]}>
+ <App />
+ </MotionConfig>
+ </Suspense>,
document.getElementById("root")
);
}}
diff --git a/apps/web/src/interfaces/crypto.js b/apps/web/src/interfaces/crypto.js
index ead8544e8..2d6b5fdb2 100644
--- a/apps/web/src/interfaces/crypto.js
+++ b/apps/web/src/interfaces/crypto.js
@@ -1,21 +1,26 @@
-import lzutf8 from "lzutf8";
-
/**
- * @return {Uint8Array}
+ * @return {Promise<Uint8Array>}
*/
function compress(data) {
- return lzutf8.compress(data, {
- blockSize: 64 * 1024 * 1024,
- outputEncoding: "ByteArray",
- inputEncoding: "String",
+ return import("lzutf8").then((lzutf8) => {
+ lzutf8.compress(data, {
+ blockSize: 64 * 1024 * 1024,
+ outputEncoding: "ByteArray",
+ inputEncoding: "String",
+ });
});
}
+/**
+ * @return {Promise<string>}
+ */
function decompress(data) {
- return lzutf8.decompress(data, {
- blockSize: 64 * 1024 * 1024,
- inputEncoding: "ByteArray",
- outputEncoding: "String",
+ return import("lzutf8").then((lzutf8) => {
+ return lzutf8.decompress(data, {
+ blockSize: 64 * 1024 * 1024,
+ inputEncoding: "ByteArray",
+ outputEncoding: "String",
+ });
});
}
@@ -48,7 +53,7 @@ class Crypto {
await this._initialize();
return global.ncrypto.encrypt.call(this, passwordOrKey, {
type: "uint8array",
- data: compress(plainData),
+ data: await compress(plainData),
});
};
@@ -91,7 +96,7 @@ class Crypto {
*/
_decryptCompressed = async (passwordOrKey, cipherData) => {
cipherData.output = "uint8array";
- return decompress(
+ return await decompress(
await global.ncrypto.decrypt.call(this, passwordOrKey, cipherData)
);
};
@@ -173,10 +178,10 @@ class CryptoWorker {
* @param {{password: string}|{key:string, salt: string}} passwordOrKey - password or derived key
* @param {string} data - the plaintext data
*/
- _encryptCompressed = (passwordOrKey, data) => {
+ _encryptCompressed = async (passwordOrKey, data) => {
const message = {
passwordOrKey,
- data: { type: "uint8array", data: compress(data) },
+ data: { type: "uint8array", data: await compress(data) },
};
return this._communicate("encrypt", message, [message.data.data.buffer]);
};
@@ -218,7 +223,7 @@ class CryptoWorker {
*/
_decryptCompressed = async (passwordOrKey, cipherData) => {
cipherData.output = "uint8array";
- return decompress(
+ return await decompress(
await this._communicate("decrypt", {
passwordOrKey,
cipher: cipherData,
diff --git a/apps/web/src/re-exports/react-qrcode-logo.js b/apps/web/src/re-exports/react-qrcode-logo.js
new file mode 100644
index 000000000..fbf023eb9
--- /dev/null
+++ b/apps/web/src/re-exports/react-qrcode-logo.js
@@ -0,0 +1 @@
+export { QRCode as default } from "react-qrcode-logo";
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index 748385a40..77a42c27c 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -7508,11 +7508,6 @@ jsesc@~0.5.0:
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d"
integrity sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=
-jshashes@^1.0.8:
- version "1.0.8"
- resolved "https://registry.yarnpkg.com/jshashes/-/jshashes-1.0.8.tgz#f60d837428383abf73ab022e1542e6614bd75514"
- integrity sha512-btmQZ/w1rj8Lb6nEwvhjM7nBYoj54yaEFo2PWh3RkxZ8qNwuvOxvQYN/JxVuwoMmdIluL+XwYVJ+pEEZoSYybQ==
-
json-parse-better-errors@^1.0.1, json-parse-better-errors@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
@@ -7660,6 +7655,11 @@ last-call-webpack-plugin@^3.0.0:
lodash "^4.17.5"
webpack-sources "^1.1.0"
+lean-he@^2.1.2:
+ version "2.1.2"
+ resolved "https://registry.yarnpkg.com/lean-he/-/lean-he-2.1.2.tgz#50c2422f0ca42f6737c9c1988b555cf00ebc712f"
+ integrity sha512-g/cq01j/rnv7JWoxFmeLgJdd/CucksyDtS+pyepO89EdT0O4KfHJokOVz/xQ4mvjKJzcrj87Q3/s2ESou90WCQ==
+
leven@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2"
@@ -8387,19 +8387,29 @@ normalize-url@^4.5.0:
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-4.5.0.tgz#453354087e6ca96957bd8f5baf753f5982142129"
integrity sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==
+notes-core@../notes-core:
+ version "6.4.0"
+ dependencies:
+ fast-sort "^2.0.1"
+ fuzzysearch "^1.0.3"
+ lean-he "^2.1.2"
+ no-internet "^1.5.2"
+ qclone "^1.0.4"
+ quill-delta-to-html "^0.12.0"
+ spark-md5 "^3.0.1"
+ turndown "^7.0.0"
+
"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":
- version "6.3.0"
- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#ce4ab84b1481430986008ad786a73fd7711852ee"
+ version "6.4.0"
+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#d655fae4986861c0ddea559613a448554c046970"
dependencies:
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"
- he "^1.2.0"
- jshashes "^1.0.8"
+ lean-he "^2.1.2"
no-internet "^1.5.2"
qclone "^1.0.4"
quill-delta-to-html "^0.12.0"
spark-md5 "^3.0.1"
- transfun "^1.0.2"
turndown "^7.0.0"
npm-run-path@^2.0.0:
@@ -11951,11 +11961,6 @@ tr46@^2.0.2:
dependencies:
punycode "^2.1.1"
-transfun@^1.0.2:
- version "1.0.2"
- resolved "https://registry.yarnpkg.com/transfun/-/transfun-1.0.2.tgz#14a3116296a8d921cbf9678ebd5eee1c5bb77b98"
- integrity sha1-FKMRYpao2SHL+WeOvV7uHFu3e5g=
-
tree-kill@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"