-
Notifications
You must be signed in to change notification settings - Fork 291
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
Introduce injected session
util in user-code
#214
Changes from 1 commit
537d40e
fca9488
4e55389
2cec0e5
356129d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ import {Layout} from '~/components'; | |
import {getLayoutData, getCountries} from '~/data'; | ||
import {GenericError} from './components/GenericError'; | ||
import {NotFound} from './components/NotFound'; | ||
import {getSession} from './lib/session.server'; | ||
import {Seo, Debugger} from './lib/seo'; | ||
|
||
import styles from './styles/app.css'; | ||
|
@@ -59,9 +58,8 @@ export const meta: MetaFunction = () => ({ | |
viewport: 'width=device-width,initial-scale=1', | ||
}); | ||
|
||
export async function loader({request, context, params}: LoaderArgs) { | ||
const session = await getSession(request, context); | ||
const cartId = await session.get('cartId'); | ||
export async function loader({context, params}: LoaderArgs) { | ||
const cartId = await context.session.get('cartId'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the session property be directly on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO this is unrelated to other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree session is unrelated, but maybe a use-case for an API that is like |
||
|
||
return defer({ | ||
layout: await getLayoutData(context, params), | ||
|
@@ -105,7 +103,7 @@ export function CatchBoundary() { | |
<Links /> | ||
</head> | ||
<body> | ||
<Layout layout={root.data.layout}> | ||
<Layout layout={root.data?.layout}> | ||
{isNotFound ? ( | ||
<NotFound type={caught.data?.pageType} /> | ||
) : ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ import { | |
} from '@remix-run/react'; | ||
import {useIsHydrated} from '~/hooks/useIsHydrated'; | ||
import invariant from 'tiny-invariant'; | ||
import {getSession} from '~/lib/session.server'; | ||
import type {SerializeFrom} from '@remix-run/server-runtime'; | ||
import { | ||
type ActionArgs, | ||
|
@@ -97,12 +96,10 @@ const ACTION_PATH = '/cart/LinesAdd'; | |
* action that handles cart create (with lines) and lines add | ||
*/ | ||
async function action({request, context, params}: ActionArgs) { | ||
const {session, sessionStorage} = context; | ||
const headers = new Headers(); | ||
|
||
const [session, formData] = await Promise.all([ | ||
getSession(request, context), | ||
request.formData(), | ||
]); | ||
const formData = await request.formData(); | ||
|
||
const rawLines = formData.get('lines') | ||
? (JSON.parse(String(formData.get('lines'))) as LinesAddLine[]) | ||
|
@@ -133,7 +130,7 @@ async function action({request, context, params}: ActionArgs) { | |
|
||
// cart created - we only need a Set-Cookie header if we're creating | ||
session.set('cartId', cart.id); | ||
headers.set('Set-Cookie', await session.commit()); | ||
headers.set('Set-Cookie', await sessionStorage.commitSession(session)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find this a bit confusing that we read from Also the commit feels a little verbose. Could we not have a cleaner headers.set('Set-Cookie', await sessionStorage.commit()); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, but it would vary ever so slightly from the official Remix APIs that IMO it would confuse people: https://remix.run/docs/en/v1/api/remix#sessions 👋 @mjackson care to share any context about how this was designed? |
||
|
||
return linesAddResponse({ | ||
prevCart: null, | ||
|
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 kinda funky: Because we define
storefront
etc inHydrogenContext
from the package, and then augmentAppLoadContext
in local types, these two sets need to be merged 🤔 Any better way to do this?