Repository navigation
refactor: migrate SpectatorListMenu to script setup - #1415
Xinglan233 wants to merge 6 commits into
Conversation
|
Thanks for this — the conversion itself is correct, and the write-up is unusually careful. Everything in it that I spot-checked holds up: Rollbar really is disabled on The migration is clean. One thing to flag, and it is my fault rather than yours. You were right not to claim a type-error reduction. I ran the check you couldn't, with Byte-identical. The error survives the migration: Line 37 is the template, not the script: <v-list-item v-for="spectator in spectatingUsers" :key="spectator">
#1412 told you these six files each had "one type error" that migration would clear. That was wrong — I picked those files by error count and size without checking what caused each error. Of the six, only If you want this PR to close its stated goal, three lines do it: defineProps({
spectatingUsers: {
/** @type {import('vue').PropType<string[]>} */
type: Array,
required: true,
},
});Verified: 420 → 419, this file to 0. Entirely your call. The refactor stands on its own as Unrelated observation while I was in here: |
Thanks for checking! Added the suggested PropType<string[]> annotation. The type check now reports 419 errors instead of 420, with no new diagnostics. All local checks, including the full Cypress suite, pass. |
itsalaidbacklife
left a comment
There was a problem hiding this comment.
Requesting one change, and the direction has shifted since my earlier comment — apologies for moving the target.
What changed: the project is adopting TypeScript for frontend code rather than JSDoc type annotations (#1399). So instead of the /** @type {import('vue').PropType<string[]>} */ form I suggested above, please use lang="ts":
<script setup lang="ts">
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
import BaseMenu from '@/components/BaseMenu.vue';
defineProps<{ spectatingUsers: string[] }>();
const { t } = useI18n();
const spectatingMenu = ref(false);
</script>That is the whole change — everything else in your PR stands as-is.
Verified, so you do not have to take it on faith:
origin/main 420 errors SpectatorListMenu.vue: 1
this PR as it stands 420 errors SpectatorListMenu.vue: 1
with <script setup lang="ts"> 419 errors SpectatorListMenu.vue: 0
vite build exit 0
string[] is the right type: src/stores/game.js:292 and :802 treat the entries as usernames.
No new dependency or build config is needed. Vite already transpiles lang="ts" through esbuild — I built this exact file against the current node_modules and it succeeded. Type checking will come later from vue-tsc in CI (#1400), but nothing about this PR has to wait for that.
Why I am asking rather than just merging: four comparable migrations landed this week (#1416–#1419) and the frontend error count did not move at all — 420 before, 420 after. They were correct refactors, but each left its type error in place, so they now need a second pass (#1428). Catching yours here saves it from the same fate.
Thanks for the careful work on this one — the write-up on the $data / Rollbar interaction was genuinely useful, and the migration itself needed no changes.
Thanks for clarifying the TypeScript direction. I have prepared the exact change you suggested locally. The component builds successfully, but I found an ESLint prerequisite that needs to be addressed before pushing it. I reproduced this independently on both the current PR head and upstream main to check whether it was specific to my local setup.
|
itsalaidbacklife
left a comment
There was a problem hiding this comment.
Withdrawing my change request — please disregard it. This PR is good as it stands.
I asked you to convert to <script setup lang="ts">. That would have broken your build, and I should have checked before asking. npm run lint is a blocking CI job and this repo has no TypeScript-aware ESLint parser, so any TS syntax fails to parse:
SpectatorListMenu.vue
50:38 error Parsing error: Unexpected token ]
It is not specific to the array type — every form fails:
const x: string = 'a'; -> Parsing error: Unexpected token :
defineProps<{ n: number }>(); -> Parsing error: Unexpected token )
export const y: string = 'b'; -> Parsing error: Unexpected token : (plain .ts)
eslint.config.js uses vue-eslint-parser, which delegates <script> to espree unless a TS parser is configured, and @typescript-eslint/parser is not installed. So lang="ts" cannot land anywhere in this repo until that tooling is added — which is now tracked in #1400, including the verified fix ([email protected] + parser wiring, confirmed to parse all four cases above).
Nothing for you to change. Your migration is correct: BaseMenu auto-registers via the <script setup> import, t and spectatingMenu are auto-exposed, the template is untouched, and GameView.vue:15 is the only consumer with no $refs access. The $data / Rollbar note was accurate too.
The one type error in this file (TS2322 on :key="spectator", from the untyped Array prop) stays open and is tracked in #1428 along with eight other already-migrated components in the same position. It needs defineProps<{ spectatingUsers: string[] }>(), which can only be written once #1400 lands.
Sorry for the churn — you got caught between a direction change and a tooling gap, neither of which was yours. Thanks for the patience, and for a genuinely careful PR.
Issue number
Refs #1412
Please check the following
Please describe additional details for testing this change
Converts
SpectatorListMenu.vueto<script setup>, preserving the required Array prop, the translation binding, and the initially closed menu state. The template is unchanged, including its slots, selectors, translations, and responsive spectator count.Validated before and after the migration with Node 22.21.0:
npm run lintnpm run test:unit(3 client and 83 Sails tests)npm run buildTemporary browser checks outside committed source also passed at 1440px and 390px, covering menu toggling and Escape, language switching, and live list updates.
Moving
spectatingMenuto a setup ref changes$datafrom{ spectatingMenu: false/true }to{}. The menu interactions passed the before/after checks above. In the current main branch, both the Rollbar import and plugin registration are commented out; if the plugin is re-enabled, its$datasnapshot will no longer include this field when reporting a component error. The previous component had no explicitname, so no explicit name is lost.Added a
PropType<string[]>JSDoc annotation to the required runtime Array prop for the spectator usernames. An isolated frontend check with TypeScript 5.6.3 and vue-tsc 2.2.10 (allowJsandcheckJsenabled) measures 420 → 419 diagnostics: the TS2322 in SpectatorListMenu.vue is removed, with no new diagnostics. The remaining 419 diagnostics are unchanged; no project typecheck tooling or configuration was added. This addresses one of the six components in #1412.