-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
fix: clone session data on .set() #12883
Conversation
🦋 Changeset detectedLatest commit: 7de535b The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
CodSpeed Performance ReportMerging #12883 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
Thanks for this. The issue with the missing |
Ah, my mistake. We can't use fs there. I think it's ok to revert to your previous version. |
reverted. I added a different "ensure the directory exists" check that is only a little bit of a hack. also added "/.astro" to .gitignore as both manually and turbo running the tests creates that directory in various places, and I didn't see anywhere else (e.g. being used as part of a test fixture) so that should be safe. |
.changeset/tough-cars-yawn.md
Outdated
'astro': patch | ||
--- | ||
|
||
Fixes a bug where session data could be corrupted if it is changed after calling .set(); also fixes a bug where responses can be returned before session data is saved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you split this into two chanegsets. You can run pnpm changeset
again to add another one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work. Thanks for tracking down all the issues. Just a single request with the changeset and we can merge this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks a lot for fixing these two.
Changes
I chose to use
parse(stringify(value))
instead of anything likestructuredClone
or trying to get fancy with the store to ensure correctness, the extra parse should not be a significant performance issue unless people start storing pathologically large session data.Testing
Added a new test in
sessions.test.js
that fails on main and succeeds on this branch.That test could probably use a helper function to maintain a "cookie jar" for session, but I don't quite know the cleanest way to do that.
Docs
No update necessary, just a bugfix. However if the powers that be decide #12881 is
wontfix
, the docs definitely need to be updated to remind users to clone their objects before calling set, or be careful with updating them after doing so.