Skip to content

更快导入腳本#498

Merged
CodFrm merged 2 commits intoscriptscat:mainfrom
cyfung1031:patch_faster_import
Jul 6, 2025
Merged

更快导入腳本#498
CodFrm merged 2 commits intoscriptscat:mainfrom
cyfung1031:patch_faster_import

Conversation

@cyfung1031
Copy link
Copy Markdown
Collaborator

@cyfung1031 cyfung1031 commented Jul 6, 2025

production 中不使用 React.StrictMode

PS. React 18 中 React.StrictMode 會令useEffect執行兩次。

App.tsx 把 UI 和 click callback 都加Cache,避免重新生成

@CodFrm
Copy link
Copy Markdown
Member

CodFrm commented Jul 6, 2025

只有在dev模式下才会执行两次,我认为是没问题的,这样也可以避免更多的问题

看见了develop模式才使用

Comment thread src/pages/import/App.tsx Outdated

const scriptImportAsync = async (item: ScriptData) => {
try {
await sleep(1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么sleep 1s,最后也是

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/scriptscat/scriptcat/pull/498/files#diff-0a1b1ad14e5c3689791273dfe01c62ac432bb7fbf7e26b6651e99175961f667cR189

后续也是一个for循环处理的,至少前面这个sleep是没有太大意义的吧

Copy link
Copy Markdown
Collaborator Author

@cyfung1031 cyfung1031 Jul 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep 是ms. 1ms
之前在Orion匯入時,瀏覽器沒反應。我覺得有可能是載入速度太快令瀏覽器卡住了

setTimeout 1ms 是為了用macroTask切開大量腳本導入時瀏覽器無法回響的問題

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyfung1031 加了1ms就可以了吗?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

沒實際感覺到哈哈
兩個sleep 都可以刪掉

@cyfung1031
Copy link
Copy Markdown
Collaborator Author

@CodFrm 我先把 await sleep(1); 注釋掉。日後有需要再加

@CodFrm CodFrm merged commit 6b7ee3d into scriptscat:main Jul 6, 2025
2 checks passed
@cyfung1031 cyfung1031 deleted the patch_faster_import branch July 8, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants