StoicBuilder
Later missionMission 9: What Place order actually sendsYou can practise it now. It counts once you reach mission 9, after “Refresh signs everyone out”.Back to HQ

DrillsThe feed asks for itself until it gets a 429

The feed asks for itself until it gets a 429

II the ForumChirp, built with BoltSteadyAbout 6 minPro

What happened

You asked Bolt to make Chirp's home feed “update when new posts come in”. Now the feed loads, and a few seconds later it's replaced by an error. The Network tab shows /api/feed requested again and again, many times a second, until the server starts answering 429.

A teammateOur Upstash usage alert went off. /api/feed got 41,000 calls in the last hour, and it's only the two of us testing.
What you seeOn screen
Couldn't load your feed. Feed failed: 429

The MagisterYou don't have to fix the code yourself. Read it until you can say, in plain words, why it breaks.

"use client";
import { useEffect, useState } from "react";
import { PostCard } from "./PostCard";

// The home feed. Updates when new posts come in.
export function Feed() {
  const [posts, setPosts] = useState([]);
  const [error, setError] = useState(null);

  useEffect(() => {
    fetch("/api/feed")
      .then((res) => {
        if (!res.ok) throw new Error(`Feed failed: ${res.status}`);
        return res.json();
      })
      .then((data) => setPosts(data.posts))
      .catch((err) => setError(err.message));
  }, [posts]);

  if (error) return <p className="feed-error">Couldn't load your feed. {error}</p>;

  return (
    <ul className="feed">
      {posts.map((post) => (
        <PostCard key={post.id} post={post} />
      ))}
    </ul>
  );
}

This one is for reading: the code needs a real database or server to run.

Your answer

Reviewed by AI against what a good fix needs. About 10 seconds.

Sign in to get your answer reviewed

It's free. Anything you've typed here stays in this browser and is waiting when you come back.

Sign in with email