fix(deps): update nextjs monorepo to v15 (major) (#1844)

This commit is contained in:
Meier Lukas
2025-01-04 19:47:23 +01:00
committed by GitHub
parent 92f4f9421e
commit d98552540a
51 changed files with 601 additions and 314 deletions

View File

@@ -1,7 +1,10 @@
"use client";
import { createTRPCClient, createTRPCReact, httpLink } from "@trpc/react-query";
import SuperJSON from "superjson";
import type { AppRouter } from ".";
import { createHeadersCallbackForSource } from "./shared";
export const clientApi = createTRPCReact<AppRouter>();
export const fetchApi = createTRPCClient<AppRouter>({
@@ -26,42 +29,3 @@ function getBaseUrl() {
export function getTrpcUrl() {
return `${getBaseUrl()}/api/trpc`;
}
/**
* Creates a headers callback for a given source
* It will set the x-trpc-source header and cookies if needed
* @param source trpc source request comes from
* @returns headers callback
*/
export function createHeadersCallbackForSource(source: string) {
return async () => {
const headers = new Headers();
headers.set("x-trpc-source", source);
const cookies = await importCookiesAsync();
// We need to set cookie for ssr requests (for example with useSuspenseQuery or middleware)
if (cookies) {
headers.set("cookie", cookies);
}
return headers;
};
}
/**
* This is a workarround as cookies are not passed to the server
* when using useSuspenseQuery or middleware
* @returns cookie string on server or null on client
*/
async function importCookiesAsync() {
if (typeof window === "undefined") {
return await import("next/headers").then(({ cookies }) =>
cookies()
.getAll()
.map(({ name, value }) => `${name}=${value}`)
.join(";"),
);
}
return null;
}

View File

@@ -9,7 +9,7 @@ import { auth } from "@homarr/auth/next";
* handling a tRPC call from a React Server Component.
*/
const createContext = cache(async () => {
const heads = new Headers(headers());
const heads = new Headers(await headers());
heads.set("x-trpc-source", "rsc");
return createTRPCContext({

View File

@@ -0,0 +1,38 @@
/**
* Creates a headers callback for a given source
* It will set the x-trpc-source header and cookies if needed
* @param source trpc source request comes from
* @returns headers callback
*/
export function createHeadersCallbackForSource(source: string) {
return async () => {
const headers = new Headers();
headers.set("x-trpc-source", source);
const cookies = await importCookiesAsync();
// We need to set cookie for ssr requests (for example with useSuspenseQuery or middleware)
if (cookies) {
headers.set("cookie", cookies);
}
return headers;
};
}
/**
* This is a workarround as cookies are not passed to the server
* when using useSuspenseQuery or middleware
* @returns cookie string on server or null on client
*/
async function importCookiesAsync() {
if (typeof window !== "undefined") {
return null;
}
const { cookies } = await import("next/headers");
return (await cookies())
.getAll()
.map(({ name, value }) => `${name}=${value}`)
.join(";");
}