AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

[Bug] CodeDialog.vue crashes with TypeError when switching to interactions protocol after previously selecting an openai-* language

Open photobrand opened this issue 1 week ago • 1 comments

发生了什么 / What happened

Summary

In web/src/playground/CodeDialog.vue:18-24:

const language = ref<string>(props.options[0]!.value)
const option = computed(() => props.options.find((item) => item.value === language.value)!)
const text = computed(() => props.code(option.value.value))
// ...
watch(
  () => (open.value ? ([text.value, option.value.highlight] as const) : undefined),

Trigger & Consequence

In web/src/playground/GetCodeDialog.vue:77-81, options filters out openai-* entries when session.settings.protocol === 'interactions'.

  1. Open GetCodeDialog under gemini or openai protocol and select an openai-* language (language.value becomes e.g. 'openai-python').
  2. Close the dialog (keeping CodeDialog mounted), switch protocol to interactions, and reopen the dialog.
  3. props.options.find(...) returns undefined, so option.value.value (line 20) and option.value.highlight (line 24) throw an uncaught TypeError: Cannot read properties of undefined, breaking the dialog.

Suggested Fix

Fallback to the first available option when language.value is no longer present in props.options:

const option = computed(
  () => props.options.find((item) => item.value === language.value) ?? props.options[0]!,
)

版本 / Version

v0.3.14

photobrand avatar Nov 22 '26 16:11 photobrand

每人最多同时打开 3 个 Issue,这个 Issue 已自动关闭。请等已有的 Issue 处理完再提,或把内容补充到已有的 Issue 里。

Each user can have at most 3 open issues at a time, so this one was closed automatically. Please wait until your existing issues are resolved, or add this to one of them.

github-actions[bot] avatar Nov 22 '26 16:11 github-actions[bot]