Next.js Discord

Discord Forum

Data fetching after a post

Unanswered
British Shorthair posted this in #help-forum
Open in Discord
British ShorthairOP
Hi everyone,

I'm working on a Next.js project with a unique flow and facing a data fetching issue. Here's the overview:

Client-Side Form Component: I have a client-side React form component that sends data to a Next.js API route.

API Route Processing: The API route processes the form data and adds a new row in a Supabase table (search_results). It then asynchronously invokes an AWS Lambda function. The API route does not wait for the Lambda response and immediately returns a success response.

Client-Side Redirect: Once the API response is received, the client-side component redirects the user to the /results page.

Server Component on /results Page: This page has a server component that fetches all records from the search_results table in Supabase.

Issue: Sometimes the record that was just added by the API route does not appear when the /results page loads. This leads me to suspect some form of caching might be at play. The newly added record is not consistently fetched by the server component.

Question: Has anyone experienced similar issues with Next.js and Supabase? How can I ensure that the most recent data, including the newly added record, is fetched every time when the /results page loads?

0 Replies