Skip to content

Commit

Permalink
Merge branch 'canary' into fix/css-in-js-streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored Nov 2, 2022
2 parents 016e0eb + a6b4031 commit bf7e39c
Show file tree
Hide file tree
Showing 38 changed files with 334 additions and 224 deletions.
3 changes: 2 additions & 1 deletion docs/api-routes/request-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ import { setCookie } from '../../utils/cookies'

const handler = (req: NextApiRequest, res: NextApiResponse) => {
// Calling our pure function using the `res` object, it will add the `set-cookie` header
setCookie(res, 'Next.js', 'api-middleware!')
// Add the `set-cookie` header on the main domain and expire after 30 days
setCookie(res, 'Next.js', 'api-middleware!', { path: '/', maxAge: 2592000 })
// Return the `set-cookie` header so we can display it in the browser and show that it works!
res.end(res.getHeader('Set-Cookie'))
}
Expand Down
2 changes: 2 additions & 0 deletions docs/basic-features/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Although the default behavior of `next/script` allows you load third-party scrip

Refer to the [`next/script`](/docs/api-reference/next/script.md#strategy) API reference documentation to learn more about each strategy and their use cases.

> **Note**: Once a `next/script` component has been loaded by the browser, it will stay in the DOM and client-side navigations won't re-execute the script.
### Offloading Scripts To A Web Worker (experimental)

> **Note:** The `worker` strategy is not yet stable and does not yet work with the [`app/`](https://beta.nextjs.org/docs/routing/defining-routes) directory. Use with caution.
Expand Down
11 changes: 11 additions & 0 deletions errors/invalid-segment-export.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Invalid Layout or Page Export

#### Why This Error Occurred

Your [layout](https://beta.nextjs.org/docs/api-reference/file-conventions/layout) or [page](https://beta.nextjs.org/docs/api-reference/file-conventions/page) inside the app directory exports an invalid field. In these files, you're only allowed to export a default React component, or [Segment Configuration Options](https://beta.nextjs.org/docs/api-reference/segment-config) for layout and pages, such as `revalidate`, `generateStaticParams`, etc.

Other custom exports are not allowed to catch misspelt configuration options and prevent conflicts with future options.

#### Possible Ways to Fix It

You can create a new file and co-locate it with the page or layout. In the new file, you can export any custom fields and import it from anywhere.
4 changes: 4 additions & 0 deletions errors/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,10 @@
{
"title": "google-fonts-missing-subsets",
"path": "/errors/google-fonts-missing-subsets.md"
},
{
"title": "invalid-segment-export",
"path": "/errors/invalid-segment-export.md"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "13.0.1"
"version": "13.0.2-canary.0"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"faunadb": "2.6.1",
"firebase": "7.14.5",
"flat": "5.0.2",
"form-data": "4.0.0",
"fs-extra": "9.0.0",
"get-port": "5.1.1",
"glob": "7.1.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "13.0.1",
"version": "13.0.2-canary.0",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "13.0.1",
"version": "13.0.2-canary.0",
"description": "ESLint configuration used by NextJS.",
"main": "index.js",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
"directory": "packages/eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "13.0.1",
"@next/eslint-plugin-next": "13.0.2-canary.0",
"@rushstack/eslint-patch": "^1.1.3",
"@typescript-eslint/parser": "^5.21.0",
"eslint-import-resolver-node": "^0.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "13.0.1",
"version": "13.0.2-canary.0",
"description": "ESLint plugin for NextJS.",
"main": "dist/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/font",
"version": "13.0.1",
"version": "13.0.2-canary.0",
"repository": {
"url": "vercel/next.js",
"directory": "packages/font"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "13.0.1",
"version": "13.0.2-canary.0",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "13.0.1",
"version": "13.0.2-canary.0",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "13.0.1",
"version": "13.0.2-canary.0",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "13.0.1",
"version": "13.0.2-canary.0",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "13.0.1",
"version": "13.0.2-canary.0",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "13.0.1",
"version": "13.0.2-canary.0",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "13.0.1",
"version": "13.0.2-canary.0",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
5 changes: 0 additions & 5 deletions packages/next-swc/Cargo.lock

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

7 changes: 1 addition & 6 deletions packages/next-swc/crates/napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@ tracing = { version = "0.1.32", features = ["release_max_level_info"] }
tracing-futures = "0.2.5"
tracing-subscriber = "0.3.9"
tracing-chrome = "0.5.0"
owo-colors = "3"
turbo-tasks = { git = "https://github.com/vercel/turbo.git", rev = "a11422fdf6b1b3cde9072d90aab6d9eebfacb591" }
turbo-tasks-memory = { git = "https://github.com/vercel/turbo.git", rev = "a11422fdf6b1b3cde9072d90aab6d9eebfacb591" }
turbopack-core = { git = "https://github.com/vercel/turbo.git", rev = "a11422fdf6b1b3cde9072d90aab6d9eebfacb591" }
turbopack-dev-server = { git = "https://github.com/vercel/turbo.git", rev = "a11422fdf6b1b3cde9072d90aab6d9eebfacb591" }
next-dev = { git = "https://github.com/vercel/turbo.git", rev = "a11422fdf6b1b3cde9072d90aab6d9eebfacb591" }
next-dev = { git = "https://github.com/vercel/turbo.git", rev = "a11422fdf6b1b3cde9072d90aab6d9eebfacb591", features = ["serializable"] }
node-file-trace = { git = "https://github.com/vercel/turbo.git", rev = "a11422fdf6b1b3cde9072d90aab6d9eebfacb591", default-features = false, features = ["node-api"] }
# There are few build targets we can't use native-tls which default features rely on,
# allow to specify alternative (rustls) instead via features.
Expand Down
1 change: 0 additions & 1 deletion packages/next-swc/crates/napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/

#![feature(future_join)]
#![recursion_limit = "2048"]
//#![deny(clippy::all)]

Expand Down
154 changes: 3 additions & 151 deletions packages/next-swc/crates/napi/src/turbopack.rs
Original file line number Diff line number Diff line change
@@ -1,157 +1,9 @@
use std::{
future::join,
net::{IpAddr, Ipv4Addr},
path::PathBuf,
time::{Duration, Instant},
};

use crate::util::MapErr;
use napi::bindgen_prelude::*;
use next_dev::{register, NextDevServerBuilder};
use owo_colors::OwoColorize;
use serde::Deserialize;
use turbo_tasks::{util::FormatDuration, TurboTasks};
use turbo_tasks_memory::MemoryBackend;
use turbopack_core::issue::IssueSeverity;

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
#[allow(unused)]
struct TurboDevServerOptions {
#[serde(default = "default_port")]
port: u16,

#[serde(default = "default_host")]
hostname: IpAddr,

#[serde(default)]
eager_compile: bool,

#[serde(default)]
log_level: Option<IssueSeverity>,

#[serde(default)]
show_all: bool,

#[serde(default)]
log_detail: bool,

#[serde(default = "default_dir")]
dir: PathBuf,

#[serde(default = "default_dir")]
root_dir: PathBuf,

#[serde(default)]
allow_retry: bool,

#[serde(default)]
dev: bool,

#[serde(default)]
is_next_dev_command: bool,

#[serde(default)]
server_components_external_packages: Vec<String>,
}

fn default_port() -> u16 {
3000
}

fn default_host() -> IpAddr {
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))
}

fn default_dir() -> PathBuf {
std::env::current_dir().expect("Current dir should be accessible")
}

async fn start_server(options: TurboDevServerOptions) -> napi::Result<()> {
let start = Instant::now();

register();

let tt = TurboTasks::new(MemoryBackend::new());
let tt_clone = tt.clone();

let dir = options
.dir
.canonicalize()
.expect("Cannot canonicalize project directory")
.to_str()
.expect("project directory contains invalid characters")
.to_string();

let root_dir = options
.root_dir
.canonicalize()
.expect("Cannot canonicalize project directory")
.to_str()
.expect("project directory contains invalid characters")
.to_string();

//server_component_external

let mut server = NextDevServerBuilder::new(tt, dir, root_dir)
.entry_request("src/index".into())
.eager_compile(options.eager_compile)
.hostname(options.hostname)
.port(options.port)
.log_detail(options.log_detail)
.show_all(options.show_all)
.log_level(
options
.log_level
.map_or_else(|| IssueSeverity::Warning, |l| l),
);

for package in options.server_components_external_packages {
server = server.server_component_external(package);
}

let server = server.build().await.convert_err()?;

let index_uri = if server.addr.ip().is_loopback() || server.addr.ip().is_unspecified() {
format!("http://localhost:{}", server.addr.port())
} else {
format!("http://{}", server.addr)
};
println!(
"{} - started server on {}:{}, url: {}",
"ready".green(),
server.addr.ip(),
server.addr.port(),
index_uri
);

let stats_future = async move {
println!(
"{event_type} - initial compilation {start}",
event_type = "event".purple(),
start = FormatDuration(start.elapsed()),
);

loop {
let (elapsed, _count) = tt_clone
.get_or_wait_update_info(Duration::from_millis(100))
.await;
println!(
"{event_type} - updated in {elapsed}",
event_type = "event".purple(),
elapsed = FormatDuration(elapsed),
);
}
};

join!(stats_future, async { server.future.await.unwrap() }).await;

Ok(())
}
use next_dev::{devserver_options::DevServerOptions, start_server};

#[napi]
pub async fn start_turbo_dev(options: Buffer) -> napi::Result<()> {
let options: TurboDevServerOptions = serde_json::from_slice(&options)?;

start_server(options).await
let options: DevServerOptions = serde_json::from_slice(&options)?;
start_server(&options).await.convert_err()
}
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "13.0.1",
"version": "13.0.2-canary.0",
"private": true,
"scripts": {
"build-native": "napi build --platform -p next-swc-napi --cargo-name next_swc_napi --features plugin --js false native",
Expand Down
8 changes: 7 additions & 1 deletion packages/next/build/swc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,13 @@ function loadNative() {
teardownTraceSubscriber: bindings.teardownTraceSubscriber,
teardownCrashReporter: bindings.teardownCrashReporter,
turbo: {
startDev: (options) => bindings.startTurboDev(toBuffer(options)),
startDev: (options) => {
const devOptions = {
...options,
noOpen: options.noOpen ?? true,
}
bindings.startTurboDev(toBuffer(devOptions))
},
startTrace: (options = {}) =>
bindings.runTurboTracing(toBuffer({ exact: true, ...options })),
},
Expand Down
4 changes: 2 additions & 2 deletions packages/next/compiled/undici/index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/next/lib/server-external-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ export const EXTERNAL_PACKAGES = [
'next-seo',
'rimraf',
'next-mdx-remote',
'sqlite3',
'mongodb',
]
4 changes: 2 additions & 2 deletions packages/next/lib/typescript/diagnosticFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ function getFormattedLayoutAndPageDiagnosticMessageText(
if (filepathAndInvalidExport) {
const main = `${type} "${chalk.bold(
relativeSourceFile
)}" exports invalid field "${chalk.bold(
)}" exports an invalid "${chalk.bold(
filepathAndInvalidExport[2]
)}". Only "default" and other configuration exports are allowed.`
)}" field. ${type} should only export a default React component and configuration options. Learn more: https://nextjs.org/docs/messages/invalid-segment-export`
return main
}
break
Expand Down
Loading

0 comments on commit bf7e39c

Please sign in to comment.