feat: 为每个控制器缓存任务勾选状态#287
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并给出了一些更高层次的反馈:
- 在
setSelectedController中,const enabledByController = { ...task.enabledByController };会在enabledByController为 undefined 时抛出错误;可以考虑默认使用一个空对象(例如:const enabledByController = { ...(task.enabledByController ?? {}) };)。 - 在
generateConfig和buildTabConfigExportText中类似的...t.enabledByController展开操作,在旧配置中enabledByController不存在时也会报错;在展开前使用空值合并运算符作为回退,以保持兼容性。 - 将
enabledByController与当前 controller 合并(添加[controllerName]: enabled)的逻辑在多个位置重复;提取一个小的辅助函数来完成这个合并,可以减少配置持久化与运行时状态更新之间行为不一致的风险。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `setSelectedController`, `const enabledByController = { ...task.enabledByController };` will throw if `enabledByController` is undefined; consider defaulting to an empty object (e.g. `const enabledByController = { ...(task.enabledByController ?? {}) };`).
- Similar `...t.enabledByController` spreads in `generateConfig` and `buildTabConfigExportText` will fail when `enabledByController` is absent on older configs; use a nullish coalescing fallback before spreading to keep compatibility.
- The logic to merge `enabledByController` with the current controller (adding `[controllerName]: enabled`) is repeated in several places; extracting a small helper for this merge would reduce the chance of diverging behavior between config persistence and runtime state updates.
## Individual Comments
### Comment 1
<location path="src/stores/appStore.ts" line_range="472-481" />
<code_context>
updateInstance: (id, updates) =>
set((state) => ({
instances: state.instances.map((i) => (i.id === id ? { ...i, ...updates } : i)),
+ ...(updates.controllerName !== undefined && {
+ selectedController: {
+ ...state.selectedController,
+ [id]: updates.controllerName,
+ },
+ }),
+ ...(updates.resourceName !== undefined && {
+ selectedResource: {
+ ...state.selectedResource,
</code_context>
<issue_to_address>
**issue (bug_risk):** Updating `selectedController`/`selectedResource` only through `updateInstance` may diverge from `setSelectedController` / `setSelectedResource` behavior.
Currently, `updateInstance` keeps `selectedController`/`selectedResource` in sync only when changes go through it, but `setSelectedController` still updates only `instance.controllerName`. This creates two inconsistent paths for changing controllers while `state.selectedController` is treated as the source of truth (e.g., for `previousControllerName`). Please either route all controller changes through `updateInstance` or update `setSelectedController` to also maintain the `selectedController` map so both representations stay aligned.
</issue_to_address>Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- In
setSelectedController,const enabledByController = { ...task.enabledByController };will throw ifenabledByControlleris undefined; consider defaulting to an empty object (e.g.const enabledByController = { ...(task.enabledByController ?? {}) };). - Similar
...t.enabledByControllerspreads ingenerateConfigandbuildTabConfigExportTextwill fail whenenabledByControlleris absent on older configs; use a nullish coalescing fallback before spreading to keep compatibility. - The logic to merge
enabledByControllerwith the current controller (adding[controllerName]: enabled) is repeated in several places; extracting a small helper for this merge would reduce the chance of diverging behavior between config persistence and runtime state updates.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `setSelectedController`, `const enabledByController = { ...task.enabledByController };` will throw if `enabledByController` is undefined; consider defaulting to an empty object (e.g. `const enabledByController = { ...(task.enabledByController ?? {}) };`).
- Similar `...t.enabledByController` spreads in `generateConfig` and `buildTabConfigExportText` will fail when `enabledByController` is absent on older configs; use a nullish coalescing fallback before spreading to keep compatibility.
- The logic to merge `enabledByController` with the current controller (adding `[controllerName]: enabled`) is repeated in several places; extracting a small helper for this merge would reduce the chance of diverging behavior between config persistence and runtime state updates.
## Individual Comments
### Comment 1
<location path="src/stores/appStore.ts" line_range="472-481" />
<code_context>
updateInstance: (id, updates) =>
set((state) => ({
instances: state.instances.map((i) => (i.id === id ? { ...i, ...updates } : i)),
+ ...(updates.controllerName !== undefined && {
+ selectedController: {
+ ...state.selectedController,
+ [id]: updates.controllerName,
+ },
+ }),
+ ...(updates.resourceName !== undefined && {
+ selectedResource: {
+ ...state.selectedResource,
</code_context>
<issue_to_address>
**issue (bug_risk):** Updating `selectedController`/`selectedResource` only through `updateInstance` may diverge from `setSelectedController` / `setSelectedResource` behavior.
Currently, `updateInstance` keeps `selectedController`/`selectedResource` in sync only when changes go through it, but `setSelectedController` still updates only `instance.controllerName`. This creates two inconsistent paths for changing controllers while `state.selectedController` is treated as the source of truth (e.g., for `previousControllerName`). Please either route all controller changes through `updateInstance` or update `setSelectedController` to also maintain the `selectedController` map so both representations stay aligned.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
1204244136
force-pushed
the
feat/per-controller-task-cache
branch
from
July 16, 2026 11:17
1b74416 to
69d1934
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
已实现:
Summary by Sourcery
为每个控制器添加任务启用状态的缓存,并在标签页和配置的导出/导入之间持久化该状态。
新功能:
增强:
Original summary in English
Summary by Sourcery
Add per-controller caching of task enabled state and persist it across tabs and config export/import.
New Features:
Enhancements: