Skip to content

Commit

Permalink
Merge pull request #226 from aiji42/fix-225
Browse files Browse the repository at this point in the history
Fix 225
  • Loading branch information
aiji42 authored Jun 6, 2022
2 parents 2745521 + 4b627d4 commit 8c17362
Show file tree
Hide file tree
Showing 8 changed files with 1,666 additions and 1,679 deletions.
14 changes: 7 additions & 7 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
},
"dependencies": {
"@geist-ui/react": "^2.2.5",
"next": "12.1.0",
"next-with-split": "^4.3.1-beta.1",
"react": "17.0.2",
"react-dom": "17.0.2"
"next": "12.1.6",
"next-with-split": "4.3.2-beta.2",
"react": "18.1.0",
"react-dom": "18.1.0"
},
"devDependencies": {
"@types/node": "^17.0.21",
"@types/react": "17.0.39",
"typescript": "4.6.2"
"@types/node": "^17.0.40",
"@types/react": "18.0.12",
"typescript": "4.7.3"
}
}
2 changes: 2 additions & 0 deletions example/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Document, {
} from 'next/document'
import { CssBaseline } from '@geist-ui/react'

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
class MyDocument extends Document {
static async getInitialProps(ctx: DocumentContext) {
const initialProps = await Document.getInitialProps(ctx)
Expand Down
252 changes: 121 additions & 131 deletions example/yarn.lock

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,30 @@
"next": ">=12.0.0"
},
"devDependencies": {
"@babel/core": "^7.17.5",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.7",
"@commitlint/cli": "^16.2.1",
"@commitlint/config-conventional": "^16.2.1",
"@babel/core": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@types/app-root-path": "^1.2.4",
"@types/cookie": "^0.4.1",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.21",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
"babel-jest": "^27.5.1",
"eslint": "^8.10.0",
"@types/cookie": "^0.5.1",
"@types/jest": "^28.1.1",
"@types/node": "^17.0.40",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"babel-jest": "^28.1.0",
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.5.0",
"husky": "^7.0.4",
"jest": "^27.5.1",
"lint-staged": "^12.3.4",
"next": "^12.1.0",
"prettier": "^2.5.1",
"husky": "^8.0.1",
"jest": "^28.1.0",
"lint-staged": "^13.0.0",
"next": "^12.1.6",
"prettier": "^2.6.2",
"semantic-release": "^19.0.2",
"semantic-release-cli": "^5.4.4",
"ts-add-module-exports": "^1.0.0",
"ts-node": "^10.6.0",
"typescript": "^4.6.2"
"ts-node": "^10.8.1",
"typescript": "^4.7.3"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
Expand Down
9 changes: 5 additions & 4 deletions src/__tests__/mddleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('middleware', () => {
NextResponse.rewrite = jest.fn().mockReturnValue({
cookie
})
NextResponse.next = jest.fn().mockReturnValue({ cookie })
})
afterAll(() => {
process.env = OLD_ENV
Expand Down Expand Up @@ -120,7 +121,7 @@ describe('middleware', () => {

middleware(makeRequest({}))

expect(NextResponse.rewrite).toBeCalledWith({ pathname: '/foo/bar' })
expect(NextResponse.next).toBeCalled()
expect(cookie).toBeCalledWith(
'x-split-key-test1',
'original',
Expand All @@ -139,7 +140,7 @@ describe('middleware', () => {
})
)

expect(NextResponse.rewrite).toBeCalled()
expect(NextResponse.next).toBeCalled()
expect(NextResponse).not.toBeCalled()
expect(cookie).toBeCalledWith(
'x-split-key-test1',
Expand Down Expand Up @@ -176,7 +177,7 @@ describe('middleware', () => {
})
)

expect(NextResponse.rewrite).toBeCalled()
expect(NextResponse.next).toBeCalled()
expect(NextResponse).not.toBeCalled()
expect(cookie).toBeCalledWith(
'x-split-key-test1',
Expand Down Expand Up @@ -211,7 +212,7 @@ describe('middleware', () => {
})
)

expect(NextResponse.rewrite).toBeCalled()
expect(NextResponse.next).toBeCalled()
expect(NextResponse).not.toBeCalled()
expect(cookie).toBeCalledWith(
'x-split-key-test1',
Expand Down
4 changes: 1 addition & 3 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ const createResponse = (
return new NextResponse(null)
if (isExternal) return NextResponse.rewrite(rewriteTo)

const newUrl = req.nextUrl.clone()
newUrl.pathname = rewriteTo
return NextResponse.rewrite(newUrl)
return NextResponse.next()
}

const getRefererPathname = (req: NextRequest) => {
Expand Down
3 changes: 1 addition & 2 deletions src/with-split.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SplitOptions } from './types'
import { makeRuntimeConfig } from './make-runtime-config'
import { NextConfig } from 'next/dist/server/config'
import { ImageConfig } from 'next/dist/server/image-config'
import { manageMiddleware } from './manage-middleware'

type WithSplitArgs = {
Expand Down Expand Up @@ -82,7 +81,7 @@ export const withSplit =
(!isMain && assetHost
? `https://${assetHost}/_next/image`
: undefined)
} as ImageConfig,
},
env: {
...nextConfig.env,
...(isMain && {
Expand Down
Loading

1 comment on commit 8c17362

@vercel
Copy link

@vercel vercel bot commented on 8c17362 Jun 6, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

next-with-split – ./

next-with-split.vercel.app
next-with-split-git-main-aiji42.vercel.app
next-with-split-aiji42.vercel.app

Please sign in to comment.