Skip to content

fix(spx-gui): fix stage defaulting to widget tab when switching to stage#2961

Merged
nighca merged 1 commit intodevfrom
xgopilot/issue-2960-1773738065
Mar 17, 2026
Merged

fix(spx-gui): fix stage defaulting to widget tab when switching to stage#2961
nighca merged 1 commit intodevfrom
xgopilot/issue-2960-1773738065

Conversation

@xgopilot
Copy link
Copy Markdown
Contributor

@xgopilot xgopilot Bot commented Mar 17, 2026

Requested by @nighca

Fixes #2960

Summary

  • Removed the watcher in StageEditorState that automatically switched to the widgets tab whenever a widget was selected
  • WidgetsEditorState initializes with the first widget pre-selected, which caused the watcher to trigger and switch to the widgets tab as soon as the stage was activated
  • Now the stage correctly defaults to the code tab when first activated, matching expected behavior

Root Cause

In StageEditor.vue, StageEditorState had a watcher on widgetsState.selected:

watch(
  () => this.widgetsState.selected,
  (selectedWidget) => {
    if (selectedWidget != null) {
      this.select('widgets')  // This was the culprit
    }
  }
)

WidgetsEditorState initializes selectedIdRef with the first widget's ID from getStage().widgets[0]?.id. When the project loads and widgets become available, this triggers the watcher chain:

  1. WidgetsEditorState auto-selects the first widget
  2. The watcher in StageEditorState sees a non-null widget and switches to 'widgets' tab
  3. Result: switching to stage always shows the widget tab instead of code tab

Fix

Removed the problematic watcher. The widgets tab is now only shown when:

  • The user explicitly clicks the "Widgets" quick button (calls select('widgets'))
  • The user explicitly selects a widget (calls selectWidget())
  • State is restored from the URL route via selectByRoute()

This preserves the "restore prior selection" behavior described in the issue while fixing the incorrect default.

Remove the watcher in StageEditorState that automatically switched to
the widgets tab when a widget was selected. This watcher caused the stage
to always display the widget tab when switching to the stage, because
WidgetsEditorState initializes with the first widget pre-selected.

Now the stage correctly defaults to the code tab when first activated.
The widgets tab is only shown when the user explicitly navigates to it
or when state is restored from the route.

Fixes #2960

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: nighca <1492263+nighca@users.noreply.github.com>
@xgopilot
Copy link
Copy Markdown
Contributor Author

xgopilot Bot commented Mar 17, 2026

Clean, well-scoped fix. The removed watcher was the sole cause of the bug — all intentional widget-selection paths (selectWidget, selectByRoute, and click handlers) already call this.select('widgets') explicitly, so the watcher was both redundant and harmful for the initialization case. Unused watch import correctly cleaned up too. No issues found.

@nighca nighca merged commit e9fb8a3 into dev Mar 17, 2026
8 checks passed
@xgopilot xgopilot Bot deleted the xgopilot/issue-2960-1773738065 branch March 17, 2026 09:14
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.

Switching to stage can incorrectly default to the widget tab

3 participants