Skip to content

Remove postId from Show and Tell revalidation calls - #1455

Merged
MattIPv4 merged 4 commits into
alveusgg:mainfrom
alok0:show-and-tell-revalidate
Sep 16, 2025
Merged

MattIPv4 merged 4 commits into
alveusgg:mainfrom
alok0:show-and-tell-revalidate

Conversation

@alok0

@alok0 alok0 commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

@alok0
alok0 requested a review from a team as a code owner September 15, 2025 19:12
@vercel

vercel Bot commented Sep 15, 2025

Copy link
Copy Markdown

@alok0 is attempting to deploy a commit to the Alveus Team on Vercel.

A member of the Team first needs to authorize it.

@MattIPv4 MattIPv4 changed the title remove postId from show-and-tell/revalidate Remove postId from Show and Tell revalidation calls Sep 15, 2025
@MattIPv4

Copy link
Copy Markdown
Member

@pjeweb do you recall why we make a secondary API call here, rather than calling res.revalidate directly?

@vercel

vercel Bot commented Sep 15, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
alveusgg-website Ready Ready Preview Sep 15, 2025 9:08pm

@pjeweb

pjeweb commented Sep 15, 2025

Copy link
Copy Markdown
Member

@pjeweb do you recall why we make a secondary API call here, rather than calling res.revalidate directly?

premature optimization? honestly not sure. i think it should just work directly

@alok0

alok0 commented Sep 15, 2025

Copy link
Copy Markdown
Contributor Author

Might be because the revalidate call is deep in the database code?

@MattIPv4

MattIPv4 commented Sep 15, 2025 •

Copy link
Copy Markdown
Member

Yeh that's true, though I don't see why the revalidateCache method couldn't call revalidatePath from next/cache twice instead of the fetch it currently calls.

Edit: Actually, does using the methods from next/cache work when this is in the pages router?

@MattIPv4

Copy link
Copy Markdown
Member

Want to try that as part of this to remove another moving piece, or just land this for now given we know its a no-op change?

@alok0

alok0 commented Sep 15, 2025

Copy link
Copy Markdown
Contributor Author

It looks like the only places where it would be called are from trpc.

@MattIPv4

MattIPv4 commented Sep 15, 2025 •

Copy link
Copy Markdown
Member

Sweet. Having looked at this logic more, I'm not really sure this'll change anything as these params were a no-op, but this at least cleans the logic up to make it a bit easier to trace what is happening.

The only potential time saved here is removing:

postIdOrIds.forEach((postId) =>
  url.searchParams.append("postId", postId),
);

I know from experience (nodejs/node#51518 + nodejs/node#51520) that URL.searchParams can be really expensive, though my fix has been in Node.js for a while (I don't think any other runtime has adopted this optimization though).

directly call revalidatePath in server/db/show-and-tell.ts instead of making api call to /revalidate endpoint
@MattIPv4

Copy link
Copy Markdown
Member
Failed to compile.
./src/server/db/show-and-tell.ts
Error:   x You're importing a component that needs "revalidatePath". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
  |
   ,-[/vercel/path0/apps/website/src/server/db/show-and-tell.ts:2:1]
 1 | import { TRPCError } from "@trpc/server";
 2 | import { revalidatePath } from "next/cache";
   :          ^^^^^^^^^^^^^^
 3 | import { z } from "zod";
 4 | 
 5 | import {
   `----
Import trace for requested module:
./src/server/db/show-and-tell.ts
./src/pages/show-and-tell/map.tsx
> Build failed because of webpack errors
 ELIFECYCLE  Command failed with exit code 1.

RIP. I guess if we want to do this, we'll need to either pass through revalidate from res in the tRPC router, or call it directly in the tRPC router mutation definitions?

@MattIPv4

Copy link
Copy Markdown
Member

Very much a nit, but can we always do res: NextApiResponse rather than resp? Where res collides, I think the existing variables can be renamed to smth like data and still hold the same meaning?

@MattIPv4

Copy link
Copy Markdown
Member

Pushed this up to preview. @pjeweb would you mind giving this a test tomorrow?

@pjeweb

pjeweb commented Sep 16, 2025

Copy link
Copy Markdown
Member

Pushed this up to preview. @pjeweb would you mind giving this a test tomorrow?

on it now

@pjeweb pjeweb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works great and code looks clean

@alok0 thank you!

Comment on lines +7 to +9
/**
* @deprecated 2025-09-15
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you file an issue to track removing this? We can pull Vercel logs to check no other traffic is going to this that we've forgotten about.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MattIPv4
MattIPv4 merged commit 2a187a5 into alveusgg:main Sep 16, 2025
7 checks passed

This branch was successfully deployed

2 active (1 outdated) deployments
preview — f768a20b Deployed Sep 15, 2025 by MattIPv4 via Update Chatbot (Preview) #495
Preview — eb453f80 Deployed Sep 15, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants