Skip to content

紧急修正: GM.delete/setValue Promise不fulfill#865

Merged
CodFrm merged 7 commits intoscriptscat:mainfrom
cyfung1031:pr-urgent-fix-60391
Oct 21, 2025
Merged

紧急修正: GM.delete/setValue Promise不fulfill#865
CodFrm merged 7 commits intoscriptscat:mainfrom
cyfung1031:pr-urgent-fix-60391

Conversation

@cyfung1031
Copy link
Copy Markdown
Collaborator

合并后请发布新Beta版

之前没考虑 deleteValue 时,value 本身就是undefined, 因此 GM.deleteValue(xxx) 不会 Promise fulfill
现在没值更新也是发消息。
收消息那边处理

@CodFrm CodFrm changed the base branch from main to release/v1.2 October 20, 2025 06:13
@CodFrm CodFrm changed the base branch from release/v1.2 to main October 20, 2025 06:13
@CodFrm
Copy link
Copy Markdown
Member

CodFrm commented Oct 21, 2025

一个可复现的脚本:

// ==UserScript==
// @name         New Userscript T0Z1-1
// @namespace    https://docs.scriptcat.org/
// @version      0.1.0
// @description  try to take over the world!
// @author       You
// @match        https://github.com/scriptscat/scriptcat/pull/865
// @icon         https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant        GM.setValue
// @grant        GM.deleteValue
// ==/UserScript==

(function () {
    'use strict';
    GM.deleteValue('test1').then(() => {
        console.log("delete ok");
    });

    GM.setValue('test1', undefined).then(() => {
        console.log('set ok');
    });

    // 变量值没变
    GM.setValue('test2', 1).then(() => {
        console.log('set test2 ok');
        GM.setValue('test2', 1).then(() => {
            console.log('set2 test2 ok');
        });
    });
    // Your code here...
})();

@CodFrm CodFrm requested a review from Copilot October 21, 2025 08:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

此PR修复了 GM.deleteValueGM.setValue 方法在值未实际更新时 Promise 不会 fulfill 的关键 bug。主要更改包括:

  • 添加 valueUpdated 标志来追踪值是否实际更新
  • 确保即使值未改变也发送消息以 fulfill Promise
  • 在 content script 中只在值实际更新时处理值变更

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/app/service/service_worker/value.ts 添加 valueUpdated 标志并修复了一个 bug (使用错误的变量引用 config![tabKey][key].default);无条件发送消息确保 Promise fulfill
src/app/service/service_worker/value.test.ts 更新测试以验证 valueUpdated 标志在各种场景下的行为
src/app/service/service_worker/runtime.ts 添加条件判断,仅在值实际更新时更新早期启动脚本
src/app/service/queue.ts TScriptValueUpdate 类型中添加 valueUpdated 字段
src/app/service/content/types.ts ValueUpdateDataEncoded 类型中添加 valueUpdated 字段
src/app/service/content/gm_api.ts valueUpdate 方法中添加条件判断,仅在值实际更新时处理值变更逻辑
src/app/service/content/gm_api.test.ts 更新测试以包含 valueUpdated 字段并改进测试覆盖率
src/app/repo/scripts.ts 使用 Partial<Record<>> 改进 UserConfig 类型定义的类型安全性

Comment thread src/app/service/content/gm_api.ts Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@CodFrm CodFrm merged commit 43572a3 into scriptscat:main Oct 21, 2025
1 of 2 checks passed
@cyfung1031
Copy link
Copy Markdown
Collaborator Author

@CodFrm 这个bug有明显影响脚本操作。可以的话先发个Beta版。
1.2.0-beta.2 到现在最新的其他Commit都是小改动。应该问题不大

@CodFrm
Copy link
Copy Markdown
Member

CodFrm commented Oct 21, 2025

@cyfung1031 上一个版本的edge的审核还没给我过,我在等edge审核过了再发

@cyfung1031
Copy link
Copy Markdown
Collaborator Author

cyfung1031 commented Oct 22, 2025

@cyfung1031 上一个版本的edge的审核还没给我过,我在等edge审核过了再发

Edge 1.2.0.1300 了
个人认为 #859 也可以合并一下才发布

@cyfung1031 cyfung1031 deleted the pr-urgent-fix-60391 branch December 21, 2025 09:39
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.

3 participants