Skip to content

Commit

Permalink
Merge branch 'canary' into fix-dynamic-middleware-routing.patch
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzawa committed Dec 20, 2021
2 parents 5fc80cd + e29699b commit ed4b3ea
Show file tree
Hide file tree
Showing 44 changed files with 617 additions and 281 deletions.
190 changes: 99 additions & 91 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -663,16 +663,16 @@ jobs:
- id: get-week
run: echo ::set-output name=WEEK::$(date +%U)

- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v2
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
with:
path: .turbo
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ steps.get-week.outputs.WEEK }}-${{ github.sha }}
restore-keys: |
turbo-${{ github.job }}-${{ github.ref_name }}-${{ steps.get-week.outputs.WEEK }}-
turbo-${{ github.job }}-canary-${{ steps.get-week.outputs.WEEK }}-
# - name: Turbo Cache
# id: turbo-cache
# uses: actions/cache@v2
# if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
# with:
# path: .turbo
# key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ steps.get-week.outputs.WEEK }}-${{ github.sha }}
# restore-keys: |
# turbo-${{ github.job }}-${{ github.ref_name }}-${{ steps.get-week.outputs.WEEK }}-
# turbo-${{ github.job }}-canary-${{ steps.get-week.outputs.WEEK }}-

# We use restore-key to pick latest cache.
# We will not get exact match, but doc says
Expand All @@ -693,7 +693,8 @@ jobs:

- name: Build
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
run: turbo run build-native --cache-dir=".turbo"
working-directory: packages/next-swc
run: yarn build-native
env:
MACOSX_DEPLOYMENT_TARGET: '10.13'
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
Expand Down Expand Up @@ -847,15 +848,15 @@ jobs:
path: ~/.cargo/git
key: stable-${{ matrix.os }}-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}

- name: Turbo cache
id: turbo-cache
uses: actions/cache@v2
with:
path: .turbo
key: turbo-${{ github.job }}-${{ matrix.name }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
restore-keys: |
turbo-${{ github.job }}-${{ matrix.name }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
turbo-${{ github.job }}-${{ matrix.name }}-canary-${{ needs.build.outputs.weekNum }}-
# - name: Turbo cache
# id: turbo-cache
# uses: actions/cache@v2
# with:
# path: .turbo
# key: turbo-${{ github.job }}-${{ matrix.name }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
# restore-keys: |
# turbo-${{ github.job }}-${{ matrix.name }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
# turbo-${{ github.job }}-${{ matrix.name }}-canary-${{ needs.build.outputs.weekNum }}-

- name: Cross build aarch64 setup
if: ${{ matrix.target == 'aarch64-apple-darwin' }}
Expand All @@ -878,7 +879,8 @@ jobs:
next-swc-cargo-cache-${{ matrix.os }}
- name: 'Build'
run: turbo run build-native --cache-dir=".turbo" -- --release --target ${{ matrix.target }}
working-directory: packages/next-swc
run: yarn build-native --release --target ${{ matrix.target }}
env:
MACOSX_DEPLOYMENT_TARGET: '10.13'
TURBO_TOKEN: ${{secrets.TURBO_TOKEN}}
Expand Down Expand Up @@ -934,19 +936,20 @@ jobs:
override: true
target: i686-pc-windows-msvc

- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v2
with:
path: .turbo
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
restore-keys: |
turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-
# - name: Turbo Cache
# id: turbo-cache
# uses: actions/cache@v2
# with:
# path: .turbo
# key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
# restore-keys: |
# turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
# turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-

- name: Build
shell: bash
run: turbo run build-native --cache-dir=".turbo" -- --release --target i686-pc-windows-msvc
working-directory: packages/next-swc
run: yarn build-native --release --target i686-pc-windows-msvc

- name: Upload artifact
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -981,19 +984,20 @@ jobs:
override: true
target: aarch64-pc-windows-msvc

- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v2
with:
path: .turbo
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
restore-keys: |
turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-
# - name: Turbo Cache
# id: turbo-cache
# uses: actions/cache@v2
# with:
# path: .turbo
# key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
# restore-keys: |
# turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
# turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-

- name: Build
shell: bash
run: turbo run build-native --cache-dir=".turbo" -- --release --target aarch64-pc-windows-msvc
working-directory: packages/next-swc
run: yarn build-native --release --target aarch64-pc-windows-msvc

- name: Upload artifact
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -1031,19 +1035,19 @@ jobs:
docker pull ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
docker tag ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine builder
- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v2
with:
path: .turbo
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
restore-keys: |
turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-
# - name: Turbo Cache
# id: turbo-cache
# uses: actions/cache@v2
# with:
# path: .turbo
# key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
# restore-keys: |
# turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
# turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-

- name: 'Build'
run: |
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd)/packages/next-swc:/build -w /build builder sh -c "npm i -g @napi-rs/cli@1.2.1 && npm i -g turbo@1.0.14 && turbo run build-native --cache-dir=".turbo" -- --release --target x86_64-unknown-linux-musl"
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd)/packages/next-swc:/build -w /build builder sh -c "npm i -g @napi-rs/cli@1.2.1 && npm i -g turbo@1.0.14 && yarn build-native --release --target x86_64-unknown-linux-musl"
- name: Upload artifact
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -1093,19 +1097,20 @@ jobs:
sudo apt-get update
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -y
- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v2
with:
path: .turbo
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
restore-keys: |
turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-
# - name: Turbo Cache
# id: turbo-cache
# uses: actions/cache@v2
# with:
# path: .turbo
# key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
# restore-keys: |
# turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
# turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-

- name: Cross build aarch64
working-directory: packages/next-swc
if: ${{ steps.binary-cache.outputs.cache-hit != 'true' }}
run: turbo run build-native --cache-dir=".turbo" -- --release --target aarch64-unknown-linux-gnu
run: yarn build-native --release --target aarch64-unknown-linux-gnu

- name: Upload artifact
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -1152,18 +1157,19 @@ jobs:
sudo apt-get update
sudo apt-get install gcc-aarch64-linux-gnu -y
- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v2
with:
path: .turbo
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
restore-keys: |
turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-
# - name: Turbo Cache
# id: turbo-cache
# uses: actions/cache@v2
# with:
# path: .turbo
# key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
# restore-keys: |
# turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
# turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-

- name: Cross build aarch64
run: turbo run build-native --cache-dir=".turbo" -- --release --target aarch64-unknown-linux-musl
working-directory: packages/next-swc
run: yarn build-native --release --target aarch64-unknown-linux-musl

- name: Upload artifact
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -1213,18 +1219,19 @@ jobs:
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf -y
- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v2
with:
path: .turbo
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
restore-keys: |
turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-
# - name: Turbo Cache
# id: turbo-cache
# uses: actions/cache@v2
# with:
# path: .turbo
# key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
# restore-keys: |
# turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
# turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-

- name: Cross build aarch64
run: turbo run build-native --cache-dir=".turbo" -- --release --target armv7-unknown-linux-gnueabihf
working-directory: packages/next-swc
run: yarn build-native --release --target armv7-unknown-linux-gnueabihf

- name: Upload artifact
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -1260,21 +1267,22 @@ jobs:
override: true
target: aarch64-linux-android

- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v2
with:
path: .turbo
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
restore-keys: |
turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-
# - name: Turbo Cache
# id: turbo-cache
# uses: actions/cache@v2
# with:
# path: .turbo
# key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-${{ github.sha }}
# restore-keys: |
# turbo-${{ github.job }}-${{ github.ref_name }}-${{ needs.build.outputs.weekNum }}-
# turbo-${{ github.job }}-canary-${{ needs.build.outputs.weekNum }}-

- name: Build
shell: bash
working-directory: packages/next-swc
run: |
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android24-clang"
turbo run build-native --cache-dir=".turbo" -- --release --target aarch64-linux-android
yarn build-native --release --target aarch64-linux-android
- name: Upload artifact
uses: actions/upload-artifact@v2
Expand Down
49 changes: 48 additions & 1 deletion docs/api-reference/next/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The following is the definition of the `router` object returned by both [`useRou
- `isReady`: `boolean` - Whether the router fields are updated client-side and ready for use. Should only be used inside of `useEffect` methods and not for conditionally rendering on the server.
- `isPreview`: `boolean` - Whether the application is currently in [preview mode](/docs/advanced-features/preview-mode.md).

Additionally, the following methods are also included inside `router`:
The following methods are included inside `router`:

### router.push

Expand Down Expand Up @@ -414,6 +414,53 @@ export default function MyApp({ Component, pageProps }) {
}
```

## Potential ESLint errors

Certain methods accessible on the `router` object return a Promise. If you have the ESLint rule, [no-floating-promises](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-floating-promises.md) enabled, consider disabling it either globally, or for the affected line.

If your application needs this rule, you should either `void` the promise – or use an `async` function, `await` the Promise, then void the function call. **This is not applicable when the method is called from inside an `onClick` handler**.

The affected methods are:

- `router.push`
- `router.replace`
- `router.prefetch`

### Potential solutions

```jsx
import { useEffect } from 'react'
import { useRouter } from 'next/router'

// Here you would fetch and return the user
const useUser = () => ({ user: null, loading: false })

export default function Page() {
const { user, loading } = useUser()
const router = useRouter()

useEffect(() => {
// disable the linting on the next line - This is the cleanest solution
// eslint-disable-next-line no-floating-promises
router.push('/login')

// void the Promise returned by router.push
if (!(user || loading)) {
void router.push('/login')
}
// or use an async function, await the Promise, then void the function call
async function handleRouteChange() {
if (!(user || loading)) {
await router.push('/login')
}
}
void handleRouteChange()
}, [user, loading])

return <p>Redirecting...</p>
}
```

## withRouter

If [`useRouter`](#useRouter) is not the best fit for you, `withRouter` can also add the same [`router` object](#router-object) to any component.
Expand Down
2 changes: 2 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ const createJestConfig = nextJest({
// Add any custom config to be passed to Jest
const customJestConfig = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
moduleDirectories: ['node_modules', '<rootDir>/'],
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
Expand Down
2 changes: 1 addition & 1 deletion examples/styled-jsx-with-csp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"dependencies": {
"nanoid": "3.1.21",
"next": "10.0.8",
"next": "^12.0.7",
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
Expand Down
13 changes: 2 additions & 11 deletions examples/styled-jsx-with-csp/pages/_document.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import Document, { Html, Head, Main, NextScript } from 'next/document'
import flush from 'styled-jsx/server'

import { nanoid } from 'nanoid'

class CustomDocument extends Document {
static async getInitialProps(ctx) {
const nonce = nanoid()

// https://github.com/vercel/next.js/blob/canary/packages/next/pages/_document.tsx#L89
const { html, head } = await ctx.renderPage()

// Adds `nonce` to style tags on Server Side Rendering
const styles = [...flush({ nonce })]
const docProps = await ctx.defaultGetInitialProps(ctx, { nonce })

let contentSecurityPolicy = ''
if (process.env.NODE_ENV === 'production') {
Expand All @@ -24,8 +16,7 @@ class CustomDocument extends Document {
}

ctx.res.setHeader('Content-Security-Policy', contentSecurityPolicy)

return { styles, html, head, nonce }
return { ...docProps, nonce }
}

render() {
Expand Down

0 comments on commit ed4b3ea

Please sign in to comment.