-
Notifications
You must be signed in to change notification settings - Fork 288
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
👩💻 improved HydrogenSession typing. #1590
Conversation
4d4353d
to
844874f
Compare
Does anyone know if there are other documentation I need to update with this change? |
844874f
to
6297eb4
Compare
6297eb4
to
a88ac93
Compare
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.
I'd suggest renaming the project session to CookieSession
and keep HydrogenSession
type as is:
import {
// ...
type HydrogenSession,
} from '@shopify/hydrogen';
// ...
CookieSession.init(request, [env.SESSION_SECRET]),
// ...
export class CookieSession implements HydrogenSession {
// ...
It might require more changes but it feels like a better update 🤔
… and use it in all the example projects.
Co-authored-by: Fran Dios <frankdiox@gmail.com>
047a5c8
to
d235766
Compare
examples/customer-api/server.ts
Outdated
@@ -102,7 +103,7 @@ export default { | |||
* Feel free to customize it to your needs, add helper methods, or | |||
* swap out the cookie-based implementation with something else! | |||
*/ | |||
export class HydrogenSession { | |||
export class HydrogenSession implements DefaultHydrogenSession { |
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.
Somewhat nit-picky, but I think that DefaultHydrogenSession
doesn't really make sense as an identifier name. It is the interface that the developer must conform to. So it isn't really a "default". It is what they need to implement to ensure compatibility. IMO export class Session implements HydrogenSession
makes more sense. But that means a bit more to modify.
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.
Ahh, I see Fran above had a similar comment. Whether it is Session
or CookieSession
, I just don't like calling the type DefaultHydrogenSession
in our examples.
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.
OK I will update the name of the Session in our template. Was avoiding making a bigger change but if everyone are on board I will make it happen :)
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.
This is a great change, thank you for pushing it!
d0aed02
to
d114ea0
Compare
…ession to be session typing coming from Hydrogen package
d114ea0
to
d5c4a0b
Compare
WHY are these changes introduced?
The current typing for
HydrogenSession
is de-coupled from the implementation ofHydrogenSession
in project. This means the shape of the class could be very different from what @shopify/hydrogen expect session to look like.WHAT is this pull request doing?
Export the typing for
HydrogenSession
from @shopify/hydrogen and use it to implementHydrogenSession
in all the example projects.The type is implemented using base session type from
@remix-run/server-runtime
which should ensure all session type from remix are supported. (Addressing concern from #1430 (comment))Having
HydrogenSession
implemented from a base type will ensure the interface of this class is what we expect it to be when we use property from this class in hydrogen utility.HOW to test your changes?
Any
CookieSession
class that implementsHydrogenSession
type, changed the interface so it no longer conform to the interface and see type error in editor.example 1: changed return type of
commit
methodexample 2: remove
get
methodPost-merge steps
Checklist