Skip to content

Commit

Permalink
Merge branch 'canary' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Oct 13, 2020
2 parents 2ff9a6b + f1b3818 commit 5b6cb6e
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 27 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build_test_deploy.yml
Expand Up @@ -107,12 +107,13 @@ jobs:
steps:
- uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- run: cat package.json | jq '.resolutions.webpack = "^5.0.0-beta.30"' > package.json.tmp && mv package.json.tmp package.json
- run: cat package.json | jq '.resolutions.react = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp package.json
- run: cat package.json | jq '.resolutions."react-dom" = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp package.json
- run: cat packages/next/package.json | jq '.resolutions.webpack = "^5.0.0-beta.30"' > package.json.tmp && mv package.json.tmp packages/next/package.json
- run: cat packages/next/package.json | jq '.resolutions.react = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp packages/next/package.json
- run: cat packages/next/package.json | jq '.resolutions."react-dom" = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp packages/next/package.json
- run: yarn install --check-files
- run: node run-tests.js test/integration/production/test/index.test.js
- run: node run-tests.js test/integration/basic/test/index.test.js
- run: node run-tests.js test/integration/font-optimization/test/index.test.js
- run: node run-tests.js test/acceptance/*

testFirefox:
Expand Down
1 change: 1 addition & 0 deletions docs/advanced-features/custom-app.md
Expand Up @@ -44,6 +44,7 @@ The `Component` prop is the active `page`, so whenever you navigate between rout

- If your app is running and you just added a custom `App`, you'll need to restart the development server. Only required if `pages/_app.js` didn't exist before.
- Adding a custom `getInitialProps` in your `App` will disable [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md) in pages without [Static Generation](/docs/basic-features/data-fetching.md#getstaticprops-static-generation).
- `App` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching.md) like [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) or [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering).

### TypeScript

Expand Down
7 changes: 4 additions & 3 deletions docs/advanced-features/custom-document.md
Expand Up @@ -51,9 +51,10 @@ The `ctx` object is equivalent to the one received in [`getInitialProps`](/docs/

## Caveats

- `Document` is only rendered in the server, event handlers like `onClick` won't work
- React components outside of `<Main />` will not be initialized by the browser. Do _not_ add application logic here or custom CSS (like `styled-jsx`). If you need shared components in all your pages (like a menu or a toolbar), take a look at the [`App`](/docs/advanced-features/custom-app.md) component instead
- `Document`'s `getInitialProps` function is not called during client-side transitions, nor when a page is [statically optimized](/docs/advanced-features/automatic-static-optimization.md)
- `Document` is only rendered in the server, event handlers like `onClick` won't work.
- React components outside of `<Main />` will not be initialized by the browser. Do _not_ add application logic here or custom CSS (like `styled-jsx`). If you need shared components in all your pages (like a menu or a toolbar), take a look at the [`App`](/docs/advanced-features/custom-app.md) component instead.
- `Document`'s `getInitialProps` function is not called during client-side transitions, nor when a page is [statically optimized](/docs/advanced-features/automatic-static-optimization.md).
- `Document` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching.md) like [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) or [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering).

## Customizing `renderPage`

Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/fast-refresh.md
Expand Up @@ -75,7 +75,7 @@ local state being reset on every edit to a file:
- The file you're editing might have _other_ exports in addition to a React
component.
- Sometimes, a file would export the result of calling higher-order component
like `higherOrderComponent(WrappedComponent)`. If the returned component is a
like `HOC(WrappedComponent)`. If the returned component is a
class, state will be reset.

As more of your codebase moves to function components and Hooks, you can expect
Expand Down
1 change: 1 addition & 0 deletions examples/with-tailwindcss/tailwind.config.js
@@ -1,6 +1,7 @@
module.exports = {
future: {
removeDeprecatedGapUtilities: true,
purgeLayersByDefault: true,
},
purge: ['./components/**/*.{js,ts,jsx,tsx}', './pages/**/*.{js,ts,jsx,tsx}'],
theme: {
Expand Down
Expand Up @@ -5,8 +5,6 @@ import {
getFontDefinitionFromNetwork,
FontManifest,
} from '../../../next-server/server/font-utils'
// @ts-ignore
import BasicEvaluatedExpression from 'webpack/lib/BasicEvaluatedExpression'
import postcss from 'postcss'
import minifier from 'cssnano-simple'
import { OPTIMIZED_FONT_PROVIDERS } from '../../../next-server/lib/constants'
Expand All @@ -16,6 +14,13 @@ const { RawSource } = webpack.sources || sources

const isWebpack5 = parseInt(webpack.version!) === 5

let BasicEvaluatedExpression: any
if (isWebpack5) {
BasicEvaluatedExpression = require('webpack/lib/javascript/BasicEvaluatedExpression')
} else {
BasicEvaluatedExpression = require('webpack/lib/BasicEvaluatedExpression')
}

async function minifyCss(css: string): Promise<string> {
return new Promise((resolve) =>
postcss([
Expand Down Expand Up @@ -62,13 +67,20 @@ export class FontStylesheetGatheringPlugin {
if (parser?.state?.module?.resource.includes('node_modules')) {
return
}
return node.name === '__jsx'
? new BasicEvaluatedExpression()
//@ts-ignore
.setRange(node.range)
.setExpression(node)
.setIdentifier('__jsx')
: undefined
let result
if (node.name === '__jsx') {
result = new BasicEvaluatedExpression()
// @ts-ignore
result.setRange(node.range)
result.setExpression(node)
result.setIdentifier('__jsx')

// This was added webpack 5.
if (isWebpack5) {
result.getMembers = () => []
}
}
return result
})

parser.hooks.call
Expand Down
2 changes: 1 addition & 1 deletion packages/next/client/index.tsx
Expand Up @@ -92,7 +92,7 @@ if (process.env.__NEXT_i18n_SUPPORT) {
const localePathResult = normalizeLocalePath(asPath, locales)

if (localePathResult.detectedLocale) {
asPath = asPath.substr(localePathResult.detectedLocale.length + 1)
asPath = asPath.substr(localePathResult.detectedLocale.length + 1) || '/'
} else {
// derive the default locale if it wasn't detected in the asPath
// since we don't prerender static pages with all possible default
Expand Down
16 changes: 8 additions & 8 deletions packages/next/next-server/server/next-server.ts
Expand Up @@ -1150,6 +1150,13 @@ export default class Server {
const isDataReq = !!query._nextDataReq && (isSSG || isServerProps)
delete query._nextDataReq

const locale = query.__nextLocale as string
const locales = query.__nextLocales as string[]
// const defaultLocale = query.__nextDefaultLocale as string
delete query.__nextLocale
delete query.__nextLocales
// delete query.__nextDefaultLocale

let previewData: string | false | object | undefined
let isPreviewMode = false

Expand Down Expand Up @@ -1178,7 +1185,7 @@ export default class Server {
}

if (this.nextConfig.experimental.i18n) {
return normalizeLocalePath(path, this.renderOpts.locales).pathname
return normalizeLocalePath(path, locales).pathname
}
return path
}
Expand All @@ -1190,13 +1197,6 @@ export default class Server {
urlPathname = stripNextDataPath(urlPathname)
}

const locale = query.__nextLocale as string
const locales = query.__nextLocales as string[]
// const defaultLocale = query.__nextDefaultLocale as string
delete query.__nextLocale
delete query.__nextLocales
// delete query.__nextDefaultLocale

const ssgCacheKey =
isPreviewMode || !isSSG
? undefined // Preview mode bypasses the cache
Expand Down
43 changes: 41 additions & 2 deletions test/integration/i18n-support/test/index.test.js
Expand Up @@ -26,7 +26,46 @@ let appPort

const locales = ['en-US', 'nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en']

function runTests() {
function runTests(isDev) {
it('should update asPath on the client correctly', async () => {
for (const check of ['en', 'En']) {
const browser = await webdriver(appPort, `/${check}`)

expect(await browser.elementByCss('html').getAttribute('lang')).toBe('en')
expect(await browser.elementByCss('#router-locale').text()).toBe('en')
expect(
JSON.parse(await browser.elementByCss('#router-locales').text())
).toEqual(locales)
expect(await browser.elementByCss('#router-as-path').text()).toBe('/')
expect(await browser.elementByCss('#router-pathname').text()).toBe('/')
}
})

if (!isDev) {
it('should handle fallback correctly after generating', async () => {
const browser = await webdriver(
appPort,
'/en/gsp/fallback/hello-fallback'
)

// wait for the fallback to be generated/stored to ISR cache
browser.waitForElementByCss('#gsp')

// now make sure we're serving the previously generated file from the cache
const html = await renderViaHTTP(
appPort,
'/en/gsp/fallback/hello-fallback'
)
const $ = cheerio.load(html)

expect($('#gsp').text()).toBe('gsp page')
expect($('#router-locale').text()).toBe('en')
expect(JSON.parse($('#router-locales').text())).toEqual(locales)
expect($('#router-pathname').text()).toBe('/gsp/fallback/[slug]')
expect($('#router-as-path').text()).toBe('/gsp/fallback/hello-fallback')
})
}

it('should use correct default locale for locale domains', async () => {
const res = await fetchViaHTTP(appPort, '/', undefined, {
headers: {
Expand Down Expand Up @@ -729,7 +768,7 @@ describe('i18n Support', () => {
})
afterAll(() => killApp(app))

runTests()
runTests(true)
})

describe('production mode', () => {
Expand Down

0 comments on commit 5b6cb6e

Please sign in to comment.