Use feature flag in Next 16 Cache Component API GET route

Đang mở
#541 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Sôi nổi
Công nghệ
next.js, typescript
Lĩnh vực
api, backend

Hướng nghiên cứu

Start by reproducing the issue in the Next 16 API route GET method with Cache Components enabled, using the feature flag imported from lib/flags. Compare direct flag access with access from a cached data call; done when the route can read the flag without the headers() prerendering error.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

I am trying to use a feature flag in a Next 16 app that has Cache Components enabled. I am trying to access the feature flag in an API routes GET method and receiving the error below. If I move the flag request into a cached data call, then it complains that headers() is accessed.

What is the correct way to handle this?

Error:

Error: During prerendering, `headers()` rejects when the prerender is complete. Typically these errors are handled by React but if you move `headers()` to a different context by using `setTimeout`, `after`, or similar functions you may observe this error and you should handle it in that context. . This occurred at route "/api/route-name"

Example Code:

import { flag } from 'lib/flags';

export async function GET(req: NextRequest): Promise<Response> {
  const flagValue = await flag();
}
Ngôn ngữ chính
TypeScript
Star
629
Fork
93
Merge trung bình
1 ngày 15 phút
Pull request đã merge (30 ngày)
25

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của vercel/flags

Tất cả issue của vercel/flags

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.