Skip to content

Commit

Permalink
fix: correct passing executionCtx to context.cloudflare.ctx (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Dec 3, 2024
1 parent 8399406 commit a2418e2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions examples/cloudflare-pages/app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ export const loader = (args: LoaderFunctionArgs) => {
const extra = args.context.extra
const cloudflare = args.context.cloudflare
const myVarInVariables = args.context.hono.context.get('MY_VAR_IN_VARIABLES')
return { cloudflare, extra, myVarInVariables }
const isWaitUntilDefined = !!cloudflare.ctx.waitUntil
return { cloudflare, extra, myVarInVariables, isWaitUntilDefined }
}

export default function Index() {
const { cloudflare, extra, myVarInVariables } = useLoaderData<typeof loader>()
const { cloudflare, extra, myVarInVariables, isWaitUntilDefined } = useLoaderData<typeof loader>()
return (
<div>
<h1>Remix and Hono</h1>
Expand All @@ -21,6 +22,7 @@ export default function Index() {
</h3>
<h4>Extra is {extra}</h4>
<h5>Var in Variables is {myVarInVariables}</h5>
<h6>waitUntil is {isWaitUntilDefined ? 'defined' : 'not defined'}</h6>
</div>
)
}
3 changes: 3 additions & 0 deletions examples/cloudflare-pages/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ test('Should return 200 response - /', async ({ page }) => {

const contentH5 = await page.textContent('h5')
expect(contentH5).toBe('Var in Variables is My variable set in c.set')

const contentH6 = await page.textContent('h6')
expect(contentH6).toBe('waitUntil is defined')
})

test('Should return 200 response - /api', async ({ page }) => {
Expand Down
6 changes: 4 additions & 2 deletions examples/cloudflare-workers/app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ export const loader = (args: LoaderFunctionArgs) => {
const extra = args.context.extra
const cloudflare = args.context.cloudflare
const myVarInVariables = args.context.hono.context.get('MY_VAR_IN_VARIABLES')
return { cloudflare, extra, myVarInVariables }
const isWaitUntilDefined = !!cloudflare.ctx.waitUntil
return { cloudflare, extra, myVarInVariables, isWaitUntilDefined }
}

export default function Index() {
const { cloudflare, extra, myVarInVariables } = useLoaderData<typeof loader>()
const { cloudflare, extra, myVarInVariables, isWaitUntilDefined } = useLoaderData<typeof loader>()
return (
<div>
<h1>Remix and Hono</h1>
Expand All @@ -21,6 +22,7 @@ export default function Index() {
</h3>
<h4>Extra is {extra}</h4>
<h5>Var in Variables is {myVarInVariables}</h5>
<h6>waitUntil is {isWaitUntilDefined ? 'defined' : 'not defined'}</h6>
</div>
)
}
3 changes: 3 additions & 0 deletions examples/cloudflare-workers/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ test('Should return 200 response - /', async ({ page }) => {

const contentH5 = await page.textContent('h5')
expect(contentH5).toBe('Var in Variables is My variable set in c.set')

const contentH6 = await page.textContent('h6')
expect(contentH6).toBe('waitUntil is defined')
})

test('Should return 200 response - /api', async ({ page }) => {
Expand Down
4 changes: 1 addition & 3 deletions src/remix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export const createGetLoadContextArgs = (c: Context): GetLoadContextArgs => {
cloudflare: {
env: c.env,
cf: c.req.raw.cf,
ctx: {
...c.executionCtx,
},
ctx: c.executionCtx,
// @ts-expect-error globalThis.caches is not typed
caches: globalThis.caches ? caches : undefined,
},
Expand Down

0 comments on commit a2418e2

Please sign in to comment.