Settings menu #47

Closed
opened 2026-10-15 10:21:51 +00:00 by Syndria98 · 7 comments
Owner

When entering the settings from the main menu it shows a "Syntax Error" and the settings menu does not display and when closing it also does not display again the main menu. Can you fix that?

When entering the settings from the main menu it shows a "Syntax Error" and the settings menu does not display and when closing it also does not display again the main menu. Can you fix that?
Syndria98 added the ai-ready label 2026-10-15 10:21:51 +00:00
Agent added the working label 2026-10-15 10:21:52 +00:00
Collaborator

I'll investigate the settings window and the main menu flow.

I'll investigate the settings window and the main menu flow.
Collaborator

Let me test a hypothesis about useI18n + GetUserSetting behavior directly in Node.

Let me test a hypothesis about `useI18n` + `GetUserSetting` behavior directly in Node.
Collaborator

Now I have the diagnosis. Let me verify it precisely before fixing:

Now I have the diagnosis. Let me verify it precisely before fixing:
Collaborator

Confirmed the root cause. Now the fix:

Confirmed the root cause. Now the fix:
Collaborator

Now the test, following the repo's existing vm/source-reading style:

Now the test, following the repo's existing vm/source-reading style:
Collaborator

Fixed, diagnosed, and covered by tests.

Root cause

SettingsWindow.vue wrote the value it read from the server straight into vue‑i18n's global locale:

GetUserSetting('lang').then(value => { locale.value = value; … });

For every account that never picked a language there is nothing stored: GET /user/get-settings answers res.json({status:'ok', settings: data.settings}) → settings: undefined, so GetUserSetting('lang') returns undefined. vue‑i18n rejects a locale of that type on the next translation — I reproduced it against the version the lockfile pins (vue‑i18n 11.4.14):

ON RENDER $t(): SyntaxError: cannot support locale type

That is the "Syntax Error" in the issue. Because the locale is global and reactive, every translation in every window throws from then on: the settings window never renders, and the main menu behind it goes down with it (the error page replaces the app), which is why closing settings did not bring the main menu back either.

Changes

frontend/app/components/windows/SettingsWindow.vue

  • applyLanguage(code) puts a language into vue‑i18n only when it is one of the codes in i18n/locales.ts; no stored language (or one no longer offered) leaves the language on screen alone, and a failed settings request is caught instead of poisoning the locale.
  • localeToShow(code) seeds the dropdown with the language actually being shown instead of an empty row, and getLocaleName no longer dereferences a locale that is not there.
  • changeLocale only saves a language it managed to apply (and no longer logs the option object).
  • GetUser()?.admin — an expired token made the same onBeforeMount hook throw while opening the settings.

frontend/app/services/WindowDefinitions.js

  • Closing the settings window goes back to the main menu (CreateWindow leaves the already‑open main menu alone, so it never doubles).

tests/settings-window.test.js (new, 10 tests) — the window script is lifted out of its <script setup> into a node:vm context with locale/selectedLocale as plain refs, the way tests/sidebar-section-pane.test.js does it: nothing but a looked‑up locale reaches vue‑i18n, an unknown/missing stored language leaves it untouched, a known one is applied and shown, the dropdown always has a row, and closing the window restores the main menu.

Verification

  • node --test tests/ → 131 tests, 131 pass, 0 fail (121 pre‑existing + 10 new).
  • Sanity check that the new tests catch the regression: with the two files reverted to the reported code, 8 of the 10 fail; restored, all pass.
  • pnpm --filter ./frontend run build → build complete; both changed modules also transform cleanly through nuxt dev.

Nothing committed or pushed.

One pre-existing gap I did not touch (separate, unimplemented feature): the admin‑only "Manage accounts" button in the same window calls CreateWindow('account_management', …), but account_management is not registered in WindowDefinitions.js, so clicking it crashes the window app the same way — and the ClearWindow('settings') calls in that handler pass a string where a {type}/{id} selector is expected. Worth its own issue.

Fixed, diagnosed, and covered by tests. ## Root cause `SettingsWindow.vue` wrote the value it read from the server straight into vue‑i18n's **global** locale: ```js GetUserSetting('lang').then(value => { locale.value = value; … }); ``` For every account that never picked a language there is nothing stored: `GET /user/get-settings` answers `res.json({status:'ok', settings: data.settings})` → `settings: undefined`, so `GetUserSetting('lang')` returns `undefined`. vue‑i18n rejects a locale of that type on the next translation — I reproduced it against the version the lockfile pins (vue‑i18n 11.4.14): ``` ON RENDER $t(): SyntaxError: cannot support locale type ``` That is the "Syntax Error" in the issue. Because the locale is global and reactive, every translation in every window throws from then on: the settings window never renders, and the main menu behind it goes down with it (the error page replaces the app), which is why closing settings did not bring the main menu back either. ## Changes `frontend/app/components/windows/SettingsWindow.vue` - `applyLanguage(code)` puts a language into vue‑i18n **only when it is one of the codes in `i18n/locales.ts`**; no stored language (or one no longer offered) leaves the language on screen alone, and a failed settings request is caught instead of poisoning the locale. - `localeToShow(code)` seeds the dropdown with the language actually being shown instead of an empty row, and `getLocaleName` no longer dereferences a locale that is not there. - `changeLocale` only saves a language it managed to apply (and no longer logs the option object). - `GetUser()?.admin` — an expired token made the same `onBeforeMount` hook throw while opening the settings. `frontend/app/services/WindowDefinitions.js` - Closing the settings window goes back to the main menu (`CreateWindow` leaves the already‑open main menu alone, so it never doubles). `tests/settings-window.test.js` (new, 10 tests) — the window script is lifted out of its `<script setup>` into a `node:vm` context with `locale`/`selectedLocale` as plain refs, the way `tests/sidebar-section-pane.test.js` does it: nothing but a looked‑up locale reaches vue‑i18n, an unknown/missing stored language leaves it untouched, a known one is applied and shown, the dropdown always has a row, and closing the window restores the main menu. ## Verification - `node --test tests/` → **131 tests, 131 pass, 0 fail** (121 pre‑existing + 10 new). - Sanity check that the new tests catch the regression: with the two files reverted to the reported code, 8 of the 10 fail; restored, all pass. - `pnpm --filter ./frontend run build` → build complete; both changed modules also transform cleanly through `nuxt dev`. Nothing committed or pushed. One pre-existing gap I did **not** touch (separate, unimplemented feature): the admin‑only "Manage accounts" button in the same window calls `CreateWindow('account_management', …)`, but `account_management` is not registered in `WindowDefinitions.js`, so clicking it crashes the window app the same way — and the `ClearWindow('settings')` calls in that handler pass a string where a `{type}`/`{id}` selector is expected. Worth its own issue.
Collaborator

Implementation is ready for review: #50

Implementation is ready for review: https://git.aranroig.com/Syndria98/dragonroll/pulls/50
Agent added help wanted and removed working labels 2026-10-15 11:03:09 +00:00
Agent referenced this issue from a commit 2026-10-15 11:03:11 +00:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Syndria98/dragonroll#47