Skip to content

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

:bug: Fix opening documents in new mobile tabs https://github.com/siyuan-note/siyuan/issues/16094

Daniel063b53e11bfa
diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts
index d763a546be..31ac389bac 100644
--- a/app/src/mobile/editor.ts
+++ b/app/src/mobile/editor.ts
@@ -187,6 +187,7 @@ export const loadMobileFileById = (app: App, id: string, action: TProtyleAction[
mergedOptions: protyleOptions,
signal,
fail,
+ isValid,
cb() {
if (!isValid()) {
fail();
@@ -227,6 +228,7 @@ export const loadMobileFileById = (app: App, id: string, action: TProtyleAction[
protyle: window.siyuan.mobile.editor.protyle,
action: actionList,
scrollPosition,
+ isValid,
afterCB() {
if (!isValid()) {
fail();
@@ -245,9 +247,6 @@ export const loadMobileFileById = (app: App, id: string, action: TProtyleAction[
console.error(error);
fail();
}
- if (!completed) {
- fail();
- }
}, undefined, undefined, signal).then(() => {
if (!getDocHandled) {
fail();
diff --git a/app/src/mobile/tabs/MobileTabs.ts b/app/src/mobile/tabs/MobileTabs.ts
index 88de92ac4b..0f9d5a79c7 100644
--- a/app/src/mobile/tabs/MobileTabs.ts
+++ b/app/src/mobile/tabs/MobileTabs.ts
@@ -198,6 +198,7 @@ export class MobileTabs {
data.notebook = notebookId;
}
let handled = false;
+ // 仅取消导航状态,不中止底层请求,避免部分 WebView 的 fetch 包装层将 AbortError 暴露为未处理异常。
void fetchPost("/api/block/getBlockInfo", data, (response) => {
handled = true;
if (response.code === 0 && response.data?.rootID) {
@@ -205,7 +206,7 @@ export class MobileTabs {
} else {
reject(new InvalidMobileTabTargetError(response.msg));
}
- }, undefined, undefined, signal).then(() => {
+ }).then(() => {
if (!handled && !signal?.aborted) {
reject(new Error("Failed to resolve mobile tab target"));
}
@@ -271,6 +272,7 @@ export class MobileTabs {
resolve(result);
};
abortController.signal.addEventListener("abort", () => finish("cancelled"), {once: true});
+ // 过期响应由 epoch 和 isValid 丢弃,不向 fetch 传递 signal。
loadMobileFileById(this.app, loadID, loadAction, options.scrollPosition, info.box, (protyle) => {
if (epoch !== this.navigationEpoch) {
finish("cancelled");
@@ -309,7 +311,7 @@ export class MobileTabs {
}
finish("success");
options.afterOpen?.(protyle);
- }, options.forceReload, () => epoch === this.navigationEpoch, abortController.signal, loadScroll, false, (invalid) => {
+ }, options.forceReload, () => epoch === this.navigationEpoch, undefined, loadScroll, false, (invalid) => {
finish(abortController.signal.aborted ? "cancelled" : (invalid ? "invalid" : "failed"));
});
});
diff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.ts
index 7403ef0dec..349775bb02 100644
--- a/app/src/protyle/scroll/saveScroll.ts
+++ b/app/src/protyle/scroll/saveScroll.ts
@@ -69,6 +69,7 @@ export const getDocByScroll = (options: {
updateReadonly?: boolean,
signal?: AbortSignal,
fail?: (invalid?: boolean) => void,
+ isValid?: () => boolean,
}) => {
const fetchDoc = (params: Record<string, any>, callback: (response: IWebSocketData) => void) => {
let handled = false;
@@ -92,7 +93,6 @@ export const getDocByScroll = (options: {
}
}
const renderDoc = (response: IWebSocketData) => {
- let callbackCalled = false;
try {
onGet({
scrollPosition: options.mergedOptions?.scrollPosition,
@@ -101,19 +101,16 @@ export const getDocByScroll = (options: {
action: actions,
scrollAttr: options.scrollAttr,
afterCB: options.cb ? () => {
- callbackCalled = true;
options.cb(response.data.keywords);
} : undefined,
- updateReadonly: options.updateReadonly
+ updateReadonly: options.updateReadonly,
+ isValid: options.isValid,
});
} catch (error) {
console.error(error);
options.fail?.();
return;
}
- if (options.cb && !callbackCalled) {
- options.fail?.();
- }
};
if (options.scrollAttr?.zoomInId && options.scrollAttr?.rootId && options.scrollAttr.zoomInId !== options.scrollAttr.rootId) {
const getDocParam: Record<string, any> = {
diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts
index 1fd775aeb9..1266cf982e 100644
--- a/app/src/protyle/util/onGet.ts
+++ b/app/src/protyle/util/onGet.ts
@@ -37,8 +37,12 @@ export const onGet = (options: {
updateReadonly?: boolean,
scrollPosition?: ScrollLogicalPosition,
afterCB?: () => void,
- dataDocType?: string
+ dataDocType?: string,
+ isValid?: () => boolean,
}) => {
+ if (options.isValid && !options.isValid()) {
+ return;
+ }
if (!options.action) {
options.action = [];
}
@@ -131,6 +135,9 @@ export const onGet = (options: {
docInfoParam.notebook = options.protyle.notebookId;
}
fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
+ if (options.isValid && !options.isValid()) {
+ return;
+ }
if (options.protyle.options.render.title) {
// 页签没有打开
options.protyle.title.render(options.protyle, response);