ITADN

Incorrect channel selection restoration on OutputChannel.show()

#17549Opencolin-grant-work 创建于 2026-05-25
### Bug Description: When `OutputChannel.show()` is called while the `OutputWidget` does not exist (e.g., the user previously closed the Output panel tab), the channel selection dropdown in the toolbar does not reflect the channel that was just shown. The editor content may display the correct channel, but the dropdown selector shows the previously selected channel. The root cause is a race condition between `channel.show()` and widget creation/state restoration: 1. `OutputChannel.show()` synchronously sets `OutputChannelManager.selectedChannel` to the target channel and fires `channelWasShownEmitter`. 2. `OutputContribution.init()` handles `onChannelWasShown` by calling `open()`, which triggers `WidgetManager.getOrCreateWidget()` to create a new `OutputWidget`. 3. The new widget's `@postConstruct init()` registers listeners for `onSelectedChannelChanged` and `onChannelWasShown`, but **both events already fired before the widget existed**, so the widget never processes them. 4. `init()` calls `restoreSelectedChannelFromStorage()` (async), which reads the previously stored channel name and overrides `OutputChannelManager.selectedChannel` back to the old value — undoing the selection made in step 1. 5. The toolbar's `OutputToolbarContribution` re-renders with the restored (stale) channel name. The `onChannelWasShown` handler in `OutputWidget.init()` (lines 78–83) is specifically designed to clear pending restoration when a channel is explicitly shown, but it never fires because the event occurred before the widget was created. ### Steps to Reproduce: 1. Register two output channels (e.g., "Channel A" and "Channel B"). 2. Programmatically show Channel A (e.g., via `OutputCommands.SHOW`). The Output panel opens with Channel A selected in the dropdown. ✓ 3. Close the Output panel by clicking the tab's close button (this disposes the widget and saves "Channel A" to storage). 4. Programmatically show Channel B (e.g., via `OutputCommands.SHOW` or `channel.show()`). 5. **Expected:** Output panel opens with Channel B selected in the dropdown. 6. **Actual:** Output panel opens, but the dropdown shows "Channel A" (the previously stored channel). The editor content may briefly show Channel B before being overridden, or may show Channel A. ### Additional Information - Operating System: MacOS - Theia Version: 128342e9ba53c273de5ef8a5bc9b93dbc0b931d4
0 条评论