From dfcf151f3be40494b984ec2c57189de10389cb04 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 14 Jun 2026 07:27:26 +0000 Subject: [PATCH] Auto-fix: Resolve Issue #105 --- pr_body.txt | 44 ++++++++++++++++ src/views/ExperimentSummary.vue | 91 ++++----------------------------- 2 files changed, 53 insertions(+), 82 deletions(-) create mode 100644 pr_body.txt diff --git a/pr_body.txt b/pr_body.txt new file mode 100644 index 00000000..173139e1 --- /dev/null +++ b/pr_body.txt @@ -0,0 +1,44 @@ +### AI: Resolves #105 + +This Pull Request was automatically generated by OpenCode to address Issue #105. + +### 📝 AI Modification Summary & Conclusion: +# Conclusion + +## Files Modified + +### 1. `src/views/ExperimentSummary.vue` + +**Changes Made:** + +- **Consolidated initial data fetch**: Replaced the `onMounted` + `watch` dual-trigger pattern with a single `watch` using `{ immediate: true }`. This eliminates the potential double-fetch scenario where `onMounted` fires once and the `watch` could trigger again on the same tick during route settling. Removed the `onMounted` import as it is no longer needed. + +- **Optimized cover change flow to eliminate redundant `/Contents/GetSummary` calls**: The `copySubject` → "Change Cover" handler previously made two separate `/Contents/GetSummary` API calls per cover change operation: + 1. A preliminary call to obtain the current `Image` index before upload + 2. A `setTimeout`-delayed call (800ms) after upload to refresh the cover URL + + Both have been eliminated: + - The `Image` index is now read directly from `data.value.Image` (already populated by the initial `fetchSummary()` call that runs on mount/route change via the `watch({ immediate: true })`) + - After upload succeeds, the cover URL is refreshed locally by incrementing `data.value.Image` and calling `getCoverUrl(data.value)`, avoiding any network request + +- **Replaced stale `summaryRes.Data` references**: All references to the removed preliminary `getData('/Contents/GetSummary', ...)` result (`summaryRes.Data`) in `/Contents/SubmitExperiment` calls were replaced with `data.value`, which holds the canonical summary data already fetched by `fetchSummary()`. + +## Technical Solutions + +1. **Single source of truth for category normalization**: The codebase already uses `getRouteCategory()` (defined in `src/router/category.ts`) as the sole interface for reading route category. All three views (`ExperimentSummary.vue`, `Comments.vue`, `Editor.vue`) obtain their category via this function, which normalizes aliases (e.g., `p`/`project` → `Experiment`, `d`/`c` → `Discussion`, `u` → `User`) into the stable set `Experiment | Discussion | User`. No page directly reads `route.params.category`. + +2. **Watch with `{ immediate: true }`**: This is the idiomatic Vue 3 Composition API pattern for fetching data on component creation AND on subsequent dependency changes, replacing the error-prone `onMounted` + separate `watch` combo that could cause duplicate fetches. + +3. **Local state mutation over API polling**: Instead of making a `/Contents/GetSummary` API call to refresh the cover URL after upload, the component now updates its local `data.value.Image` to the known new index and recomputes `coverUrl` directly via `getCoverUrl()`. This eliminates up to 2 unnecessary API calls (plus their error-retry callbacks) per cover change. + +## Implementation Summary + +The changes reduce the number of `/Contents/GetSummary` network requests triggered by the `ExperimentSummary.vue` page: + +| Scenario | Before | After | +|---|---|---| +| Initial page load | 1 call (onMounted) | 1 call (watch, immediate) | +| Route change (same component) | 1 call (watch) | 1 call (watch) | +| Cover change flow | 2-4 calls (preliminary + setTimeout refresh + retries) | 0 calls (uses local state) | + +The `getRouteCategory` abstraction is properly used across all views, ensuring consistent canonical category values for API calls, comment posting, editor deep links, tags, and logging. No file outside `src/router/category.ts` reads `route.params.category` directly. diff --git a/src/views/ExperimentSummary.vue b/src/views/ExperimentSummary.vue index 689164ca..ff0b5b75 100644 --- a/src/views/ExperimentSummary.vue +++ b/src/views/ExperimentSummary.vue @@ -159,7 +159,7 @@