Skip to content

Commit 13f650d

Browse files
committed
fix: some component updates skipped because of throttling
1 parent e25468c commit 13f650d

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

packages/app-backend-core/src/index.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,25 @@ async function connect () {
112112

113113
// Components
114114

115-
hook.on(HookEvents.COMPONENT_UPDATED, throttle(async (app, uid, parentUid, component) => {
115+
const sendComponentUpdate = throttle(async (appRecord: AppRecord, id: string) => {
116+
try {
117+
// Update component inspector
118+
if (id && isSubscribed(BridgeSubscriptions.SELECTED_COMPONENT_DATA, sub => sub.payload.instanceId === id)) {
119+
await sendSelectedComponentData(appRecord, id, ctx)
120+
}
121+
122+
// Update tree (tags)
123+
if (isSubscribed(BridgeSubscriptions.COMPONENT_TREE, sub => sub.payload.instanceId === id)) {
124+
await sendComponentTreeData(appRecord, id, appRecord.componentFilter, 0, ctx)
125+
}
126+
} catch (e) {
127+
if (SharedData.debugInfo) {
128+
console.error(e)
129+
}
130+
}
131+
}, 100)
132+
133+
hook.on(HookEvents.COMPONENT_UPDATED, async (app, uid, parentUid, component) => {
116134
try {
117135
if (!app || !uid || !component) return
118136
let id: string
@@ -125,29 +143,21 @@ async function connect () {
125143
appRecord = ctx.currentAppRecord
126144
}
127145

128-
// Update component inspector
129-
if (id && isSubscribed(BridgeSubscriptions.SELECTED_COMPONENT_DATA, sub => sub.payload.instanceId === id)) {
130-
await sendSelectedComponentData(appRecord, id, ctx)
131-
}
132-
133-
// Update tree (tags)
134-
if (isSubscribed(BridgeSubscriptions.COMPONENT_TREE, sub => sub.payload.instanceId === id)) {
135-
await sendComponentTreeData(appRecord, id, appRecord.componentFilter, 0, ctx)
136-
}
137-
138146
if (SharedData.trackUpdates) {
139147
await sendComponentUpdateTracking(id, ctx)
140148
}
141149

142150
if (SharedData.flashUpdates) {
143151
await flashComponent(component, appRecord.backend)
144152
}
153+
154+
await sendComponentUpdate(appRecord, id)
145155
} catch (e) {
146156
if (SharedData.debugInfo) {
147157
console.error(e)
148158
}
149159
}
150-
}, 1000 / 10))
160+
})
151161

152162
hook.on(HookEvents.COMPONENT_ADDED, async (app, uid, parentUid, component) => {
153163
try {

0 commit comments

Comments
 (0)