Skip to content

Commit

Permalink
fix: small improvements/fixes to cookie chunker in ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
hf committed Apr 5, 2024
1 parent 720c351 commit 811283f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
21 changes: 9 additions & 12 deletions packages/ssr/src/createServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,14 @@ export function createServerClient<
},
setItem: async (key: string, value: string) => {
const chunks = createChunks(key, value);
await Promise.all(
chunks.map(async (chunk) => {
if (typeof cookies.set === 'function') {
await cookies.set(chunk.name, chunk.value, {
...DEFAULT_COOKIE_OPTIONS,
...cookieOptions,
maxAge: DEFAULT_COOKIE_OPTIONS.maxAge
});
}
})
);

for (let i = 0; i < chunks.length; i += 1) {
await cookies.set(chunk.name, chunk.value, {
...DEFAULT_COOKIE_OPTIONS,
...cookieOptions,
maxAge: DEFAULT_COOKIE_OPTIONS.maxAge
});
}
},
removeItem: async (key: string) => {
if (typeof cookies.remove === 'function' && typeof cookies.get !== 'function') {
Expand All @@ -90,7 +87,7 @@ export function createServerClient<
return;
}

deleteChunks(
await deleteChunks(
key,
async (chunkName) => {
if (typeof cookies.get === 'function') {
Expand Down
1 change: 0 additions & 1 deletion packages/ssr/src/utils/chunker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export async function deleteChunks(

if (value) {
await removeChunk(key);
return;
}

for (let i = 0; ; i++) {
Expand Down

0 comments on commit 811283f

Please sign in to comment.