Skip to content

Commit

Permalink
Merge branch 'canary' into add/legacybrowsers-rfc
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed May 17, 2022
2 parents c6eeb26 + c947abb commit 79a2da5
Show file tree
Hide file tree
Showing 17 changed files with 390 additions and 83 deletions.
23 changes: 23 additions & 0 deletions docs/deployment.md
Expand Up @@ -98,6 +98,29 @@ Next.js will automatically load the latest version of your application in the ba

**Note:** If a new page (with an old version) has already been prefetched by `next/link`, Next.js will use the old version. Navigating to a page that has _not_ been prefetched (and is not cached at the CDN level) will load the latest version.

## Manual Graceful shutdowns

Sometimes you might want to run some cleanup code on process signals like `SIGTERM` or `SIGINT`.

You can do that by setting the env variable `NEXT_MANUAL_SIG_HANDLE` to `true` and then register a handler for that signal inside your `_document.js` file.

```js
// pages/_document.js

if (process.env.NEXT_MANUAL_SIG_HANDLE) {
// this should be added in your custom _document
process.on('SIGTERM', () => {
console.log('Received SIGTERM: ', 'cleaning up')
process.exit(0)
})

process.on('SIGINT', () => {
console.log('Received SIGINT: ', 'cleaning up')
process.exit(0)
})
}
```

## Related

For more information on what to do next, we recommend the following sections:
Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions packages/next-swc/crates/core/src/next_dynamic.rs
Expand Up @@ -223,6 +223,7 @@ impl Fold for NextDynamicPatcher {
})))];

let mut has_ssr_false = false;
let mut has_suspense = false;

if expr.args.len() == 2 {
if let Expr::Object(ObjectLit {
Expand Down Expand Up @@ -250,21 +251,29 @@ impl Fold for NextDynamicPatcher {
if let Some(Lit::Bool(Bool {
value: false,
span: _,
})) = match &**value {
Expr::Lit(lit) => Some(lit),
_ => None,
} {
})) = value.as_lit()
{
has_ssr_false = true
}
}
if sym == "suspense" {
if let Some(Lit::Bool(Bool {
value: true,
span: _,
})) = value.as_lit()
{
has_suspense = true
}
}
}
}
}
props.extend(options_props.iter().cloned());
}
}

if has_ssr_false && self.is_server {
// Don't need to strip the `loader` argument if suspense is true
// See https://github.com/vercel/next.js/issues/36636 for background
if has_ssr_false && !has_suspense && self.is_server {
expr.args[0] = Lit::Null(Null { span: DUMMY_SP }).as_arg();
}

Expand Down
Expand Up @@ -9,3 +9,8 @@ const DynamicClientOnlyComponent = dynamic(
() => import('../components/hello'),
{ ssr: false }
)

const DynamicClientOnlyComponentWithSuspense = dynamic(
() => import('../components/hello'),
{ ssr: false, suspense: true }
)
Expand Up @@ -17,3 +17,13 @@ const DynamicClientOnlyComponent = dynamic(()=>import('../components/hello')
},
ssr: false
});
const DynamicClientOnlyComponentWithSuspense = dynamic(()=>import('../components/hello')
, {
loadableGenerated: {
modules: [
"some-file.js -> " + "../components/hello"
]
},
ssr: false,
suspense: true
});
Expand Up @@ -17,3 +17,13 @@ const DynamicClientOnlyComponent = dynamic(()=>import('../components/hello')
},
ssr: false
});
const DynamicClientOnlyComponentWithSuspense = dynamic(()=>import('../components/hello')
, {
loadableGenerated: {
webpack: ()=>[
require.resolveWeak("../components/hello")
]
},
ssr: false,
suspense: true
});
Expand Up @@ -16,3 +16,13 @@ const DynamicClientOnlyComponent = dynamic(null, {
},
ssr: false
});
const DynamicClientOnlyComponentWithSuspense = dynamic(()=>import('../components/hello')
, {
loadableGenerated: {
modules: [
"some-file.js -> " + "../components/hello"
]
},
ssr: false,
suspense: true
});
7 changes: 5 additions & 2 deletions packages/next/bin/next.ts
Expand Up @@ -129,8 +129,11 @@ if (process.versions.pnp === '3') {
}

// Make sure commands gracefully respect termination signals (e.g. from Docker)
process.on('SIGTERM', () => process.exit(0))
process.on('SIGINT', () => process.exit(0))
// Allow the graceful termination to be manually configurable
if (!process.env.NEXT_MANUAL_SIG_HANDLE) {
process.on('SIGTERM', () => process.exit(0))
process.on('SIGINT', () => process.exit(0))
}

commands[command]()
.then((exec) => exec(forwardedArgs))
Expand Down
6 changes: 5 additions & 1 deletion packages/next/build/swc/options.js
Expand Up @@ -105,7 +105,11 @@ function getBaseSWCOptions({
}
: null,
removeConsole: nextConfig?.compiler?.removeConsole,
reactRemoveProperties: nextConfig?.compiler?.reactRemoveProperties,
// disable "reactRemoveProperties" when "jest" is true
// otherwise the setting from next.config.js will be used
reactRemoveProperties: jest
? false
: nextConfig?.compiler?.reactRemoveProperties,
modularizeImports: nextConfig?.experimental?.modularizeImports,
relay: nextConfig?.compiler?.relay,
emotion: getEmotionOptions(nextConfig, development),
Expand Down

0 comments on commit 79a2da5

Please sign in to comment.