RSSHub icon indicating copy to clipboard operation
RSSHub copied to clipboard

【代码问题】未知原因导致副作用重复触发

Open GrinZero opened this issue 1 year ago • 1 comments

路由地址

NOROUTE

完整路由地址

NOROUTE

相关文档

Any

预期是什么?

我尝试在 lib/utils/ofetch 这个文件中添加了有副作用的代码用于启动 devtools,但是 devtools 不断报错。 经过 debugger,我添加了这一部分代码: image

尝试发现,是因为存在循环引用导致的函数副作用被二次触发。对应的位置应该在这里: image

我想询问一下这部分代码能否被移动到其他地方以解决循环引用问题。因为我理解中,这或许会导致 ofetch 文件导出的 rofetch 出现无法预知的行为。

实际发生了什么?

即便使用了动态导入,实际上并没有解决循环引用导致的 ofetch.ts 存在的副作用隐患。可能导致导出的 rofetch 对象存在未知行为。

部署

RSSHub 演示 (https://rsshub.app)

部署相关信息

No response

额外信息

register Error
    at <anonymous> (/Users/bugyaluwang/Desktop/my-projects/RSSHub/lib/utils/ofetch.ts:6:25)
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:106:12)
register Error
    at logger (/Users/bugyaluwang/Desktop/my-projects/RSSHub/lib/utils/ofetch.ts:6:25)
    at Object.<anonymous> (/Users/bugyaluwang/Desktop/my-projects/RSSHub/lib/utils/ofetch.ts:35:16)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Object.transformer (/Users/bugyaluwang/Desktop/my-projects/RSSHub/node_modules/.pnpm/[email protected]/node_modules/tsx/dist/register-DpmFHar1.cjs:2:1186)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Module._load (node:internal/modules/cjs/loader:1019:12)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:177:18)
    at ofetch (/Users/bugyaluwang/Desktop/my-projects/RSSHub/lib/utils/got.ts:2:20)
    at Object.<anonymous> (/Users/bugyaluwang/Desktop/my-projects/RSSHub/lib/utils/got.ts:86:27)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Object.transformer (/Users/bugyaluwang/Desktop/my-projects/RSSHub/node_modules/.pnpm/[email protected]/node_modules/tsx/dist/register-DpmFHar1.cjs:2:1186)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Module._load (node:internal/modules/cjs/loader:1019:12)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:177:18)

这不是重复的 issue

  • [X] 我已经搜索了 现有 issue,以确保该错误尚未被报告。

GrinZero avatar Oct 16 '24 08:10 GrinZero

很抱歉得到了错误的结论,目前未知是什么原因导致重复触发

GrinZero avatar Oct 18 '24 03:10 GrinZero

link -> https://github.com/privatenumber/tsx/issues/499

GrinZero avatar Oct 21 '24 02:10 GrinZero