Skip to content

Improve editor refresh for kernel API /api/block/moveBlock #14559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wish5115 opened this issue Apr 10, 2025 · 11 comments
Closed

Improve editor refresh for kernel API /api/block/moveBlock #14559

wish5115 opened this issue Apr 10, 2025 · 11 comments
Assignees
Milestone

Comments

@wish5115
Copy link

wish5115 commented Apr 10, 2025

/api/block/moveBlock调用后,在新文档中无法实时显示块,需要F5刷新才行,怎么改进?

In what scenarios do you need this feature?

假设有A,B两个文档,A,B文档同时打开,A文档的块通过api /api/block/moveBlock 移动到B文档后,如果第一次移动到B时,B文档无法实时显示移动过来的块,需要按F5刷新才行,有没有办法不通过刷新也能实时显示?

目前通过 protyle.reload() 刷新实现,但这种刷新,如果移动过来的块在文档的下方,页面会闪动以下,体验不好。

Describe the optimal solution

期望移动过来的块能实时显示。

Describe the candidate solution

No response

Other information

No response

@88250
Copy link
Member

88250 commented Apr 10, 2025

我这里分屏后测试,两个页签都会自动刷新内容的。

@88250
Copy link
Member

88250 commented Apr 10, 2025

补充个录屏:

issue.webm

暂时关了,欢迎随时跟帖,谢谢。

@88250 88250 closed this as completed Apr 10, 2025
@wish5115
Copy link
Author

wish5115 commented Apr 10, 2025

我这里分屏后测试,两个页签都会自动刷新内容的。

两个以上同时移动更容易出问题,如下图所示

Image

总之,这个api不稳定,每次仅移动一个块时,时好时坏,同时移动多个块时,第一次移动到新文档一般都有问题。

我测试的版本有 v3.1.24,v3.1.27,v3.1.10 ,都有这个问题,记得其他版本也有问题。


附测试代码

let to = '20250410123049-anh992z';
await fetchSyncPost('/api/block/moveBlock', {
                          "id": '20250316200508-wkewsu8',
                          "previousID": to,
                          "parentID": '',
                    });
await fetchSyncPost('/api/block/moveBlock', {
                          "id": '20250316201817-bmmtfuh',
                          "previousID": to,
                          "parentID": '',
                    });

async function fetchSyncPost(url, data, method = 'POST') {
     return await (await fetch(url, {method: method, body: JSON.stringify(data||{})})).json();
 }

@wish5115
Copy link
Author

wish5115 commented Apr 10, 2025

另外,这个api还有一个小问题,就是当只用parentID且previousID填空字符串时,会报错:previousID can not be the ID of a document

必须删除previousID或填undefined才行

@TCOTC
Copy link
Contributor

TCOTC commented Apr 10, 2025

请使用 3.1.27 测试

@wish5115
Copy link
Author

wish5115 commented Apr 10, 2025

请使用 3.1.27 测试

3.1.27 也是一样的问题。

@wish5115
Copy link
Author

暂时用这种方案,移动后,先检查目标文档所有块是否已显示,有未显示的再刷新

function reloadProtyle(ids = [], node = null) {
    node = node || document;
    if(ids.length > 0) {
        // 检查id的元素是否存在
        let hasNotExistEl = false;
        for(const id of ids){
            const el = node.querySelector(`[data-node-id="${id}"]`);
            if(!el) {
                hasNotExistEl = true;
                break;
            }
        }
        if(hasNotExistEl) (siyuan?.mobile||getProtyle()?.model)?.editor?.reload();
    } else {
        (siyuan?.mobile||getProtyle()?.model)?.editor?.reload();
    }
}

@88250
Copy link
Member

88250 commented Apr 10, 2025

#14559 (comment) 我这里可以重现了 @Vanessa219

#14559 (comment) previousIDparentID 是二选一的,优先使用 previousID,所以如果传入了这个字段的话值不能为空。

@88250 88250 reopened this Apr 10, 2025
@88250 88250 changed the title /api/block/moveBlock调用后,在新文档中无法实时显示块,需要F5刷新才行,怎么改进? Improve editor refresh for kernel API /api/block/moveBlock Apr 10, 2025
@88250 88250 added this to the 3.1.28 milestone Apr 10, 2025
@wish5115
Copy link
Author

#14559 (comment) previousIDparentID 是二选一的,优先使用 previousID,所以如果传入了这个字段的话值不能为空。

收到,感谢D大!

@88250 88250 closed this as completed Apr 13, 2025
@88250 88250 reopened this Apr 13, 2025
@88250
Copy link
Member

88250 commented Apr 13, 2025

我和 V 分析了下,这个前端无法实时刷新(因为跨编辑器 move 比较复杂),但可以实现内核推送编辑器刷新,将就就用这个方案吧。

88250 added a commit that referenced this issue Apr 13, 2025

Verified

This commit was signed with the committer’s verified signature.
@88250 88250 closed this as completed Apr 13, 2025
@wish5115
Copy link
Author

我和 V 分析了下,这个前端无法实时刷新(因为跨编辑器 move 比较复杂),但可以实现内核推送编辑器刷新,将就就用这个方案吧。

OK!感谢D大和V姐!辛苦了!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants