Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: The rendering process no longer crashes when pasting large amounts of `text/siyuan` content into the editor https://github.com/siyuan-note/siyuan/issues/17569

Daniel596a7f750614
diff --git a/app/electron/main.js b/app/electron/main.js
index 81f3f0929a..9303ebb180 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -484,6 +484,11 @@ const initMainWindow = () => {
}
});
+ currentWindow.webContents.on('render-process-gone', (event, details) => {
+ console.log('Reason: ', details.reason);
+ console.log('Exit code', details.exitCode);
+ });
+
if (windowState.isDevToolsOpened) {
currentWindow.webContents.openDevTools({mode: "bottom"});
}
diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts
index 1237edd9b6..369057baae 100644
--- a/app/src/protyle/util/paste.ts
+++ b/app/src/protyle/util/paste.ts
@@ -375,9 +375,43 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
insertHTML(removeZWJ(textPlain).replace(/```/g, "\u200D```"), protyle);
return;
} else if (siyuanHTML) {
+ async function streamInsert(container: HTMLElement, bigHtmlString: string) {
+ const iframe = document.createElement('iframe');
+ iframe.style.display = 'none';
+ document.body.appendChild(iframe);
+
+ const doc = iframe.contentWindow.document;
+ doc.open();
+
+ const chunkSize = 102400;
+ let offset = 0;
+ while (offset < bigHtmlString.length) {
+ const chunk = bigHtmlString.substring(offset, offset + chunkSize);
+ doc.write(chunk);
+ offset += chunkSize;
+ await new Promise(resolve => setTimeout(resolve, 0));
+ }
+
+ doc.close();
+
+ const fragment = document.createDocumentFragment();
+ while (doc.body.firstChild) {
+ fragment.appendChild(doc.body.firstChild);
+ }
+
+ container.innerHTML = '';
+ container.appendChild(fragment);
+
+ document.body.removeChild(iframe);
+ }
+
// 编辑器内部粘贴
const tempElement = document.createElement("div");
- tempElement.innerHTML = siyuanHTML;
+ if (1024 * 512 < siyuanHTML.length) {
+ await streamInsert(tempElement, siyuanHTML)
+ } else {
+ tempElement.innerHTML = siyuanHTML;
+ }
if (range.toString()) {
let types: string[] = [];
let linkElement: HTMLElement;