Skip to content

Commit

Permalink
Merge branch 'canary' into plugin/page-type-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Feb 3, 2022
2 parents 19e00c7 + b772513 commit b8b4c7c
Show file tree
Hide file tree
Showing 26 changed files with 122 additions and 69 deletions.
8 changes: 3 additions & 5 deletions docs/deployment.md
Expand Up @@ -28,9 +28,9 @@ All JavaScript code inside `.next` has been **compiled** and browser bundles hav

## Managed Next.js with Vercel

[Vercel](https://vercel.com/) is a frontend cloud platform from the creators of Next.js. It's the fastest way to deploy your managed Next.js application with zero configuration.
[Vercel](https://vercel.com?utm_source=github.com&utm_medium=referral&utm_campaign=deployment) is the fastest way to deploy your Next.js application with zero configuration.

When deploying to Vercel, the platform automatically detects Next.js, runs `next build`, and optimizes the build output for you, including:
When deploying to Vercel, the platform [automatically detects Next.js](https://vercel.com/solutions/nextjs?utm_source=github.com&utm_medium=referral&utm_campaign=deployment), runs `next build`, and optimizes the build output for you, including:

- Persisting cached assets across deployments if unchanged
- [Immutable deployments](https://vercel.com/features/previews) with a unique URL for every commit
Expand All @@ -49,9 +49,7 @@ In addition, Vercel provides features like:
- Support for [Image Optimization](/docs/basic-features/image-optimization.md) with `next/image`
- Instant global deployments via `git push`

You can start using Vercel (for free) through a personal hobby account, or create a team to start the next big thing. Learn more about [Next.js on Vercel](https://vercel.com/solutions/nextjs) or read the [Vercel Documentation](https://vercel.com/docs).

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/hello-world&project-name=hello-world&repository-name=hello-world&utm_source=github.com&utm_medium=referral&utm_campaign=deployment)
[Deploy a Next.js application to Vercel](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/hello-world&project-name=hello-world&repository-name=hello-world&utm_source=github.com&utm_medium=referral&utm_campaign=deployment) for free to try it out.

## Self-Hosting

Expand Down
2 changes: 1 addition & 1 deletion errors/invalid-api-status-body.md
Expand Up @@ -22,7 +22,7 @@ After

```js
export default function handler(req, res) {
res.status(204).send()
res.status(204).end()
}
```

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.0.11-canary.2"
"version": "12.0.11-canary.3"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"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": "12.0.11-canary.2",
"@next/eslint-plugin-next": "12.0.11-canary.3",
"@rushstack/eslint-patch": "^1.0.8",
"@typescript-eslint/parser": "^5.0.0",
"eslint-import-resolver-node": "^0.3.4",
Expand Down
17 changes: 12 additions & 5 deletions packages/eslint-plugin-next/lib/rules/inline-script-id.js
Expand Up @@ -27,15 +27,22 @@ module.exports = {
return
}

const attributes = node.openingElement.attributes
const attributeNames = new Set()
node.openingElement.attributes.forEach((attribute) => {
if (attribute.type === 'JSXAttribute') {
attributeNames.add(attribute.name.name)
} else if (attribute.type === 'JSXSpreadAttribute') {
attribute.argument.properties.forEach((property) => {
attributeNames.add(property.key.name)
})
}
})

if (
node.children.length > 0 ||
attributes.some(
(attribute) => attribute.name.name === 'dangerouslySetInnerHTML'
)
attributeNames.has('dangerouslySetInnerHTML')
) {
if (!attributes.some((attribute) => attribute.name.name === 'id')) {
if (!attributeNames.has('id')) {
context.report({
node,
message:
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"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
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/core/src/lib.rs
Expand Up @@ -112,7 +112,7 @@ pub fn custom_before_pass(
#[cfg(not(target_arch = "wasm32"))]
let relay_plugin = {
if let Some(config) = &opts.relay {
Either::Left(relay::relay(config, file.name.clone()))
Either::Left(relay::relay(config, file.name.clone(), opts.pages_dir.clone()))
} else {
Either::Right(noop())
}
Expand Down
68 changes: 43 additions & 25 deletions packages/next-swc/crates/core/src/relay.rs
Expand Up @@ -24,6 +24,7 @@ impl Default for RelayLanguageConfig {

struct Relay<'a> {
root_dir: PathBuf,
pages_dir: PathBuf,
file_name: FileName,
config: &'a Config,
}
Expand Down Expand Up @@ -85,36 +86,44 @@ impl<'a> Fold for Relay<'a> {
#[derive(Debug)]
enum BuildRequirePathError {
FileNameNotReal,
ArtifactDirectoryExpected,
ArtifactDirectoryExpected { file_name: String },
}

fn path_for_artifact(
root_dir: &Path,
config: &Config,
definition_name: &str,
) -> Result<PathBuf, BuildRequirePathError> {
let filename = match &config.language {
RelayLanguageConfig::Flow => format!("{}.graphql.js", definition_name),
RelayLanguageConfig::TypeScript => {
format!("{}.graphql.ts", definition_name)
}
};
impl<'a> Relay<'a> {
fn path_for_artifact(
&self,
real_file_name: &Path,
definition_name: &str,
) -> Result<PathBuf, BuildRequirePathError> {
let filename = match &self.config.language {
RelayLanguageConfig::Flow => format!("{}.graphql.js", definition_name),
RelayLanguageConfig::TypeScript => {
format!("{}.graphql.ts", definition_name)
}
};

if let Some(artifact_directory) = &config.artifact_directory {
Ok(root_dir.join(artifact_directory).join(filename))
} else {
Err(BuildRequirePathError::ArtifactDirectoryExpected)
if let Some(artifact_directory) = &self.config.artifact_directory {
Ok(self.root_dir.join(artifact_directory).join(filename))
} else if real_file_name.starts_with(&self.pages_dir) {
Err(BuildRequirePathError::ArtifactDirectoryExpected {
file_name: real_file_name.display().to_string(),
})
} else {
Ok(real_file_name
.parent()
.unwrap()
.join("__generated__")
.join(filename))
}
}
}

impl<'a> Relay<'a> {
fn build_require_path(
&mut self,
operation_name: &str,
) -> Result<PathBuf, BuildRequirePathError> {
match &self.file_name {
FileName::Real(_real_file_name) => {
path_for_artifact(&self.root_dir, self.config, operation_name)
FileName::Real(real_file_name) => {
self.path_for_artifact(real_file_name, operation_name)
}
_ => Err(BuildRequirePathError::FileNameNotReal),
}
Expand All @@ -140,10 +149,14 @@ impl<'a> Relay<'a> {
file. This is likely a bug and \
should be reported to Next.js"
.to_string(),
BuildRequirePathError::ArtifactDirectoryExpected => {
"The `artifactDirectory` is expected to be set in the Relay config \
file to work correctly with Next.js."
.to_string()
BuildRequirePathError::ArtifactDirectoryExpected { file_name } => {
format!(
"The generated file for `{}` will be created in `pages` \
directory, which will break production builds. Try moving the \
file outside of `pages` or set the `artifactDirectory` in the \
Relay config file.",
file_name
)
}
};

Expand All @@ -161,10 +174,15 @@ impl<'a> Relay<'a> {
}
}

pub fn relay<'a>(config: &'a Config, file_name: FileName) -> impl Fold + '_ {
pub fn relay<'a>(
config: &'a Config,
file_name: FileName,
pages_dir: Option<PathBuf>,
) -> impl Fold + '_ {
Relay {
root_dir: std::env::current_dir().unwrap(),
file_name,
pages_dir: pages_dir.unwrap_or_else(|| panic!("pages_dir is expected.")),
config,
}
}
8 changes: 7 additions & 1 deletion packages/next-swc/crates/core/tests/fixture.rs
Expand Up @@ -160,7 +160,13 @@ fn relay_no_artifact_dir_fixture(input: PathBuf) {
};
test_fixture(
syntax(),
&|_tr| relay(&config, FileName::Real(PathBuf::from("input.tsx"))),
&|_tr| {
relay(
&config,
FileName::Real(PathBuf::from("input.tsx")),
Some(PathBuf::from("src/pages")),
)
},
&input,
&output,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"private": true,
"scripts": {
"build-native": "napi build --platform --cargo-name next_swc_napi native",
Expand Down
14 changes: 7 additions & 7 deletions packages/next/package.json
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -69,7 +69,7 @@
]
},
"dependencies": {
"@next/env": "12.0.11-canary.2",
"@next/env": "12.0.11-canary.3",
"caniuse-lite": "^1.0.30001283",
"postcss": "8.4.5",
"styled-jsx": "5.0.0",
Expand Down Expand Up @@ -117,11 +117,11 @@
"@hapi/accept": "5.0.2",
"@napi-rs/cli": "1.2.1",
"@napi-rs/triples": "1.0.3",
"@next/polyfill-module": "12.0.11-canary.2",
"@next/polyfill-nomodule": "12.0.11-canary.2",
"@next/react-dev-overlay": "12.0.11-canary.2",
"@next/react-refresh-utils": "12.0.11-canary.2",
"@next/swc": "12.0.11-canary.2",
"@next/polyfill-module": "12.0.11-canary.3",
"@next/polyfill-nomodule": "12.0.11-canary.3",
"@next/react-dev-overlay": "12.0.11-canary.3",
"@next/react-refresh-utils": "12.0.11-canary.3",
"@next/swc": "12.0.11-canary.3",
"@peculiar/webcrypto": "1.1.7",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-overlay/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/react-dev-overlay",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"description": "A development-only overlay for developing React applications.",
"repository": {
"url": "vercel/next.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-refresh-utils/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/react-refresh-utils",
"version": "12.0.11-canary.2",
"version": "12.0.11-canary.3",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down
Expand Up @@ -2,13 +2,13 @@ import {
Environment,
FetchFunction,
fetchQuery,
graphql,
Network,
RecordSource,
Store,
} from 'relay-runtime'
import { GetServerSideProps } from 'next'
import { pagesQuery } from '../__generated__/pagesQuery.graphql'
import { pagesQuery as pagesQueryType } from '../queries/__generated__/pagesQuery.graphql'
import pagesQuery from '../queries/pagesQuery'

type Props = { greeting: string }

Expand Down Expand Up @@ -41,13 +41,9 @@ export const getServerSideProps: GetServerSideProps = async ({ req }) => {
network: Network.create(createGraphQLFetcher(req.headers.host)),
})

const result = await fetchQuery<pagesQuery>(
const result = await fetchQuery<pagesQueryType>(
environment,
graphql`
query pagesQuery {
greeting
}
`,
pagesQuery,
{}
).toPromise()

Expand Down
@@ -0,0 +1,7 @@
import { graphql } from 'relay-runtime'

export default graphql`
query pagesQuery {
greeting
}
`
@@ -1,6 +1,5 @@
module.exports = {
src: './pages',
schema: './schema.graphql',
artifactDirectory: './__generated__',
language: 'typescript',
}

0 comments on commit b8b4c7c

Please sign in to comment.