Skip to content

Commit a7d4520

Browse files
Deprecate monkey patching examples in JS/UI custom nodes docs (#591)
* Update custom-nodes/js/javascript_hooks.mdx * Update custom-nodes/js/javascript_objects_and_hijacking.mdx * Update custom-nodes/js/javascript_objects_and_hijacking.mdx * Update custom-nodes/js/javascript_examples.mdx * Update custom-nodes/js/javascript_examples.mdx * Update zh-CN/custom-nodes/js/javascript_objects_and_hijacking.mdx * Update zh-CN/custom-nodes/js/javascript_objects_and_hijacking.mdx * Update zh-CN/custom-nodes/js/javascript_examples.mdx * Update zh-CN/custom-nodes/js/javascript_examples.mdx * Update Chinese version --------- Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> Co-authored-by: ComfyUI Wiki <[email protected]>
1 parent afffe90 commit a7d4520

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

custom-nodes/js/javascript_examples.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ import { api } from "../../scripts/api.js";
119119

120120
## Detect an interrupted workflow
121121

122+
<Note>
123+
**Deprecated:** The API hijacking pattern shown below is deprecated and subject to change at any point in the near future. Use the official [extension hooks](/custom-nodes/js/javascript_hooks) and API event listeners where available.
124+
</Note>
125+
122126
A simple example of hijacking the api:
123127

124128
```Javascript
@@ -134,6 +138,10 @@ import { api } from "../../scripts/api.js";
134138

135139
## Catch clicks on your node
136140

141+
<Note>
142+
**Deprecated:** The node method hijacking pattern shown below is deprecated and subject to change at any point in the near future. Use the official [extension hooks](/custom-nodes/js/javascript_hooks) where available.
143+
</Note>
144+
137145
`node` has a mouseDown method you can hijack.
138146
This time we're careful to pass on any return value.
139147

custom-nodes/js/javascript_hooks.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ might modify yours!), in which case care should be taken to ensure interoperabil
5050
And play nicely - isolate your changes wherever possible.</Tip>
5151

5252
A very common idiom in `beforeRegisterNodeDef` is to 'hijack' an existing method:
53+
54+
<Note>
55+
**Deprecated:** The prototype hijacking pattern shown below is deprecated and subject to change at any point in the near future. For context menus, use the official [Context Menu API](/custom-nodes/js/context-menu-migration) instead. For other use cases, prefer using the official [extension hooks](/custom-nodes/js/javascript_hooks) where available.
56+
</Note>
57+
5358
```Javascript
5459
async beforeRegisterNodeDef(nodeType, nodeData, app) {
5560
if (nodeType.comfyClass=="MyNodeClass") {
@@ -70,6 +75,8 @@ or even make calling it conditional.
7075
When hijacking a method in this way, you will want to look at the core comfy code (breakpoints are your friend) to check
7176
and conform with the method signature.
7277
78+
<Warning>This approach is fragile and may break with future ComfyUI updates. Use official APIs whenever possible.</Warning>
79+
7380
#### nodeCreated()
7481
7582
```Javascript

custom-nodes/js/javascript_objects_and_hijacking.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ which can be found at `doc/index.html`.
1414
The `app` object (always accessible by `import { app } from "../../scripts/app.js";`) represents the Comfy application running in the browser,
1515
and contains a number of useful properties and functions, some of which are listed below.
1616

17+
<Note>
18+
**Deprecated:** Hijacking/monkey-patching functions on `app` or prototypes is deprecated and subject to change at any point in the near future. Use the official [extension hooks](/custom-nodes/js/javascript_hooks) and [Context Menu API](/custom-nodes/js/context-menu-migration) instead.
19+
</Note>
20+
1721
<Warning>Hijacking functions on `app` is not recommended, as Comfy is under constant development, and core behavior may change.</Warning>
1822

1923
### Properties
@@ -81,7 +85,11 @@ Group nodes, primitive nodes, notes, and redirect nodes have different propertie
8185

8286
A `ComfyNode` object represents a node in the current workflow. It has a number of important properties
8387
that you may wish to make use of, a very large number of functions that you may wish to use, or hijack to
84-
modify behavior.
88+
modify behavior.
89+
90+
<Note>
91+
**Deprecated:** Hijacking prototype methods on `ComfyNode` or `LGraphNode` is deprecated and subject to change at any point in the near future. Use the official [extension hooks](/custom-nodes/js/javascript_hooks) where available, such as `getNodeMenuItems` for context menus. See the [Context Menu Migration Guide](/custom-nodes/js/context-menu-migration) for examples.
92+
</Note>
8593

8694
To get a more complete sense of the node object, you may find it helpful to insert the following
8795
code into your extension and place a breakpoint on the `console.log` command. When you then create a new node

zh-CN/custom-nodes/js/javascript_examples.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ import { api } from "../../scripts/api.js";
116116

117117
## 检测工作流被中断
118118

119+
<Note>
120+
**已弃用:** 下面展示的 API 劫持模式已被弃用,可能在不久的将来随时更改。请尽可能使用官方的 [扩展钩子](/zh-CN/custom-nodes/js/javascript_hooks) 和 API 事件监听器。
121+
</Note>
122+
119123
这是一个劫持 api 的简单例子:
120124

121125
```Javascript
@@ -131,6 +135,10 @@ import { api } from "../../scripts/api.js";
131135

132136
## 捕获节点点击
133137

138+
<Note>
139+
**已弃用:** 下面展示的节点方法劫持模式已被弃用,可能在不久的将来随时更改。请尽可能使用官方的 [扩展钩子](/zh-CN/custom-nodes/js/javascript_hooks)
140+
</Note>
141+
134142
`node` 有一个 mouseDown 方法可以被劫持。
135143
这次我们注意传递任何返回值。
136144

zh-CN/custom-nodes/js/javascript_hooks.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ async beforeRegisterNodeDef(nodeType, nodeData, app)
3535
<Tip>由于其他扩展也可能会修改节点,建议尽量减少假设,并尽量隔离你的更改,友好共存。</Tip>
3636

3737
`beforeRegisterNodeDef` 中非常常见的做法是"劫持"已有方法:
38+
39+
<Note>
40+
**已弃用:** 下面展示的原型劫持模式已被弃用,可能在不久的将来随时更改。对于右键菜单,请改用官方的 [右键菜单 API](/zh-CN/custom-nodes/js/context-menu-migration)。对于其他用例,请尽可能使用官方的 [扩展钩子](/zh-CN/custom-nodes/js/javascript_hooks)
41+
</Note>
42+
3843
```Javascript
3944
async beforeRegisterNodeDef(nodeType, nodeData, app) {
4045
if (nodeType.comfyClass=="MyNodeClass") {
@@ -51,6 +56,8 @@ async beforeRegisterNodeDef(nodeType, nodeData, app) {
5156
5257
以这种方式劫持方法时,建议查看核心 comfy 代码(断点调试很有用),以确保方法签名一致。
5358
59+
<Warning>这种方法比较脆弱,可能会在未来的 ComfyUI 更新中失效。请尽可能使用官方 API。</Warning>
60+
5461
#### nodeCreated()
5562
5663
```Javascript

zh-CN/custom-nodes/js/javascript_objects_and_hijacking.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Comfy 的许多功能都由 LiteGraph 提供,因此如果你要开发更复杂
1111

1212
`app` 对象(始终可通过 `import { app } from "../../scripts/app.js";` 获取)代表在浏览器中运行的 Comfy 应用,包含许多有用的属性和函数,部分如下所示。
1313

14+
<Note>
15+
**已弃用:** 劫持/猴子补丁 `app` 上的函数或原型方法已被弃用,可能在不久的将来随时更改。请改用官方的 [扩展钩子](/zh-CN/custom-nodes/js/javascript_hooks)[右键菜单 API](/zh-CN/custom-nodes/js/context-menu-migration)
16+
</Note>
17+
1418
<Warning>不建议劫持 `app` 上的函数,因为 Comfy 正在持续开发,核心行为可能会变化。</Warning>
1519

1620
### 属性
@@ -74,6 +78,10 @@ ComfyNode_object_for_my_node.inputs.forEach(input => {
7478

7579
`ComfyNode` 对象代表当前工作流中的一个节点。它有许多重要属性和大量可用或可劫持的函数,用于修改行为。
7680

81+
<Note>
82+
**已弃用:** 劫持 `ComfyNode``LGraphNode` 上的原型方法已被弃用,可能在不久的将来随时更改。请尽可能使用官方的 [扩展钩子](/zh-CN/custom-nodes/js/javascript_hooks),例如使用 `getNodeMenuItems` 处理右键菜单。参见 [右键菜单迁移指南](/zh-CN/custom-nodes/js/context-menu-migration) 获取示例。
83+
</Note>
84+
7785
为了更全面地了解节点对象,你可以在扩展中插入如下代码,并在 `console.log` 处打断点。创建新节点时即可用调试器查看节点。
7886

7987
```Javascript

0 commit comments

Comments
 (0)