fix: Always fetch full story and update existing in feed

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2025-11-20 22:58:44 +00:00
parent 5a7f55184d
commit f08202d592

View File

@@ -21,13 +21,8 @@ function Feed({ updateCache }) {
if (!updated) return;
let currentStories = Array.isArray(stories) ? [...stories] : [];
const existingStoryIds = new Set(currentStories.map(s => s.id));
for (const newStory of [...newApiStories].reverse()) {
if (existingStoryIds.has(newStory.id)) {
continue;
}
try {
const storyRes = await fetch('/api/' + newStory.id);
if (!storyRes.ok) throw new Error('Story fetch failed');
@@ -38,6 +33,10 @@ function Feed({ updateCache }) {
console.log('Preloaded story:', fullStory.id, fullStory.title);
updateCache(fullStory.id, fullStory);
const existingStoryIndex = currentStories.findIndex(s => s.id === newStory.id);
if (existingStoryIndex > -1) {
currentStories.splice(existingStoryIndex, 1);
}
currentStories.unshift(newStory);
} catch (error) {
console.log('Skipping story due to fetch error', newStory.id, error);