Skip to content

Potential issue in ErfassungStimmzettelView #2077

@vjohnslhm

Description

@vjohnslhm

⚠️ Potential issue | 🔴 Critical

Fix potential false 404: wait until wahlen are loaded before redirecting.

The watcher triggers on wahlID; if wahlen aren’t initialized yet, wahl is undefined and you redirect erroneously.

Apply:

-import { storeToRefs } from "pinia";
-import { computed, watch } from "vue";
+import { storeToRefs } from "pinia";
+import { computed, watchEffect } from "vue";
 ...
-const { wahlenActions } = useWahlenStore();
+const wahlenStore = useWahlenStore();
+const { wahlenActions } = wahlenStore;
+const { wahlenState } = storeToRefs(wahlenStore);
 ...
-watch(
-  () => wahlID.value,
-  () => {
-    if (!wahl.value) {
-      router.push({ name: EXAMPLE_ROUTES_NOTFOUND });
-    }
-  }
-);
+watchEffect(() => {
+  // redirect only after wahlen finished loading (null -> loaded array)
+  if (wahlenState.value.wahlen !== null && !wahl.value) {
+    router.push({ name: EXAMPLE_ROUTES_NOTFOUND });
+  }
+});

Also applies to: 15-15, 24-25, 27-33, 37-44

🤖 Prompt for AI Agents
In wls-gui-wahllokalsystem/src/views/auszaehlung/ErfassungStimmzettelView.vue
around lines 3, 15, 24-25, 27-33 and 37-44, the watcher and redirects run as
soon as wahlID changes even if the wahlen list hasn't finished loading, causing
false 404 redirects when wahl is undefined; update each watcher and any redirect
logic to first wait for wahlen to be initialized (e.g., check a loaded flag or
that wahlen.length > 0) before attempting to look up the wahl by ID and
redirect, and guard all uses of getStimmzettelTermForWahl(wahl) and similar
calls with a null/undefined check so you only compute the title or redirect when
the matching wahl is present.

Originally posted by @coderabbitai[bot] in #2047 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions