Skip to content

Commit

Permalink
Merge branch 'canary' into removeclassnamesdep
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Dec 15, 2021
2 parents e66915b + 5d606eb commit ce8e477
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
12 changes: 9 additions & 3 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,12 +1242,18 @@ export default async function build(
processCwd: dir,
ignore: [
'**/next/dist/pages/**/*',
'**/next/dist/server/image-optimizer.js',
'**/next/dist/compiled/@ampproject/toolbox-optimizer/**/*',
'**/next/dist/server/lib/squoosh/**/*.wasm',
'**/next/dist/compiled/webpack/(bundle4|bundle5).js',
'**/node_modules/sharp/**/*',
'**/node_modules/webpack5/**/*',
'**/next/dist/server/lib/squoosh/**/*.wasm',
...(ciEnvironment.hasNextSupport
? [
// only ignore image-optimizer code when
// this is being handled outside of next-server
'**/next/dist/server/image-optimizer.js',
'**/node_modules/sharp/**/*',
]
: []),
],
}
)
Expand Down
13 changes: 13 additions & 0 deletions packages/next/server/image-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,19 @@ export async function imageOptimizer(
optimizedBuffer = await transformer.toBuffer()
// End sharp transformation logic
} else {
if (
showSharpMissingWarning &&
nextConfig.experimental?.outputStandalone
) {
// TODO: should we ensure squoosh also works even though we don't
// recommend it be used in production and this is a production feature
console.error(
`Error: 'sharp' is required to be installed in standalone mode for the image optimization to function correctly`
)
req.statusCode = 500
res.end('internal server error')
return { finished: true }
}
// Show sharp warning in production once
if (showSharpMissingWarning) {
console.warn(
Expand Down
13 changes: 8 additions & 5 deletions packages/next/shared/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1134,11 +1134,14 @@ export default class Router implements BaseRouter {
resolvedAs = delLocale(delBasePath(resolvedAs), this.locale)

/**
* If the route update was triggered for client-side hydration then
* do not check the preflight request. Otherwise when rendering
* a page with refresh it might get into an infinite loop.
* If the route update was triggered for client-side hydration and
* the rendered route is not dynamic do not check the preflight
* request as it is not necessary.
*/
if ((options as any)._h !== 1) {
if (
(options as any)._h !== 1 ||
isDynamicRoute(removePathTrailingSlash(pathname))
) {
const effect = await this._preflightRequest({
as,
cache: process.env.NODE_ENV === 'production',
Expand All @@ -1158,7 +1161,7 @@ export default class Router implements BaseRouter {
} else if (effect.type === 'redirect' && effect.destination) {
window.location.href = effect.destination
return new Promise(() => {})
} else if (effect.type === 'refresh') {
} else if (effect.type === 'refresh' && as !== window.location.pathname) {
window.location.href = as
return new Promise(() => {})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const PartsPage = () => {
return <div className="title">Parts page</div>
}

export default PartsPage
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export async function middleware(request) {
return fetch(url)
}

if (url.pathname.endsWith('/dynamic-replace')) {
return NextResponse.rewrite('/_interface/dynamic-path')
}

return new Response(null, {
headers: {
'req-url-basepath': request.nextUrl.basePath,
Expand Down
11 changes: 11 additions & 0 deletions test/integration/middleware/core/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,17 @@ function interfaceTests(locale = '') {
)
expect(res.headers.get('x-dynamic-path')).toBe('true')
})

it(`${locale} renders correctly rewriting to a different dynamic path`, async () => {
const browser = await webdriver(
context.appPort,
'/interface/dynamic-replace'
)
const element = await browser.elementByCss('.title')
expect(await element.text()).toEqual('Parts page')
const logs = await browser.log()
expect(logs.every((log) => log.source === 'log')).toEqual(true)
})
}

function getCookieFromResponse(res, cookieName) {
Expand Down

0 comments on commit ce8e477

Please sign in to comment.