Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking Change] Remove session.commit everywhere and instead do it in server before returning the new response. #2137

Merged
merged 1 commit into from
Jun 6, 2024

Conversation

michenly
Copy link
Contributor

…o true whenever session is changed. And set to false whenever session is commited. Then in server code, check if session is dirty, if its dirty, set cookie with sessin.commit.

WHY are these changes introduced?

Original idea from @frandiox in #2108 (comment)

WHAT is this pull request doing?

HOW to test your changes?

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

@michenly michenly self-assigned this May 21, 2024
Copy link
Contributor

shopify bot commented May 21, 2024

Oxygen deployed a preview of your dirty-session branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
vite ✅ Successful (Logs) Preview deployment Inspect deployment May 30, 2024 5:27 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment May 30, 2024 5:26 PM
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment June 6, 2024 6:40 PM
optimistic-cart-ui ✅ Successful (Logs) Preview deployment Inspect deployment May 30, 2024 5:26 PM
subscriptions ✅ Successful (Logs) Preview deployment Inspect deployment May 30, 2024 5:27 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment May 30, 2024 5:26 PM

Learn more about Hydrogen's GitHub integration.

@michenly michenly force-pushed the dirty-session branch 4 times, most recently from 0f2adc6 to 8f6a236 Compare May 22, 2024 02:36
Copy link
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I mentioned remix-oxygen in the original idea but that's because I thought we'd need access to customerAccount. Since we just need session.dirty and its implementation lives in userland... what about just adding the following to server.ts?

const response = await handleRequest(request);

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

if (response.status === 404) {
  ...
}

return response;

That way it all lives in userland and we don't do anything special for Oxygen anymore. Those who deploy to Node.js will need to do the same in their entry point, just like when they call storefrontRedirect.

Also, this is something we'll hopefully be able to move to Remix middleware... and it will simplify a lot upgrading to single fetch until then since we don't need to modify responseStub, right?


Aside from that, any better name than session.dirty? Maybe session.isPending? 🤔

@michenly michenly requested review from frandiox and blittle May 22, 2024 16:01
@michenly michenly marked this pull request as ready for review May 22, 2024 17:15
@Shopify Shopify deleted a comment from github-actions bot May 22, 2024
@michenly michenly force-pushed the dirty-session branch 3 times, most recently from ecde315 to 72d3c42 Compare May 22, 2024 17:33
Copy link
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simplification is looking great. One thing to note, though, is that I think this should be considered as a breaking change in Hydrogen because customerAccount is not calling session.commit() anymore in some situations, right? And they must add the commit to their entrypoints manually.

Maybe something to keep for the July release. Or if we want to release it earlier, maybe we should keep the commits in customerAccount for now and extract that in a different PR?

.changeset/nice-deers-return.md Outdated Show resolved Hide resolved
Copy link
Contributor

@blittle blittle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @frandiox that this is a breaking change. Maybe we just wait to merge it?

@michenly
Copy link
Contributor Author

👍 I will update the changlog and wait to merge for July release

@michenly michenly changed the title Remove session.commit everywhere and instead do it in server before returning the new response. [Breaking Change] Remove session.commit everywhere and instead do it in server before returning the new response. May 23, 2024
@michenly michenly force-pushed the dirty-session branch 4 times, most recently from ec4f1ac to 794cb08 Compare May 29, 2024 00:08
@blittle blittle added the 2024.7 label May 29, 2024
@michenly michenly force-pushed the dirty-session branch 4 times, most recently from 5bed521 to 9e7e023 Compare May 30, 2024 17:25
…o true whenever session is changed. And set to false whenever session is commited. Then in server code, check if session is dirty, if its dirty, set cookie with sessin.commit.

move commit logic to template instead

update all the examples

bring back location header

add changeset
@michenly michenly merged commit 4337200 into main Jun 6, 2024
13 checks passed
@michenly michenly deleted the dirty-session branch June 6, 2024 18:45
This was referenced Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants