Skip to content

Commit

Permalink
Merge branch 'canary' into chore/rm-deprecated-substr
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle authored Mar 21, 2022
2 parents e5b473b + cd47984 commit 2b3b0f8
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 14 deletions.
3 changes: 3 additions & 0 deletions docs/api-reference/next.config.js/redirects.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ module.exports = {
- `source` is the incoming request path pattern.
- `destination` is the path you want to route to.
- `permanent` `true` or `false` - if `true` will use the 308 status code which instructs clients/search engines to cache the redirect forever, if `false` will use the 307 status code which is temporary and is not cached.

> **Why does Next.js use 307 and 308?** Traditionally a 302 was used for a temporary redirect, and a 301 for a permanent redirect, but many browsers changed the request method of the redirect to `GET`, regardless of the original method. For example, if the browser made a request to `POST /v1/users` which returned status code `302` with location `/v2/users`, the subsequent request might be `GET /v2/users` instead of the expected `POST /v2/users`. Next.js uses the 307 temporary redirect, and 308 permanent redirect status codes to explicitly preserve the request method used.
- `basePath`: `false` or `undefined` - if false the basePath won't be included when matching, can be used for external rewrites only.
- `locale`: `false` or `undefined` - whether the locale should not be included when matching.
- `has` is an array of [has objects](#header-cookie-and-query-matching) with the `type`, `key` and `value` properties.
Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/data-fetching/get-server-side-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function getServerSideProps(context) {
- When you request this page directly, `getServerSideProps` runs at request time, and this page will be pre-rendered with the returned props
- When you request this page on client-side page transitions through [`next/link`](/docs/api-reference/next/link.md) or [`next/router`](/docs/api-reference/next/router.md), Next.js sends an API request to the server, which runs `getServerSideProps`

It then returns `JSON` that contains the result of running `getServerSideProps`, that `JSON` will be used to render the page. All this work will be handled automatically by Next.js, so you don’t need to do anything extra as long as you have `getServerSideProps` defined.
`getServerSideProps` returns JSON which will be used to render the page. All this work will be handled automatically by Next.js, so you don’t need to do anything extra as long as you have `getServerSideProps` defined.

You can use the [next-code-elimination tool](https://next-code-elimination.vercel.app/) to verify what Next.js eliminates from the client-side bundle.

Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ description: Next.js helps you optimize loading third-party scripts with the bui

</details>

The Next.js Script component, [`next/script`](/docs/api-reference/next/script.md), is an extension of the HTML `<script>` element. It enables developers to set the loading priority of third-party scripts anywhere in their application without needing to append directly to `next/head`, saving developer time while improving loading performance.
The Next.js Script component, [`next/script`](/docs/api-reference/next/script.md), is an extension of the HTML `<script>` element. It enables developers to set the loading priority of third-party scripts anywhere in their application, outside `next/head`, saving developer time while improving loading performance.

```jsx
import Script from 'next/script'
Expand Down
18 changes: 18 additions & 0 deletions packages/next-swc/crates/napi/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
use std::{
env,
fs::File,
io::{BufWriter, Write},
path::Path,
};

extern crate napi_build;

fn main() {
let out_dir = env::var("OUT_DIR").expect("Outdir should exist");
let dest_path = Path::new(&out_dir).join("triple.txt");
let mut f =
BufWriter::new(File::create(&dest_path).expect("Failed to create target triple text"));
write!(
f,
"{}",
env::var("TARGET").expect("Target should be specified")
)
.expect("Failed to write target triple text");

napi_build::setup();
}
2 changes: 2 additions & 0 deletions packages/next-swc/crates/napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ fn init(mut exports: JsObject) -> napi::Result<()> {

exports.create_named_method("parse", parse::parse)?;

exports.create_named_method("getTargetTriple", util::get_target_triple)?;

Ok(())
}

Expand Down
9 changes: 8 additions & 1 deletion packages/next-swc/crates/napi/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ DEALINGS IN THE SOFTWARE.
*/

use anyhow::{Context, Error};
use napi::{CallContext, JsBuffer, Status};
use napi::{CallContext, Env, JsBuffer, JsString, Status};
use serde::de::DeserializeOwned;
use std::any::type_name;

static TARGET_TRIPLE: &str = include_str!(concat!(env!("OUT_DIR"), "/triple.txt"));

#[contextless_function]
pub fn get_target_triple(env: Env) -> napi::ContextlessResult<JsString> {
env.create_string(TARGET_TRIPLE).map(Some)
}

pub trait MapErr<T>: Into<Result<T, anyhow::Error>> {
fn convert_err(self) -> napi::Result<T> {
self.into()
Expand Down
7 changes: 7 additions & 0 deletions packages/next/build/swc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,10 @@ export async function parse(src, options) {
let parserOptions = getParserOptions(options)
return bindings.parse(src, parserOptions).then((astStr) => JSON.parse(astStr))
}

export function getBinaryMetadata() {
let bindings = loadBindingsSync()
return {
target: bindings.getTargetTriple(),
}
}
2 changes: 1 addition & 1 deletion packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export default async function getBaseWebpackConfig(

if (!loggedIgnoredCompilerOptions && !useSWCLoader && config.compiler) {
Log.info(
'`compiler` options in `next.config.js` will be ignored while using Babel https://next.js.org/docs/messages/ignored-compiler-options'
'`compiler` options in `next.config.js` will be ignored while using Babel https://nextjs.org/docs/messages/ignored-compiler-options'
)
loggedIgnoredCompilerOptions = true
}
Expand Down
29 changes: 19 additions & 10 deletions test/e2e/prerender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1922,11 +1922,15 @@ describe('Prerender', () => {
expect(res.status).toBe(200)
}
await next.deleteFile('error.txt')
expect(
next.cliOutput.match(
/throwing error for \/blocking-fallback\/test-errors-1/
).length
).toBe(1)
await check(
() =>
next.cliOutput.match(
/throwing error for \/blocking-fallback\/test-errors-1/
).length === 1
? 'success'
: next.cliOutput,
'success'
)
})

it('should automatically reset cache TTL when an error occurs and runtime cache was available', async () => {
Expand All @@ -1947,11 +1951,16 @@ describe('Prerender', () => {
expect(res.status).toBe(200)
}
await next.deleteFile('error.txt')
expect(
next.cliOutput.match(
/throwing error for \/blocking-fallback\/test-errors-2/
).length
).toBe(1)

await check(
() =>
next.cliOutput.match(
/throwing error for \/blocking-fallback\/test-errors-2/
).length === 1
? 'success'
: next.cliOutput,
'success'
)
})

it('should handle manual revalidate for fallback: blocking', async () => {
Expand Down

0 comments on commit 2b3b0f8

Please sign in to comment.