Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add after request context method #677

Merged
merged 1 commit into from
Dec 11, 2024
Merged

Conversation

aralroca
Copy link
Collaborator

Fixes #676

after

after(cb: () => void): void

The after method allows you to schedule work to be executed after a response (or prerender) is finished. This is useful for tasks and other side effects that should not block the response, such as logging and analytics.

It can be used everywhere when you have access to the RequestContext (Middleware, API routes, Server components, etc).

Example:

import { type RequestContext } from "brisa";

export default function SomeComponent({}, { after }: RequestContext) {
  after(() => {
    console.log("The response is sent");
  });

  return <div>Some content</div>;
}

Note

Good to know: after is not a Dynamic API and calling it does not cause a route to become dynamic. If it's used within a static page, the callback will execute at build time.

@aralroca aralroca self-assigned this Dec 11, 2024
@aralroca aralroca changed the title feat: add 'after' request context method feat: add after request context method Dec 11, 2024
Copy link

pkg-pr-new bot commented Dec 11, 2024

Open in Stackblitz

brisa-adapter-vercel

npm i https://pkg.pr.new/brisa-build/brisa/brisa-adapter-vercel@677

brisa-pandacss

npm i https://pkg.pr.new/brisa-build/brisa/brisa-pandacss@677

brisa

npm i https://pkg.pr.new/brisa-build/brisa@677

brisa-tailwindcss

npm i https://pkg.pr.new/brisa-build/brisa/brisa-tailwindcss@677

create-brisa

npm i https://pkg.pr.new/brisa-build/brisa/create-brisa@677

www

npm i https://pkg.pr.new/brisa-build/brisa/www@677

commit: a75a3bc

@aralroca aralroca merged commit 2b6554c into canary Dec 11, 2024
6 of 11 checks passed
@aralroca aralroca deleted the aralroca/after-api branch December 11, 2024 23:47
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.

create after method to request context to run tasks after the response
1 participant