Skip to content

Commit

Permalink
add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
michenly committed May 22, 2024
1 parent 726d595 commit ecde315
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .changeset/nice-deers-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
'skeleton': patch
'@shopify/hydrogen': patch
'@shopify/cli-hydrogen': patch
---

Remove manual setting of session in headers and recommend setting it in server after response is created.

Step 1: Add `isPending` implementation in session

```diff
// in app/lib/session.ts
export class AppSession implements HydrogenSession {
+ public isPending = false;

get unset() {
+ this.isPending = true;
return this.#session.unset;
}

get set() {
+ this.isPending = true;
return this.#session.set;
}

commit() {
+ this.isPending = false;
return this.#sessionStorage.commitSession(this.#session);
}
}
```

Step 2: update response header if `session.isPending` is true

```diff
// in server.ts
export default {
async fetch(request: Request): Promise<Response> {
try {
const response = await handleRequest(request);

+ if (session.isPending) {
+ response.headers.set('Set-Cookie', await session.commit());
+ }

return response;
} catch (error) {
...
}
},
};
```

Step 3: remove setting cookie with session.commit()

```diff
// in route files
export async function loader({context}: LoaderFunctionArgs) {
return json({},
- {
- headers: {
- 'Set-Cookie': await context.session.commit(),
- },
},
);
}
```

0 comments on commit ecde315

Please sign in to comment.