Unverified Commit 19a61586 authored by Nicolas's avatar Nicolas Committed by GitHub

Add config support for build activity indicator position (#30109)

When you edit your code, and Next.js is compiling the application, a compilation indicator appears in the bottom right corner of the page.

In some cases this indicator can be misplaced on the page, for example, when conflicting with a chat launcher. To change its position, open `next.config.js` and set the `buildActivityPosition` in the `devIndicators` object to `bottom-right` (default), `bottom-left`, `top-right` or `top-left`.

I also added the documentation for both `devIndicators.buildActivity` & the new `devIndicators.buildActivityPosition`.

## Feature

- [x] Implements a new feature
- [x] Documentation added
parent f1f498ef
---
description: In development mode, pages include an indicator to let you know if your new code it's being compiled. You can opt-out of it here.
---
# Build indicator
When you edit your code, and Next.js is compiling the application, a compilation indicator appears in the bottom right corner of the page.
> **Note:** This indicator is only present in development mode and will not appear when building and running the app in production mode.
In some cases this indicator can be misplaced on your page, for example, when conflicting with a chat launcher. To change its position, open `next.config.js` and set the `buildActivityPosition` in the `devIndicators` object to `bottom-right` (default), `bottom-left`, `top-right` or `top-left`:
```js
module.exports = {
devIndicators: {
buildActivityPosition: 'bottom-right',
},
}
```
In some cases this indicator might not be useful for you. To remove it, open `next.config.js` and disable the `buildActivity` config in `devIndicators` object:
```js
module.exports = {
devIndicators: {
buildActivity: false,
},
}
```
...@@ -411,6 +411,10 @@ ...@@ -411,6 +411,10 @@
{ {
"title": "URL Imports", "title": "URL Imports",
"path": "/docs/api-reference/next.config.js/url-imports.md" "path": "/docs/api-reference/next.config.js/url-imports.md"
},
{
"title": "Build indicator",
"path": "/docs/api-reference/next.config.js/build-indicator.md"
} }
] ]
} }
......
...@@ -1333,6 +1333,9 @@ export default async function getBaseWebpackConfig( ...@@ -1333,6 +1333,9 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_BUILD_INDICATOR': JSON.stringify( 'process.env.__NEXT_BUILD_INDICATOR': JSON.stringify(
config.devIndicators.buildActivity config.devIndicators.buildActivity
), ),
'process.env.__NEXT_BUILD_INDICATOR_POSITION': JSON.stringify(
config.devIndicators.buildActivityPosition
),
'process.env.__NEXT_PLUGINS': JSON.stringify( 'process.env.__NEXT_PLUGINS': JSON.stringify(
config.experimental.plugins config.experimental.plugins
), ),
...@@ -1584,6 +1587,7 @@ export default async function getBaseWebpackConfig( ...@@ -1584,6 +1587,7 @@ export default async function getBaseWebpackConfig(
pageExtensions: config.pageExtensions, pageExtensions: config.pageExtensions,
trailingSlash: config.trailingSlash, trailingSlash: config.trailingSlash,
buildActivity: config.devIndicators.buildActivity, buildActivity: config.devIndicators.buildActivity,
buildActivityPosition: config.devIndicators.buildActivityPosition,
productionBrowserSourceMaps: !!config.productionBrowserSourceMaps, productionBrowserSourceMaps: !!config.productionBrowserSourceMaps,
plugins: config.experimental.plugins, plugins: config.experimental.plugins,
reactStrictMode: config.reactStrictMode, reactStrictMode: config.reactStrictMode,
......
import { addMessageListener } from './error-overlay/websocket' import { addMessageListener } from './error-overlay/websocket'
export default function initializeBuildWatcher(toggleCallback) { export default function initializeBuildWatcher(
toggleCallback,
position = 'bottom-right'
) {
const shadowHost = document.createElement('div') const shadowHost = document.createElement('div')
shadowHost.id = '__next-build-watcher' shadowHost.id = '__next-build-watcher'
// Make sure container is fixed and on a high zIndex so it shows // Make sure container is fixed and on a high zIndex so it shows
shadowHost.style.position = 'fixed' shadowHost.style.position = 'fixed'
shadowHost.style.bottom = '10px' // Ensure container's position to be top or bottom (default)
shadowHost.style.right = '20px' if (['top-left', 'top-right'].indexOf(position) > -1) {
shadowHost.style.top = '10px'
} else {
shadowHost.style.bottom = '10px'
}
// Ensure container's position to be left or right (default)
if (['bottom-left', 'top-left'].indexOf(position) > -1) {
shadowHost.style.left = '20px'
} else {
shadowHost.style.right = '20px'
}
shadowHost.style.width = 0 shadowHost.style.width = 0
shadowHost.style.height = 0 shadowHost.style.height = 0
shadowHost.style.zIndex = 99999 shadowHost.style.zIndex = 99999
......
...@@ -91,7 +91,7 @@ initNext({ webpackHMR }) ...@@ -91,7 +91,7 @@ initNext({ webpackHMR })
if (process.env.__NEXT_BUILD_INDICATOR) { if (process.env.__NEXT_BUILD_INDICATOR) {
initializeBuildWatcher((handler) => { initializeBuildWatcher((handler) => {
buildIndicatorHandler = handler buildIndicatorHandler = handler
}) }, process.env.__NEXT_BUILD_INDICATOR_POSITION)
} }
// delay rendering until after styles have been applied in development // delay rendering until after styles have been applied in development
......
...@@ -93,6 +93,11 @@ export type NextConfig = { [key: string]: any } & { ...@@ -93,6 +93,11 @@ export type NextConfig = { [key: string]: any } & {
images?: ImageConfig images?: ImageConfig
devIndicators?: { devIndicators?: {
buildActivity?: boolean buildActivity?: boolean
buildActivityPosition?:
| 'bottom-right'
| 'bottom-left'
| 'top-right'
| 'top-left'
} }
onDemandEntries?: { onDemandEntries?: {
maxInactiveAge?: number maxInactiveAge?: number
...@@ -179,6 +184,7 @@ export const defaultConfig: NextConfig = { ...@@ -179,6 +184,7 @@ export const defaultConfig: NextConfig = {
images: imageConfigDefault, images: imageConfigDefault,
devIndicators: { devIndicators: {
buildActivity: true, buildActivity: true,
buildActivityPosition: 'bottom-right',
}, },
onDemandEntries: { onDemandEntries: {
maxInactiveAge: 15 * 1000, maxInactiveAge: 15 * 1000,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment