Skip to content

Commit a6e57f4

Browse files
authored
Update cookie dependency to 1.0 (#12172)
1 parent 7fd797a commit a6e57f4

File tree

5 files changed

+43
-25
lines changed

5 files changed

+43
-25
lines changed

.changeset/wet-actors-act.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router": major
3+
---
4+
5+
Update `cookie` dependency to `^1.0.1` - please see the [release notes](https://github.com/jshttp/cookie/releases) for any breaking changes

packages/react-router/lib/server-runtime/cookies.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import type { CookieParseOptions, CookieSerializeOptions } from "cookie";
1+
import type { ParseOptions, SerializeOptions } from "cookie";
22
import { parse, serialize } from "cookie";
33

44
import { sign, unsign } from "./crypto";
55
import { warnOnce } from "./warnings";
66

7-
export type { CookieParseOptions, CookieSerializeOptions };
7+
export type {
8+
ParseOptions as CookieParseOptions,
9+
SerializeOptions as CookieSerializeOptions,
10+
};
811

912
export interface CookieSignatureOptions {
1013
/**
@@ -18,8 +21,8 @@ export interface CookieSignatureOptions {
1821
secrets?: string[];
1922
}
2023

21-
export type CookieOptions = CookieParseOptions &
22-
CookieSerializeOptions &
24+
export type CookieOptions = ParseOptions &
25+
SerializeOptions &
2326
CookieSignatureOptions;
2427

2528
/**
@@ -55,16 +58,13 @@ export interface Cookie {
5558
* Parses a raw `Cookie` header and returns the value of this cookie or
5659
* `null` if it's not present.
5760
*/
58-
parse(
59-
cookieHeader: string | null,
60-
options?: CookieParseOptions
61-
): Promise<any>;
61+
parse(cookieHeader: string | null, options?: ParseOptions): Promise<any>;
6262

6363
/**
6464
* Serializes the given value to a string and returns the `Set-Cookie`
6565
* header.
6666
*/
67-
serialize(value: any, options?: CookieSerializeOptions): Promise<string>;
67+
serialize(value: any, options?: SerializeOptions): Promise<string>;
6868
}
6969

7070
/**
@@ -98,11 +98,17 @@ export const createCookie = (
9898
async parse(cookieHeader, parseOptions) {
9999
if (!cookieHeader) return null;
100100
let cookies = parse(cookieHeader, { ...options, ...parseOptions });
101-
return name in cookies
102-
? cookies[name] === ""
103-
? ""
104-
: await decodeCookieValue(cookies[name], secrets)
105-
: null;
101+
if (name in cookies) {
102+
let value = cookies[name];
103+
if (typeof value === "string" && value !== "") {
104+
let decoded = await decodeCookieValue(value, secrets);
105+
return decoded;
106+
} else {
107+
return "";
108+
}
109+
} else {
110+
return null;
111+
}
106112
},
107113
async serialize(value, serializeOptions) {
108114
return serialize(

packages/react-router/lib/server-runtime/sessions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CookieParseOptions, CookieSerializeOptions } from "cookie";
1+
import type { ParseOptions, SerializeOptions } from "cookie";
22

33
import type { Cookie, CookieOptions } from "./cookies";
44
import { createCookie, isCookie } from "./cookies";
@@ -176,7 +176,7 @@ export interface SessionStorage<Data = SessionData, FlashData = Data> {
176176
*/
177177
getSession: (
178178
cookieHeader?: string | null,
179-
options?: CookieParseOptions
179+
options?: ParseOptions
180180
) => Promise<Session<Data, FlashData>>;
181181

182182
/**
@@ -185,7 +185,7 @@ export interface SessionStorage<Data = SessionData, FlashData = Data> {
185185
*/
186186
commitSession: (
187187
session: Session<Data, FlashData>,
188-
options?: CookieSerializeOptions
188+
options?: SerializeOptions
189189
) => Promise<string>;
190190

191191
/**
@@ -194,7 +194,7 @@ export interface SessionStorage<Data = SessionData, FlashData = Data> {
194194
*/
195195
destroySession: (
196196
session: Session<Data, FlashData>,
197-
options?: CookieSerializeOptions
197+
options?: SerializeOptions
198198
) => Promise<string>;
199199
}
200200

packages/react-router/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"dependencies": {
4242
"@types/cookie": "^0.6.0",
4343
"@web3-storage/multipart-parser": "^1.0.0",
44-
"cookie": "^0.6.0",
44+
"cookie": "^1.0.1",
4545
"react-router": "workspace:*",
4646
"set-cookie-parser": "^2.6.0",
4747
"source-map": "^0.7.3",

pnpm-lock.yaml

Lines changed: 13 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)