Unverified Commit 0fa4261a authored by Hassan El Mghari's avatar Hassan El Mghari Committed by GitHub

Merge branch 'canary' into improve-data-fetching

parents 6f7f0a38 4f054260
...@@ -323,7 +323,7 @@ module.exports = { ...@@ -323,7 +323,7 @@ module.exports = {
The following Image Optimization cloud providers are included: The following Image Optimization cloud providers are included:
- Default: Works automatically with `next dev`, `next start`, or a custom server - Default: Works automatically with `next dev`, `next start`, or a custom server
- [Vercel](https://vercel.com): Works automatically when you deploy on Vercel, no configuration necessary. [Learn more](https://vercel.com/docs/next.js/image-optimization) - [Vercel](https://vercel.com): Works automatically when you deploy on Vercel, no configuration necessary. [Learn more](https://vercel.com/docs/concepts/image-optimization)
- [Imgix](https://www.imgix.com): `loader: 'imgix'` - [Imgix](https://www.imgix.com): `loader: 'imgix'`
- [Cloudinary](https://cloudinary.com): `loader: 'cloudinary'` - [Cloudinary](https://cloudinary.com): `loader: 'cloudinary'`
- [Akamai](https://www.akamai.com): `loader: 'akamai'` - [Akamai](https://www.akamai.com): `loader: 'akamai'`
......
...@@ -19,7 +19,7 @@ The big advantage of ISR is having the flexibility to choose which pages are gen ...@@ -19,7 +19,7 @@ The big advantage of ISR is having the flexibility to choose which pages are gen
## Using ISR to fetch data from a blog ## Using ISR to fetch data from a blog
To use ISR add the `revalidate` prop to `getStaticProps`: To use ISR, add the `revalidate` prop to `getStaticProps`:
```jsx ```jsx
function Blog({ posts }) { function Blog({ posts }) {
...@@ -76,12 +76,42 @@ When a request is made to a page that was pre-rendered at build time, it will in ...@@ -76,12 +76,42 @@ When a request is made to a page that was pre-rendered at build time, it will in
- Any requests to the page after the initial request and before 10 seconds are also cached and instantaneous. - Any requests to the page after the initial request and before 10 seconds are also cached and instantaneous.
- After the 10-second window, the next request will still show the cached (stale) page - After the 10-second window, the next request will still show the cached (stale) page
- Next.js triggers a regeneration of the page in the background. - Next.js triggers a regeneration of the page in the background.
- Once the page has been successfully generated, Next.js will invalidate the cache and show the updated page. If the background regeneration fails, the old page would still be unaltered. - Once the page generates successfully, Next.js will invalidate the cache and show the updated page. If the background regeneration fails, the old page would still be unaltered.
When a request is made to a path that hasn’t been generated, Next.js will server-render the page on the first request. Future requests will serve the static file from the cache. When a request is made to a path that hasn’t been generated, Next.js will server-render the page on the first request. Future requests will serve the static file from the cache. ISR on Vercel [persists the cache globally and handles rollbacks](https://vercel.com/docs/concepts/next.js/incremental-static-regeneration).
[Incremental Static Regeneration](https://vercel.com/docs/concepts/next.js/incremental-static-regeneration) covers how to persist the cache globally and handle rollbacks. [Incremental Static Regeneration](https://vercel.com/docs/concepts/next.js/incremental-static-regeneration) covers how to persist the cache globally and handle rollbacks.
## Error Handling and Revalidation
If there is an error inside `getStaticProps` when handling background regeneration, or you manually throw an error, the last successfully generated page will continue to show. On the next subsequent request, Next.js will retry calling `getStaticProps`.
```jsx
export async function getStaticProps() {
// If this request throws an uncaught error, Next.js will
// not invalidate the currently shown page and
// retry getStaticProps on the next request.
const res = await fetch('https://.../posts')
const posts = await res.json()
if (!res.ok) {
// If there is a server error, you might want to
// throw an error instead of returning so that the cache is not updated
// until the next successful request.
throw new Error(`Failed to fetch posts, received status ${res.status}`)
}
// If the request was successful, return the posts
// and revalidate every 10 seconds.
return {
props: {
posts,
},
revalidate: 10,
}
}
```
## Examples ## Examples
- [**E-commerce Demo**](https://nextjs.org/commerce) – Next.js Commerce is an all-in-one starter kit for high-performance e-commerce sites. - [**E-commerce Demo**](https://nextjs.org/commerce) – Next.js Commerce is an all-in-one starter kit for high-performance e-commerce sites.
......
...@@ -8,7 +8,9 @@ SWC requires a binary be downloaded that is compatible specific to your system. ...@@ -8,7 +8,9 @@ SWC requires a binary be downloaded that is compatible specific to your system.
#### Possible Ways to Fix It #### Possible Ways to Fix It
You might need to allow optional packages to be installed by your package manager (remove `--no-optional` flag) for the package to download correctly. When on an M1 Mac and switching from a Node.js version without M1 support e.g. v14 to a version with e.g. v16, you may need a different swc dependency which can require re-installing `node_modules` (`npm i --force` or `yarn install --force`).
Alternatively, you might need to allow optional packages to be installed by your package manager (remove `--no-optional` flag) for the package to download correctly.
If SWC continues to fail to load you can opt-out by disabling `swcMinify` in your `next.config.js` or by adding a `.babelrc` to your project with the following content: If SWC continues to fail to load you can opt-out by disabling `swcMinify` in your `next.config.js` or by adding a `.babelrc` to your project with the following content:
......
...@@ -16,5 +16,5 @@ ...@@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/" "registry": "https://registry.npmjs.org/"
} }
}, },
"version": "12.0.11-canary.15" "version": "12.0.11-canary.17"
} }
{ {
"name": "create-next-app", "name": "create-next-app",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"keywords": [ "keywords": [
"react", "react",
"next", "next",
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
.pnpm-debug.log** .pnpm-debug.log*
# local env files # local env files
.env.local .env.local
......
{ {
"name": "eslint-config-next", "name": "eslint-config-next",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"description": "ESLint configuration used by NextJS.", "description": "ESLint configuration used by NextJS.",
"main": "index.js", "main": "index.js",
"license": "MIT", "license": "MIT",
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
"directory": "packages/eslint-config-next" "directory": "packages/eslint-config-next"
}, },
"dependencies": { "dependencies": {
"@next/eslint-plugin-next": "12.0.11-canary.15", "@next/eslint-plugin-next": "12.0.11-canary.17",
"@rushstack/eslint-patch": "^1.0.8", "@rushstack/eslint-patch": "^1.0.8",
"@typescript-eslint/parser": "^5.0.0", "@typescript-eslint/parser": "^5.0.0",
"eslint-import-resolver-node": "^0.3.4", "eslint-import-resolver-node": "^0.3.4",
......
{ {
"name": "@next/eslint-plugin-next", "name": "@next/eslint-plugin-next",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"description": "ESLint plugin for NextJS.", "description": "ESLint plugin for NextJS.",
"main": "lib/index.js", "main": "lib/index.js",
"license": "MIT", "license": "MIT",
......
{ {
"name": "@next/bundle-analyzer", "name": "@next/bundle-analyzer",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"main": "index.js", "main": "index.js",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
......
{ {
"name": "@next/codemod", "name": "@next/codemod",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"chalk": "4.1.0", "chalk": "4.1.0",
......
{ {
"name": "@next/env", "name": "@next/env",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"keywords": [ "keywords": [
"react", "react",
"next", "next",
......
{ {
"name": "@next/mdx", "name": "@next/mdx",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"main": "index.js", "main": "index.js",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
......
{ {
"name": "@next/plugin-storybook", "name": "@next/plugin-storybook",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"repository": { "repository": {
"url": "vercel/next.js", "url": "vercel/next.js",
"directory": "packages/next-plugin-storybook" "directory": "packages/next-plugin-storybook"
......
{ {
"name": "@next/polyfill-module", "name": "@next/polyfill-module",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)", "description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js", "main": "dist/polyfill-module.js",
"license": "MIT", "license": "MIT",
......
{ {
"name": "@next/polyfill-nomodule", "name": "@next/polyfill-nomodule",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"description": "A polyfill for non-dead, nomodule browsers.", "description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js", "main": "dist/polyfill-nomodule.js",
"license": "MIT", "license": "MIT",
......
This diff is collapsed.
...@@ -16,14 +16,14 @@ pathdiff = "0.2.0" ...@@ -16,14 +16,14 @@ pathdiff = "0.2.0"
serde = "1" serde = "1"
serde_json = "1" serde_json = "1"
styled_components = "0.14.0" styled_components = "0.14.0"
swc = "0.121.7" swc = "0.126.2"
swc_atoms = "0.2.7" swc_atoms = "0.2.7"
swc_common = { version = "0.17.0", features = ["concurrent", "sourcemap"] } swc_common = { version = "0.17.0", features = ["concurrent", "sourcemap"] }
swc_css = "0.46.0" swc_css = "0.85.0"
swc_ecma_loader = { version = "0.28.0", features = ["node", "lru"] } swc_ecma_loader = { version = "0.28.0", features = ["node", "lru"] }
swc_ecmascript = { version = "0.112.6", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] } swc_ecmascript = { version = "0.114.2", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.1" swc_node_base = "0.5.1"
swc_stylis = "0.43.0" swc_stylis = "0.81.0"
tracing = {version = "0.1.28", features = ["release_max_level_off"]} tracing = {version = "0.1.28", features = ["release_max_level_off"]}
regex = "1.5" regex = "1.5"
......
...@@ -21,7 +21,7 @@ use tracing::{debug, trace}; ...@@ -21,7 +21,7 @@ use tracing::{debug, trace};
use super::{hash_string, string_literal_expr, LocalStyle}; use super::{hash_string, string_literal_expr, LocalStyle};
pub fn transform_css( pub fn transform_css(
cm: Arc<SourceMap>, _cm: Arc<SourceMap>,
style_info: &LocalStyle, style_info: &LocalStyle,
is_global: bool, is_global: bool,
class_name: &Option<String>, class_name: &Option<String>,
...@@ -33,7 +33,6 @@ pub fn transform_css( ...@@ -33,7 +33,6 @@ pub fn transform_css(
style_info.css_span.lo, style_info.css_span.lo,
style_info.css_span.hi, style_info.css_span.hi,
ParserConfig { ParserConfig {
parse_values: false,
allow_wrong_line_comments: true, allow_wrong_line_comments: true,
}, },
// We ignore errors because we inject placeholders for expressions which is // We ignore errors because we inject placeholders for expressions which is
...@@ -62,7 +61,6 @@ pub fn transform_css( ...@@ -62,7 +61,6 @@ pub fn transform_css(
}; };
// ? Do we need to support optionally prefixing? // ? Do we need to support optionally prefixing?
ss.visit_mut_with(&mut prefixer()); ss.visit_mut_with(&mut prefixer());
ss.visit_mut_with(&mut CssPlaceholderFixer { cm });
ss.visit_mut_with(&mut Namespacer { ss.visit_mut_with(&mut Namespacer {
class_name: match class_name { class_name: match class_name {
Some(s) => s.clone(), Some(s) => s.clone(),
...@@ -131,48 +129,6 @@ fn read_number(s: &str) -> (usize, usize) { ...@@ -131,48 +129,6 @@ fn read_number(s: &str) -> (usize, usize) {
unreachable!("read_number(`{}`) is invalid because it is empty", s) unreachable!("read_number(`{}`) is invalid because it is empty", s)
} }
/// This fixes invalid css which is created from interpolated expressions.
///
/// `__styled-jsx-placeholder-` is handled at here.
struct CssPlaceholderFixer {
cm: Arc<SourceMap>,
}
impl VisitMut for CssPlaceholderFixer {
fn visit_mut_media_query(&mut self, q: &mut MediaQuery) {
q.visit_mut_children_with(self);
match q {
MediaQuery::Ident(q) => {
if !q.raw.starts_with("__styled-jsx-placeholder-") {
return;
}
// We need to support both of @media ($breakPoint) {} and @media $queryString {}
// This is complex because @media (__styled-jsx-placeholder-0__) {} is valid
// while @media __styled-jsx-placeholder-0__ {} is not
//
// So we check original source code to determine if we should inject
// parenthesis.
// TODO(kdy1): Avoid allocation.
// To remove allocation, we should patch swc_common to provide a way to get
// source code without allocation.
//
//
// We need
//
// fn with_source_code (self: &mut Self, f: impl FnOnce(&str) -> Ret) -> _ {}
if let Ok(source) = self.cm.span_to_snippet(q.span) {
if source.starts_with('(') {
q.raw = format!("({})", &q.value).into();
}
}
}
_ => {}
}
}
}
struct Namespacer { struct Namespacer {
class_name: String, class_name: String,
is_global: bool, is_global: bool,
...@@ -229,9 +185,7 @@ impl VisitMut for Namespacer { ...@@ -229,9 +185,7 @@ impl VisitMut for Namespacer {
} }
ComplexSelectorChildren::Combinator(v) => match v.value { ComplexSelectorChildren::Combinator(v) => match v.value {
CombinatorValue::Descendant => {} CombinatorValue::Descendant => {}
CombinatorValue::NextSibling _ => {
| CombinatorValue::Child
| CombinatorValue::LaterSibling => {
combinator = Some(v.clone()); combinator = Some(v.clone());
new_selectors.push(sel); new_selectors.push(sel);
...@@ -251,23 +205,22 @@ impl Namespacer { ...@@ -251,23 +205,22 @@ impl Namespacer {
) -> Result<Vec<ComplexSelectorChildren>, Error> { ) -> Result<Vec<ComplexSelectorChildren>, Error> {
let mut pseudo_index = None; let mut pseudo_index = None;
let empty_tokens = Tokens { let empty_tokens = vec![];
span: node.span,
tokens: vec![],
};
let mut arg_tokens; let mut arg_tokens;
for (i, selector) in node.subclass_selectors.iter().enumerate() { for (i, selector) in node.subclass_selectors.iter().enumerate() {
let (name, args) = match selector { let (name, args) = match selector {
SubclassSelector::PseudoClass(PseudoClassSelector { name, children, .. }) => { SubclassSelector::PseudoClass(PseudoClassSelector { name, children, .. }) => {
match children { arg_tokens = children
Some(PseudoSelectorChildren::Nth(v)) => { .iter()
arg_tokens = nth_to_tokens(&v); .flatten()
(name, &arg_tokens) .flat_map(|v| match v {
} PseudoSelectorChildren::Nth(v) => nth_to_tokens(v).tokens,
Some(PseudoSelectorChildren::Tokens(v)) => (name, v), PseudoSelectorChildren::PreservedToken(v) => vec![v.clone()],
None => (name, &empty_tokens), })
} .collect::<Vec<_>>();
(name, &arg_tokens)
} }
SubclassSelector::PseudoElement(PseudoElementSelector { SubclassSelector::PseudoElement(PseudoElementSelector {
name, children, .. name, children, ..
...@@ -280,9 +233,19 @@ impl Namespacer { ...@@ -280,9 +233,19 @@ impl Namespacer {
// One off global selector // One off global selector
if &name.value == "global" { if &name.value == "global" {
let args = args.clone();
let mut args = {
let lo = args.first().map(|v| v.span.lo).unwrap_or(BytePos(0));
let hi = args.last().map(|v| v.span.hi).unwrap_or(BytePos(0));
Tokens {
span: Span::new(lo, hi, Default::default()),
tokens: args,
}
};
let block_tokens = get_block_tokens(&args); let block_tokens = get_block_tokens(&args);
let mut front_tokens = get_front_selector_tokens(&args); let mut front_tokens = get_front_selector_tokens(&args);
let mut args = args.clone();
front_tokens.extend(args.tokens); front_tokens.extend(args.tokens);
front_tokens.extend(block_tokens); front_tokens.extend(block_tokens);
args.tokens = front_tokens; args.tokens = front_tokens;
...@@ -291,7 +254,6 @@ impl Namespacer { ...@@ -291,7 +254,6 @@ impl Namespacer {
let x: ComplexSelector = parse_tokens( let x: ComplexSelector = parse_tokens(
&args, &args,
ParserConfig { ParserConfig {
parse_values: false,
allow_wrong_line_comments: true, allow_wrong_line_comments: true,
}, },
// TODO(kdy1): We might be able to report syntax errors. // TODO(kdy1): We might be able to report syntax errors.
...@@ -522,7 +484,6 @@ fn nth_to_tokens(nth: &Nth) -> Tokens { ...@@ -522,7 +484,6 @@ fn nth_to_tokens(nth: &Nth) -> Tokens {
let mut lexer = swc_css::parser::lexer::Lexer::new( let mut lexer = swc_css::parser::lexer::Lexer::new(
StringInput::new(&s, nth.span.lo, nth.span.hi), StringInput::new(&s, nth.span.lo, nth.span.hi),
ParserConfig { ParserConfig {
parse_values: false,
allow_wrong_line_comments: true, allow_wrong_line_comments: true,
..Default::default() ..Default::default()
}, },
......
import _JSXStyle from "styled-jsx/style"; import _JSXStyle from "styled-jsx/style";
export default { export default {
styles: <_JSXStyle id={"71f03d42ea0ec6"}>{".container.jsx-71f03d42ea0ec6{background:#000;\ncolor:white;\nfont-weight:700;\nheight:100px}"}</_JSXStyle>, styles: <_JSXStyle id={"71f03d42ea0ec6"}>{".container.jsx-71f03d42ea0ec6{background:#000;color:white;font-weight:700;height:100px}"}</_JSXStyle>,
className: "jsx-71f03d42ea0ec6" className: "jsx-71f03d42ea0ec6"
}; };
\ No newline at end of file
...@@ -4,7 +4,7 @@ function NavigationItem({ active , className }) { ...@@ -4,7 +4,7 @@ function NavigationItem({ active , className }) {
active active
}, className, "navigation-item") || "")}> }, className, "navigation-item") || "")}>
<_JSXStyle id={"2342aae4628612c6"}>{".navigation-item.jsx-2342aae4628612c6 a::after{content:attr(data-text);\ncontent: attr(data-text) / ''}"}</_JSXStyle> <_JSXStyle id={"2342aae4628612c6"}>{".navigation-item.jsx-2342aae4628612c6 a::after{content:attr(data-text);content:attr(data-text)/\"\"}"}</_JSXStyle>
</span>; </span>;
} }
......
...@@ -51,8 +51,7 @@ export default (({ display })=><div className={"jsx-1ada4ad4dab7822f " + _JSXSt ...@@ -51,8 +51,7 @@ export default (({ display })=><div className={"jsx-1ada4ad4dab7822f " + _JSXSt
] ]
])}>test</p> ])}>test</p>
<_JSXStyle id={"6116059e04f3bff7"}>{`p.${color}.jsx-1ada4ad4dab7822f{color:${otherColor}; <_JSXStyle id={"6116059e04f3bff7"}>{`p.${color}.jsx-1ada4ad4dab7822f{color:${otherColor};display:${obj.display}}`}</_JSXStyle>
display:${obj.display}}`}</_JSXStyle>
<_JSXStyle id={"94239b6d6b42c9b5"}>{"p.jsx-1ada4ad4dab7822f{color:red}"}</_JSXStyle> <_JSXStyle id={"94239b6d6b42c9b5"}>{"p.jsx-1ada4ad4dab7822f{color:red}"}</_JSXStyle>
...@@ -74,16 +73,11 @@ display:${obj.display}}`}</_JSXStyle> ...@@ -74,16 +73,11 @@ display:${obj.display}}`}</_JSXStyle>
darken(color) + 2 darken(color) + 2
]}>{`p.__jsx-style-dynamic-selector{color:${darken(color) + 2}}`}</_JSXStyle> ]}>{`p.__jsx-style-dynamic-selector{color:${darken(color) + 2}}`}</_JSXStyle>
<_JSXStyle id={"4e4be2da62837c76"}>{`@media (min-width:${mediumScreen}) {p.jsx-1ada4ad4dab7822f{color:green} <_JSXStyle id={"4e4be2da62837c76"}>{`@media(min-width:${mediumScreen}){p.jsx-1ada4ad4dab7822f{color:green}p.jsx-1ada4ad4dab7822f{color:${`red`}}}p.jsx-1ada4ad4dab7822f{color:red}`}</_JSXStyle>
p.jsx-1ada4ad4dab7822f{color:${`red`}}}
p.jsx-1ada4ad4dab7822f{color:red}`}</_JSXStyle>
<_JSXStyle id={"27040f0829fb73d4"}>{`p.jsx-1ada4ad4dab7822f{-webkit-animation-duration:${animationDuration}; <_JSXStyle id={"27040f0829fb73d4"}>{`p.jsx-1ada4ad4dab7822f{-webkit-animation-duration:${animationDuration};animation-duration:${animationDuration}}`}</_JSXStyle>
animation-duration:${animationDuration}}`}</_JSXStyle>
<_JSXStyle id={"3e72d735e703a530"}>{`p.jsx-1ada4ad4dab7822f{-webkit-animation:${animationDuration} forwards ${animationName}; <_JSXStyle id={"3e72d735e703a530"}>{`p.jsx-1ada4ad4dab7822f{-webkit-animation:${animationDuration} forwards ${animationName};animation:${animationDuration} forwards ${animationName}}div.jsx-1ada4ad4dab7822f{background:${color}}`}</_JSXStyle>
animation:${animationDuration} forwards ${animationName}}
div.jsx-1ada4ad4dab7822f{background:${color}}`}</_JSXStyle>
......
...@@ -14,7 +14,7 @@ export default (()=><div className={"jsx-bee92b62eadf8a14 " + `jsx-${styles.__ha ...@@ -14,7 +14,7 @@ export default (()=><div className={"jsx-bee92b62eadf8a14 " + `jsx-${styles.__ha
<div className={"jsx-bee92b62eadf8a14 " + `jsx-${styles.__hash} jsx-${styles3.__hash}`}>woot</div> <div className={"jsx-bee92b62eadf8a14 " + `jsx-${styles.__hash} jsx-${styles3.__hash}`}>woot</div>
<_JSXStyle id={"bee92b62eadf8a14"}>{"p.jsx-bee92b62eadf8a14{color:red}\ndiv.jsx-bee92b62eadf8a14{color:green}"}</_JSXStyle> <_JSXStyle id={"bee92b62eadf8a14"}>{"p.jsx-bee92b62eadf8a14{color:red}div.jsx-bee92b62eadf8a14{color:green}"}</_JSXStyle>
<_JSXStyle id={styles.__hash}>{styles}</_JSXStyle> <_JSXStyle id={styles.__hash}>{styles}</_JSXStyle>
...@@ -30,7 +30,7 @@ export const Test = ()=><div className={"jsx-bee92b62eadf8a14 " + `jsx-${styles3 ...@@ -30,7 +30,7 @@ export const Test = ()=><div className={"jsx-bee92b62eadf8a14 " + `jsx-${styles3
<div className={"jsx-bee92b62eadf8a14 " + `jsx-${styles3.__hash}`}>woot</div> <div className={"jsx-bee92b62eadf8a14 " + `jsx-${styles3.__hash}`}>woot</div>
<_JSXStyle id={"bee92b62eadf8a14"}>{"p.jsx-bee92b62eadf8a14{color:red}\ndiv.jsx-bee92b62eadf8a14{color:green}"}</_JSXStyle> <_JSXStyle id={"bee92b62eadf8a14"}>{"p.jsx-bee92b62eadf8a14{color:red}div.jsx-bee92b62eadf8a14{color:green}"}</_JSXStyle>
</div> </div>
; ;
...@@ -28,7 +28,7 @@ export default (()=><> ...@@ -28,7 +28,7 @@ export default (()=><>
</> </>
<_JSXStyle id={"6dd5f97e085c0297"}>{"p.jsx-6dd5f97e085c0297{color:cyan}\n.foo.jsx-6dd5f97e085c0297{font-size:18px;\ncolor:hotpink}\n#head.jsx-6dd5f97e085c0297{text-decoration:underline}"}</_JSXStyle> <_JSXStyle id={"6dd5f97e085c0297"}>{"p.jsx-6dd5f97e085c0297{color:cyan}.foo.jsx-6dd5f97e085c0297{font-size:18px;color:hotpink}#head.jsx-6dd5f97e085c0297{text-decoration:underline}"}</_JSXStyle>
</> </>
); );
......
import _JSXStyle from "styled-jsx/style"; import _JSXStyle from "styled-jsx/style";
const Test = ()=><div className={"jsx-d47d6adadf14e957"}> const Test = ()=><div className={"jsx-d47d6adadf14e957"}>
<_JSXStyle id={"d47d6adadf14e957"}>{"body{color:red}\n:hover{color:red;\ndisplay:-webkit-box;\ndisplay:-webkit-flex;\ndisplay:-ms-flexbox;\ndisplay:flex;\n-webkit-animation:foo 1s ease-out;\nanimation:foo 1s ease-out}\ndiv a{display:none}\n[data-test]>div{color:red}"}</_JSXStyle> <_JSXStyle id={"d47d6adadf14e957"}>{"body{color:red}:hover{color:red;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-animation:foo 1s ease-out;animation:foo 1s ease-out}div a{display:none}[data-test]>div{color:red}"}</_JSXStyle>
</div> </div>
; ;
......
...@@ -10,7 +10,7 @@ export default (({ breakPoint })=><div className={_JSXStyle.dynamic([ ...@@ -10,7 +10,7 @@ export default (({ breakPoint })=><div className={_JSXStyle.dynamic([
<_JSXStyle id={"42a6f8ca08e1a043"} dynamic={[ <_JSXStyle id={"42a6f8ca08e1a043"} dynamic={[
breakPoint breakPoint
]}>{`@media (${breakPoint}) {}`}</_JSXStyle> ]}>{`@media(${breakPoint}){}`}</_JSXStyle>
</div> </div>
); );
...@@ -6,7 +6,7 @@ export default function IndexPage() { ...@@ -6,7 +6,7 @@ export default function IndexPage() {
<_JSXStyle id={"bbdada4ef17d18ef"}>{"@supports (display:flex) {h1{color:hotpink}}"}</_JSXStyle> <_JSXStyle id={"bbdada4ef17d18ef"}>{"@supports(display:flex){h1{color:hotpink}}"}</_JSXStyle>
</div>; </div>;
}; };
...@@ -36,10 +36,7 @@ export default class { ...@@ -36,10 +36,7 @@ export default class {
Typography.base.size.mediumPlus, Typography.base.size.mediumPlus,
Target.largePlus, Target.largePlus,
Typography.base.size.largePlus Typography.base.size.largePlus
]}>{`html{font-size:${Typography.base.size.default}; ]}>{`html{font-size:${Typography.base.size.default};line-height:${Typography.base.lineHeight}}@media ${Target.mediumPlus}{html{font-size:${Typography.base.size.mediumPlus}}}@media ${Target.largePlus}{html{font-size:${Typography.base.size.largePlus}}}`}</_JSXStyle>
line-height:${Typography.base.lineHeight}}
@media ${Target.mediumPlus} {html{font-size:${Typography.base.size.mediumPlus}}}
@media ${Target.largePlus} {html{font-size:${Typography.base.size.largePlus}}}`}</_JSXStyle>
</div>; </div>;
} }
......
...@@ -11,21 +11,18 @@ export const uh = bar; ...@@ -11,21 +11,18 @@ export const uh = bar;
export const foo = new String(`div.jsx-945eaa83250ed332{color:${color}}`); export const foo = new String(`div.jsx-945eaa83250ed332{color:${color}}`);
foo.__hash = "945eaa83250ed332"; foo.__hash = "945eaa83250ed332";
({ ({
styles: <_JSXStyle id={"c107a919a5b2943d"}>{`div.jsx-c107a919a5b2943d{color:${colors.green.light}} styles: <_JSXStyle id={"c107a919a5b2943d"}>{`div.jsx-c107a919a5b2943d{color:${colors.green.light}}a.jsx-c107a919a5b2943d{color:red}`}</_JSXStyle>,
a.jsx-c107a919a5b2943d{color:red}`}</_JSXStyle>,
className: "jsx-c107a919a5b2943d" className: "jsx-c107a919a5b2943d"
}); });
const b = { const b = {
styles: <_JSXStyle id={"c107a919a5b2943d"}>{`div.jsx-c107a919a5b2943d{color:${colors.green.light}} styles: <_JSXStyle id={"c107a919a5b2943d"}>{`div.jsx-c107a919a5b2943d{color:${colors.green.light}}a.jsx-c107a919a5b2943d{color:red}`}</_JSXStyle>,
a.jsx-c107a919a5b2943d{color:red}`}</_JSXStyle>,
className: "jsx-c107a919a5b2943d" className: "jsx-c107a919a5b2943d"
}; };
const dynamic = (colors1)=>{ const dynamic = (colors1)=>{
const b = { const b = {
styles: <_JSXStyle id={"60132422fc87f1d1"} dynamic={[ styles: <_JSXStyle id={"60132422fc87f1d1"} dynamic={[
colors1.green.light colors1.green.light
]}>{`div.__jsx-style-dynamic-selector{color:${colors1.green.light}} ]}>{`div.__jsx-style-dynamic-selector{color:${colors1.green.light}}a.__jsx-style-dynamic-selector{color:red}`}</_JSXStyle>,
a.__jsx-style-dynamic-selector{color:red}`}</_JSXStyle>,
className: _JSXStyle.dynamic([ className: _JSXStyle.dynamic([
[ [
"60132422fc87f1d1", "60132422fc87f1d1",
...@@ -37,7 +34,6 @@ a.__jsx-style-dynamic-selector{color:red}`}</_JSXStyle>, ...@@ -37,7 +34,6 @@ a.__jsx-style-dynamic-selector{color:red}`}</_JSXStyle>,
}; };
}; };
export default { export default {
styles: <_JSXStyle id={"e5da8dd7ff5c7f39"}>{`div.jsx-e5da8dd7ff5c7f39{font-size:3em} styles: <_JSXStyle id={"e5da8dd7ff5c7f39"}>{`div.jsx-e5da8dd7ff5c7f39{font-size:3em}p.jsx-e5da8dd7ff5c7f39{color:${color}}`}</_JSXStyle>,
p.jsx-e5da8dd7ff5c7f39{color:${color}}`}</_JSXStyle>,
className: "jsx-e5da8dd7ff5c7f39" className: "jsx-e5da8dd7ff5c7f39"
}; };
...@@ -43,21 +43,7 @@ export const Red = ({ Component ="button" })=>{ ...@@ -43,21 +43,7 @@ export const Red = ({ Component ="button" })=>{
e13, e13,
e14, e14,
e15 e15
]}>{`.button.__jsx-style-dynamic-selector{--button-1: ${e1}; ]}>{`.button.__jsx-style-dynamic-selector{--button-1:${e1};--button-2:${e2};--button-3:${e3};--button-4:${e4};--button-5:${e5};--button-6:${e6};--button-7:${e7};--button-8:${e8};--button-9:${e9};--button-10:${e10};--button-11:${e11};--button-12:${e12};--button-13:${e13};--button-14:${e14};--button-15:${e15}}`}</_JSXStyle>
--button-2: ${e2};
--button-3: ${e3};
--button-4: ${e4};
--button-5: ${e5};
--button-6: ${e6};
--button-7: ${e7};
--button-8: ${e8};
--button-9: ${e9};
--button-10: ${e10};
--button-11: ${e11};
--button-12: ${e12};
--button-13: ${e13};
--button-14: ${e14};
--button-15: ${e15}}`}</_JSXStyle>
</Component>; </Component>;
}; };
...@@ -5,7 +5,7 @@ export default class { ...@@ -5,7 +5,7 @@ export default class {
<p className={"jsx-1f6cef12199c3a8f"}>test</p> <p className={"jsx-1f6cef12199c3a8f"}>test</p>
<_JSXStyle id={"1f6cef12199c3a8f"}>{"p.jsx-1f6cef12199c3a8f{content:'`'}"}</_JSXStyle> <_JSXStyle id={"1f6cef12199c3a8f"}>{"p.jsx-1f6cef12199c3a8f{content:\"`\"}"}</_JSXStyle>
</div>; </div>;
} }
......
...@@ -11,8 +11,7 @@ export default function Home({ fontFamily }) { ...@@ -11,8 +11,7 @@ export default function Home({ fontFamily }) {
<_JSXStyle id={"f804e2f486b6ac13"} dynamic={[ <_JSXStyle id={"f804e2f486b6ac13"} dynamic={[
fontFamily fontFamily
]}>{`body{font-family:${fontFamily}} ]}>{`body{font-family:${fontFamily}}code:before,code:after{content:"\`"}`}</_JSXStyle>
code:before, code:after{content:'\`'}`}</_JSXStyle>
</div>; </div>;
}; };
...@@ -21,7 +21,7 @@ export default class { ...@@ -21,7 +21,7 @@ export default class {
<_JSXStyle id={"e359801ddd3b3cb6"} dynamic={[ <_JSXStyle id={"e359801ddd3b3cb6"} dynamic={[
inputSize ? "height: calc(2 * var(--a)) !important;" : "" inputSize ? "height: calc(2 * var(--a)) !important;" : ""
]}>{`@media only screen {a.__jsx-style-dynamic-selector{${inputSize ? "height: calc(2 * var(--a)) !important;" : ""} ]}>{`@media only screen{a.__jsx-style-dynamic-selector{${inputSize ? "height: calc(2 * var(--a)) !important;" : ""}
}}`}</_JSXStyle> }}`}</_JSXStyle>
</div>; </div>;
......
...@@ -27,8 +27,7 @@ export default class { ...@@ -27,8 +27,7 @@ export default class {
a[b], a[b],
-1 * (c || 0), -1 * (c || 0),
d d
]}>{`.a:hover .b.__jsx-style-dynamic-selector{a:${a[b]}px!important; ]}>{`.a:hover .b.__jsx-style-dynamic-selector{a:${a[b]}px!important;b:translate3d(0,${-1 * (c || 0)}px,-${d}px)scale(1)!important}`}</_JSXStyle>
b:translate3d(0, ${-1 * (c || 0)}px, -${d}px) scale(1)!important}`}</_JSXStyle>
</div>; </div>;
} }
......
...@@ -21,7 +21,7 @@ export default class { ...@@ -21,7 +21,7 @@ export default class {
<_JSXStyle id={"4ca4ef3595473f53"} dynamic={[ <_JSXStyle id={"4ca4ef3595473f53"} dynamic={[
a a
]}>{`@media only screen {a.__jsx-style-dynamic-selector{color:${a}}}`}</_JSXStyle> ]}>{`@media only screen{a.__jsx-style-dynamic-selector{color:${a}}}`}</_JSXStyle>
</div>; </div>;
} }
......
...@@ -24,9 +24,7 @@ export default class { ...@@ -24,9 +24,7 @@ export default class {
<_JSXStyle id={"97886c1e9511aafa"} dynamic={[ <_JSXStyle id={"97886c1e9511aafa"} dynamic={[
a || "var(--c)", a || "var(--c)",
b || "inherit" b || "inherit"
]}>{`.a:hover .b.__jsx-style-dynamic-selector{display:inline-block; ]}>{`.a:hover .b.__jsx-style-dynamic-selector{display:inline-block;padding:0 ${a || "var(--c)"};color:${b || "inherit"}}`}</_JSXStyle>
padding:0 ${a || "var(--c)"};
color:${b || "inherit"}}`}</_JSXStyle>
</div>; </div>;
} }
......
...@@ -24,8 +24,7 @@ export default class { ...@@ -24,8 +24,7 @@ export default class {
<_JSXStyle id={"bcc606c168bcd197"} dynamic={[ <_JSXStyle id={"bcc606c168bcd197"} dynamic={[
a ? "100%" : "200px", a ? "100%" : "200px",
b ? "0" : "8px 20px" b ? "0" : "8px 20px"
]}>{`.item.__jsx-style-dynamic-selector{max-width:${a ? "100%" : "200px"}; ]}>{`.item.__jsx-style-dynamic-selector{max-width:${a ? "100%" : "200px"};padding:${b ? "0" : "8px 20px"}}`}</_JSXStyle>
padding:${b ? "0" : "8px 20px"}}`}</_JSXStyle>
</div>; </div>;
} }
......
...@@ -3,7 +3,7 @@ export default (()=><div className={"jsx-713499aa363d6373"}> ...@@ -3,7 +3,7 @@ export default (()=><div className={"jsx-713499aa363d6373"}>
<p className={"jsx-713499aa363d6373"}>test</p> <p className={"jsx-713499aa363d6373"}>test</p>
<_JSXStyle id={"713499aa363d6373"}>{"p.jsx-713499aa363d6373 a.jsx-713499aa363d6373 span.jsx-713499aa363d6373{color:red}\np.jsx-713499aa363d6373 span{background:blue}\np.jsx-713499aa363d6373 a[title=\"'w ' ' t'\"].jsx-713499aa363d6373{margin:auto}\np.jsx-713499aa363d6373 span:not(.test){color:green}\np.jsx-713499aa363d6373, h1.jsx-713499aa363d6373{color:blue;\n-webkit-animation:hahaha 3s ease forwards infinite;\nanimation:hahaha 3s ease forwards infinite;\n-webkit-animation-name:hahaha;\nanimation-name:hahaha;\nanimation-delay:100ms}\np.jsx-713499aa363d6373{-webkit-animation:hahaha 1s, hehehe 2s;\nanimation:hahaha 1s, hehehe 2s}\np.jsx-713499aa363d6373:hover{color:red}\np.jsx-713499aa363d6373::before{color:red}\n.jsx-713499aa363d6373:hover{color:red}\n.jsx-713499aa363d6373::before{color:red}\n.jsx-713499aa363d6373:hover p.jsx-713499aa363d6373{color:red}\np.jsx-713499aa363d6373+a.jsx-713499aa363d6373{color:red}\np.jsx-713499aa363d6373~a.jsx-713499aa363d6373{color:red}\np.jsx-713499aa363d6373>a.jsx-713499aa363d6373{color:red}\n@keyframes hahaha {from {top:0}to {top:100}}\n@keyframes hehehe {from {left:0}to {left:100}}\n@media (min-width:500px) {.test.jsx-713499aa363d6373{color:red}}\n.test.jsx-713499aa363d6373{display:block}\n.inline-flex.jsx-713499aa363d6373{display:-webkit-inline-box;\ndisplay:-webkit-inline-flex;\ndisplay:-ms-inline-flexbox;\ndisplay:inline-flex}\n.flex.jsx-713499aa363d6373{display:-webkit-box;\ndisplay:-webkit-flex;\ndisplay:-ms-flexbox;\ndisplay:flex}\n.test.jsx-713499aa363d6373{box-shadow:0 0 10px black, inset 0 0 5px black}\n.test[title=\",\"].jsx-713499aa363d6373{display:inline-block}\n.test.is-status.jsx-713499aa363d6373 .test.jsx-713499aa363d6373{color:red}\n.a-selector.jsx-713499aa363d6373:hover, .a-selector.jsx-713499aa363d6373:focus{outline:none}"}</_JSXStyle> <_JSXStyle id={"713499aa363d6373"}>{"p.jsx-713499aa363d6373 a.jsx-713499aa363d6373 span.jsx-713499aa363d6373{color:red}p.jsx-713499aa363d6373 span{background:blue}p.jsx-713499aa363d6373 a[title=\"'w ' ' t'\"].jsx-713499aa363d6373{margin:auto}p.jsx-713499aa363d6373 span:not(.test){color:green}p.jsx-713499aa363d6373,h1.jsx-713499aa363d6373{color:blue;-webkit-animation:hahaha 3s ease forwards infinite;animation:hahaha 3s ease forwards infinite;-webkit-animation-name:hahaha;animation-name:hahaha;animation-delay:100ms}p.jsx-713499aa363d6373{-webkit-animation:hahaha 1s,hehehe 2s;animation:hahaha 1s,hehehe 2s}p.jsx-713499aa363d6373:hover{color:red}p.jsx-713499aa363d6373::before{color:red}.jsx-713499aa363d6373:hover{color:red}.jsx-713499aa363d6373::before{color:red}.jsx-713499aa363d6373:hover p.jsx-713499aa363d6373{color:red}p.jsx-713499aa363d6373+a.jsx-713499aa363d6373{color:red}p.jsx-713499aa363d6373~a.jsx-713499aa363d6373{color:red}p.jsx-713499aa363d6373>a.jsx-713499aa363d6373{color:red}@keyframes hahaha{from{top:0}to{top:100}}@keyframes hehehe{from{left:0}to{left:100}}@media(min-width:500px){.test.jsx-713499aa363d6373{color:red}}.test.jsx-713499aa363d6373{display:block}.inline-flex.jsx-713499aa363d6373{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex}.flex.jsx-713499aa363d6373{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex}.test.jsx-713499aa363d6373{box-shadow:0 0 10px black,inset 0 0 5px black}.test[title=\",\"].jsx-713499aa363d6373{display:inline-block}.test.is-status.jsx-713499aa363d6373 .test.jsx-713499aa363d6373{color:red}.a-selector.jsx-713499aa363d6373:hover,.a-selector.jsx-713499aa363d6373:focus{outline:none}"}</_JSXStyle>
</div> </div>
); );
...@@ -3,7 +3,7 @@ export default (()=><div className={"jsx-53fd644ab080300c"}> ...@@ -3,7 +3,7 @@ export default (()=><div className={"jsx-53fd644ab080300c"}>
<p className={"jsx-53fd644ab080300c"}>test</p> <p className={"jsx-53fd644ab080300c"}>test</p>
<_JSXStyle id={"53fd644ab080300c"}>{"html.jsx-53fd644ab080300c{background-image:linear-gradient(0deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.8)), url(/static/background.svg)}\np{color:blue}\np{color:blue}\np, a.jsx-53fd644ab080300c{color:blue}\n.foo+a{color:red}\nbody{font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif}"}</_JSXStyle> <_JSXStyle id={"53fd644ab080300c"}>{"html.jsx-53fd644ab080300c{background-image:linear-gradient(0deg,rgba(255,255,255,.8),rgba(255,255,255,.8)),url(/static/background.svg)}p{color:blue}p{color:blue}p,a.jsx-53fd644ab080300c{color:blue}.foo+a{color:red}body{font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",Helvetica,Arial,sans-serif}"}</_JSXStyle>
</div> </div>
); );
...@@ -3,7 +3,7 @@ export default (()=><div className={"jsx-1f7963ae04c6466a"}> ...@@ -3,7 +3,7 @@ export default (()=><div className={"jsx-1f7963ae04c6466a"}>
<p className={"jsx-1f7963ae04c6466a"}>test</p> <p className={"jsx-1f7963ae04c6466a"}>test</p>
<_JSXStyle id={"1f7963ae04c6466a"}>{"@media (min-width:1px) and (max-width:768px) {[class*='grid__col--'].jsx-1f7963ae04c6466a{margin-top:12px;\nmargin-bottom:12px}}\n@media (max-width:64em) {.test.jsx-1f7963ae04c6466a{margin-bottom:1em}\n@supports (-moz-appearance:none) and (display:contents) {.test.jsx-1f7963ae04c6466a{margin-bottom:2rem}}}"}</_JSXStyle> <_JSXStyle id={"1f7963ae04c6466a"}>{"@media(min-width:1px)and (max-width:768px){[class*=\"grid__col--\"].jsx-1f7963ae04c6466a{margin-top:12px;margin-bottom:12px}}@media(max-width:64em){.test.jsx-1f7963ae04c6466a{margin-bottom:1em}@supports(-moz-appearance:none)and (display:contents){.test.jsx-1f7963ae04c6466a{margin-bottom:2rem}}}"}</_JSXStyle>
</div> </div>
); );
...@@ -3,7 +3,7 @@ export default (()=><div className={"jsx-1a19bb4817c105dd"}> ...@@ -3,7 +3,7 @@ export default (()=><div className={"jsx-1a19bb4817c105dd"}>
<p className={"jsx-1a19bb4817c105dd"}>test</p> <p className={"jsx-1a19bb4817c105dd"}>test</p>
<_JSXStyle id={"1a19bb4817c105dd"}>{"p.jsx-1a19bb4817c105dd{color:red}\np.jsx-1a19bb4817c105dd{color:red}\n*.jsx-1a19bb4817c105dd{color:blue}\n[href=\"woot\"].jsx-1a19bb4817c105dd{color:red}"}</_JSXStyle> <_JSXStyle id={"1a19bb4817c105dd"}>{"p.jsx-1a19bb4817c105dd{color:red}p.jsx-1a19bb4817c105dd{color:red}*.jsx-1a19bb4817c105dd{color:blue}[href=\"woot\"].jsx-1a19bb4817c105dd{color:red}"}</_JSXStyle>
</div> </div>
); );
...@@ -3,7 +3,7 @@ export default (()=><div className={"jsx-768337a97aceabd1"}> ...@@ -3,7 +3,7 @@ export default (()=><div className={"jsx-768337a97aceabd1"}>
<p className={"jsx-768337a97aceabd1"}>test</p> <p className={"jsx-768337a97aceabd1"}>test</p>
<_JSXStyle id={"768337a97aceabd1"}>{"html.jsx-768337a97aceabd1{background-image:linear-gradient(0deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.8)), url(/static/background.svg)}\np{color:blue}\np{color:blue}\np, a.jsx-768337a97aceabd1{color:blue}\n.foo+a{color:red}\nbody{font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif}\np.jsx-768337a97aceabd1{color:red}\np.jsx-768337a97aceabd1{color:red}\n*.jsx-768337a97aceabd1{color:blue}\n[href=\"woot\"].jsx-768337a97aceabd1{color:red}\np.jsx-768337a97aceabd1 a.jsx-768337a97aceabd1 span.jsx-768337a97aceabd1{color:red}\np.jsx-768337a97aceabd1 span{background:blue}\np.jsx-768337a97aceabd1 a[title=\"'w ' ' t'\"].jsx-768337a97aceabd1{margin:auto}\np.jsx-768337a97aceabd1 span:not(.test){color:green}\np.jsx-768337a97aceabd1, h1.jsx-768337a97aceabd1{color:blue;\n-webkit-animation:hahaha 3s ease forwards infinite;\nanimation:hahaha 3s ease forwards infinite;\n-webkit-animation-name:hahaha;\nanimation-name:hahaha;\nanimation-delay:100ms}\np.jsx-768337a97aceabd1{-webkit-animation:hahaha 1s, hehehe 2s;\nanimation:hahaha 1s, hehehe 2s}\np.jsx-768337a97aceabd1:hover{color:red}\np.jsx-768337a97aceabd1::before{color:red}\n.jsx-768337a97aceabd1:hover{color:red}\n.jsx-768337a97aceabd1::before{color:red}\n.jsx-768337a97aceabd1:hover p.jsx-768337a97aceabd1{color:red}\np.jsx-768337a97aceabd1+a.jsx-768337a97aceabd1{color:red}\np.jsx-768337a97aceabd1~a.jsx-768337a97aceabd1{color:red}\np.jsx-768337a97aceabd1>a.jsx-768337a97aceabd1{color:red}\n@keyframes hahaha {from {top:0}to {top:100}}\n@keyframes hehehe {from {left:0}to {left:100}}\n@media (min-width:500px) {.test.jsx-768337a97aceabd1{color:red}}\n.test.jsx-768337a97aceabd1{display:block}\n.inline-flex.jsx-768337a97aceabd1{display:-webkit-inline-box;\ndisplay:-webkit-inline-flex;\ndisplay:-ms-inline-flexbox;\ndisplay:inline-flex}\n.flex.jsx-768337a97aceabd1{display:-webkit-box;\ndisplay:-webkit-flex;\ndisplay:-ms-flexbox;\ndisplay:flex}\n.test.jsx-768337a97aceabd1{box-shadow:0 0 10px black, inset 0 0 5px black}\n.test[title=\",\"].jsx-768337a97aceabd1{display:inline-block}\n.test.is-status.jsx-768337a97aceabd1 .test.jsx-768337a97aceabd1{color:red}\n.a-selector.jsx-768337a97aceabd1:hover, .a-selector.jsx-768337a97aceabd1:focus{outline:none}\n@media (min-width:1px) and (max-width:768px) {[class*='grid__col--'].jsx-768337a97aceabd1{margin-top:12px;\nmargin-bottom:12px}}\n@media (max-width:64em) {.test.jsx-768337a97aceabd1{margin-bottom:1em}\n@supports (-moz-appearance:none) and (display:contents) {.test.jsx-768337a97aceabd1{margin-bottom:2rem}}}"}</_JSXStyle> <_JSXStyle id={"768337a97aceabd1"}>{"html.jsx-768337a97aceabd1{background-image:linear-gradient(0deg,rgba(255,255,255,.8),rgba(255,255,255,.8)),url(/static/background.svg)}p{color:blue}p{color:blue}p,a.jsx-768337a97aceabd1{color:blue}.foo+a{color:red}body{font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",Helvetica,Arial,sans-serif}p.jsx-768337a97aceabd1{color:red}p.jsx-768337a97aceabd1{color:red}*.jsx-768337a97aceabd1{color:blue}[href=\"woot\"].jsx-768337a97aceabd1{color:red}p.jsx-768337a97aceabd1 a.jsx-768337a97aceabd1 span.jsx-768337a97aceabd1{color:red}p.jsx-768337a97aceabd1 span{background:blue}p.jsx-768337a97aceabd1 a[title=\"'w ' ' t'\"].jsx-768337a97aceabd1{margin:auto}p.jsx-768337a97aceabd1 span:not(.test){color:green}p.jsx-768337a97aceabd1,h1.jsx-768337a97aceabd1{color:blue;-webkit-animation:hahaha 3s ease forwards infinite;animation:hahaha 3s ease forwards infinite;-webkit-animation-name:hahaha;animation-name:hahaha;animation-delay:100ms}p.jsx-768337a97aceabd1{-webkit-animation:hahaha 1s,hehehe 2s;animation:hahaha 1s,hehehe 2s}p.jsx-768337a97aceabd1:hover{color:red}p.jsx-768337a97aceabd1::before{color:red}.jsx-768337a97aceabd1:hover{color:red}.jsx-768337a97aceabd1::before{color:red}.jsx-768337a97aceabd1:hover p.jsx-768337a97aceabd1{color:red}p.jsx-768337a97aceabd1+a.jsx-768337a97aceabd1{color:red}p.jsx-768337a97aceabd1~a.jsx-768337a97aceabd1{color:red}p.jsx-768337a97aceabd1>a.jsx-768337a97aceabd1{color:red}@keyframes hahaha{from{top:0}to{top:100}}@keyframes hehehe{from{left:0}to{left:100}}@media(min-width:500px){.test.jsx-768337a97aceabd1{color:red}}.test.jsx-768337a97aceabd1{display:block}.inline-flex.jsx-768337a97aceabd1{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex}.flex.jsx-768337a97aceabd1{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex}.test.jsx-768337a97aceabd1{box-shadow:0 0 10px black,inset 0 0 5px black}.test[title=\",\"].jsx-768337a97aceabd1{display:inline-block}.test.is-status.jsx-768337a97aceabd1 .test.jsx-768337a97aceabd1{color:red}.a-selector.jsx-768337a97aceabd1:hover,.a-selector.jsx-768337a97aceabd1:focus{outline:none}@media(min-width:1px)and (max-width:768px){[class*=\"grid__col--\"].jsx-768337a97aceabd1{margin-top:12px;margin-bottom:12px}}@media(max-width:64em){.test.jsx-768337a97aceabd1{margin-bottom:1em}@supports(-moz-appearance:none)and (display:contents){.test.jsx-768337a97aceabd1{margin-bottom:2rem}}}"}</_JSXStyle>
</div> </div>
); );
import a from "other"; function a(a, b) {
function b(a, b) {
(null == b || b > a.length) && (b = a.length); (null == b || b > a.length) && (b = a.length);
for(var c = 0, d = new Array(b); c < b; c++)d[c] = a[c]; for(var c = 0, d = new Array(b); c < b; c++)d[c] = a[c];
return d; return d;
} }
import b from "other";
(function(a, c) { (function(a, c) {
return (function(a) { return (function(a) {
if (Array.isArray(a)) return a; if (Array.isArray(a)) return a;
...@@ -24,17 +24,17 @@ function b(a, b) { ...@@ -24,17 +24,17 @@ function b(a, b) {
} }
return g; return g;
} }
})(a, c) || (function(a, c) { })(a, c) || (function(b, c) {
if (a) { if (b) {
if ("string" == typeof a) return b(a, c); if ("string" == typeof b) return a(b, c);
var d = Object.prototype.toString.call(a).slice(8, -1); var d = Object.prototype.toString.call(b).slice(8, -1);
if ("Object" === d && a.constructor && (d = a.constructor.name), "Map" === d || "Set" === d) return Array.from(d); if ("Object" === d && b.constructor && (d = b.constructor.name), "Map" === d || "Set" === d) return Array.from(d);
if ("Arguments" === d || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(d)) return b(a, c); if ("Arguments" === d || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(d)) return a(b, c);
} }
})(a, c) || (function() { })(a, c) || (function() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
})(); })();
})(a, 1)[0]; })(b, 1)[0];
var c = function() { var c = function() {
"use strict"; "use strict";
!function(a, b) { !function(a, b) {
......
var _defaultExport = new String("@media (max-width:870px) {th.expiration-date-cell, td.expiration-date-cell{display:none}}"); var _defaultExport = new String("@media(max-width:870px){th.expiration-date-cell,td.expiration-date-cell{display:none}}");
_defaultExport.__hash = "fd71bf06ba8860bb"; _defaultExport.__hash = "fd71bf06ba8860bb";
export default _defaultExport; export default _defaultExport;
import other from 'other';
function _arrayLikeToArray(arr, len) { function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length; if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
...@@ -50,6 +49,7 @@ function _unsupportedIterableToArray(o, minLen) { ...@@ -50,6 +49,7 @@ function _unsupportedIterableToArray(o, minLen) {
if (n === "Map" || n === "Set") return Array.from(n); if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
} }
import other from 'other';
var _other = _slicedToArray(other, 1), foo = _other[0]; var _other = _slicedToArray(other, 1), foo = _other[0];
var Foo = function Foo() { var Foo = function Foo() {
"use strict"; "use strict";
......
import { useEffect } from 'react';
import { select, selectAll } from 'd3-selection';
function _classCallCheck(instance, Constructor) { function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) { if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function"); throw new TypeError("Cannot call a class as a function");
} }
} }
import { useEffect } from 'react';
import { select, selectAll } from 'd3-selection';
export default function Home() { export default function Home() {
useEffect(function() { useEffect(function() {
new MyClass(); new MyClass();
......
import styled from 'styled-components';
function _taggedTemplateLiteral(strings, raw) { function _taggedTemplateLiteral(strings, raw) {
if (!raw) { if (!raw) {
raw = strings.slice(0); raw = strings.slice(0);
...@@ -18,6 +17,7 @@ function _templateObject() { ...@@ -18,6 +17,7 @@ function _templateObject() {
}; };
return data; return data;
} }
import styled from 'styled-components';
export var foo = styled.input.withConfig({ export var foo = styled.input.withConfig({
displayName: "input__foo", displayName: "input__foo",
componentId: "sc-12c52e68-0" componentId: "sc-12c52e68-0"
......
...@@ -16,12 +16,12 @@ once_cell = "1.8.0" ...@@ -16,12 +16,12 @@ once_cell = "1.8.0"
serde = "1" serde = "1"
serde_json = "1" serde_json = "1"
next-swc = { version = "0.0.0", path = "../core" } next-swc = { version = "0.0.0", path = "../core" }
swc = "0.121.7" swc = "0.126.2"
swc_atoms = "0.2.7" swc_atoms = "0.2.7"
swc_bundler = { version = "0.105.0", features = ["concurrent"] } swc_bundler = { version = "0.107.0", features = ["concurrent"] }
swc_common = { version = "0.17.0", features = ["concurrent", "sourcemap"] } swc_common = { version = "0.17.0", features = ["concurrent", "sourcemap"] }
swc_ecma_loader = { version = "0.28.0", features = ["node", "lru"] } swc_ecma_loader = { version = "0.28.0", features = ["node", "lru"] }
swc_ecmascript = { version = "0.112.6", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] } swc_ecmascript = { version = "0.114.2", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.1" swc_node_base = "0.5.1"
[build-dependencies] [build-dependencies]
......
...@@ -16,9 +16,9 @@ path-clean = "0.1" ...@@ -16,9 +16,9 @@ path-clean = "0.1"
serde = {version = "1", features = ["derive"]} serde = {version = "1", features = ["derive"]}
serde_json = "1" serde_json = "1"
next-swc = { version = "0.0.0", path = "../core" } next-swc = { version = "0.0.0", path = "../core" }
swc = "0.121.7" swc = "0.126.2"
swc_common = { version = "0.17.0", features = ["concurrent", "sourcemap"] } swc_common = { version = "0.17.0", features = ["concurrent", "sourcemap"] }
swc_ecmascript = { version = "0.112.6", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] } swc_ecmascript = { version = "0.114.2", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
tracing = {version = "0.1.28", features = ["release_max_level_off"]} tracing = {version = "0.1.28", features = ["release_max_level_off"]}
wasm-bindgen = {version = "0.2", features = ["serde-serialize"]} wasm-bindgen = {version = "0.2", features = ["serde-serialize"]}
wasm-bindgen-futures = "0.4.8" wasm-bindgen-futures = "0.4.8"
{ {
"name": "@next/swc", "name": "@next/swc",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"private": true, "private": true,
"scripts": { "scripts": {
"build-native": "napi build --platform --cargo-name next_swc_napi native", "build-native": "napi build --platform --cargo-name next_swc_napi native",
......
...@@ -532,6 +532,13 @@ export default async function build( ...@@ -532,6 +532,13 @@ export default async function build(
await recursiveDelete(distDir, /^cache/) await recursiveDelete(distDir, /^cache/)
} }
// Ensure commonjs handling is used for files in the distDir (generally .next)
// Files outside of the distDir can be "type": "module"
await promises.writeFile(
path.join(distDir, 'package.json'),
'{"type": "commonjs"}'
)
// We need to write the manifest with rewrites before build // We need to write the manifest with rewrites before build
// so serverless can import the manifest // so serverless can import the manifest
await nextBuildSpan await nextBuildSpan
......
{ {
"name": "next", "name": "next",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"description": "The React Framework", "description": "The React Framework",
"main": "./dist/server/next.js", "main": "./dist/server/next.js",
"license": "MIT", "license": "MIT",
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
] ]
}, },
"dependencies": { "dependencies": {
"@next/env": "12.0.11-canary.15", "@next/env": "12.0.11-canary.17",
"caniuse-lite": "^1.0.30001283", "caniuse-lite": "^1.0.30001283",
"postcss": "8.4.5", "postcss": "8.4.5",
"styled-jsx": "5.0.0", "styled-jsx": "5.0.0",
...@@ -117,11 +117,11 @@ ...@@ -117,11 +117,11 @@
"@hapi/accept": "5.0.2", "@hapi/accept": "5.0.2",
"@napi-rs/cli": "1.2.1", "@napi-rs/cli": "1.2.1",
"@napi-rs/triples": "1.0.3", "@napi-rs/triples": "1.0.3",
"@next/polyfill-module": "12.0.11-canary.15", "@next/polyfill-module": "12.0.11-canary.17",
"@next/polyfill-nomodule": "12.0.11-canary.15", "@next/polyfill-nomodule": "12.0.11-canary.17",
"@next/react-dev-overlay": "12.0.11-canary.15", "@next/react-dev-overlay": "12.0.11-canary.17",
"@next/react-refresh-utils": "12.0.11-canary.15", "@next/react-refresh-utils": "12.0.11-canary.17",
"@next/swc": "12.0.11-canary.15", "@next/swc": "12.0.11-canary.17",
"@peculiar/webcrypto": "1.1.7", "@peculiar/webcrypto": "1.1.7",
"@taskr/clear": "1.1.0", "@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0", "@taskr/esnext": "1.1.0",
......
...@@ -1143,6 +1143,23 @@ export default abstract class Server { ...@@ -1143,6 +1143,23 @@ export default abstract class Server {
res.statusCode = parseInt(pathname.substr(1), 10) res.statusCode = parseInt(pathname.substr(1), 10)
} }
// static pages can only respond to GET/HEAD
// requests so ensure we respond with 405 for
// invalid requests
if (
!is404Page &&
!is500Page &&
pathname !== '/_error' &&
req.method !== 'HEAD' &&
req.method !== 'GET' &&
(typeof components.Component === 'string' || isSSG)
) {
res.statusCode = 405
res.setHeader('Allow', ['GET', 'HEAD'])
await this.renderError(null, req, res, pathname)
return null
}
// handle static page // handle static page
if (typeof components.Component === 'string') { if (typeof components.Component === 'string') {
return { return {
......
...@@ -41,6 +41,7 @@ import { DecodeError } from '../../shared/lib/utils' ...@@ -41,6 +41,7 @@ import { DecodeError } from '../../shared/lib/utils'
import { Span, trace } from '../../trace' import { Span, trace } from '../../trace'
import { getProperError } from '../../lib/is-error' import { getProperError } from '../../lib/is-error'
import ws from 'next/dist/compiled/ws' import ws from 'next/dist/compiled/ws'
import { promises as fs } from 'fs'
const wsServer = new ws.Server({ noServer: true }) const wsServer = new ws.Server({ noServer: true })
...@@ -432,6 +433,15 @@ export default class HotReloader { ...@@ -432,6 +433,15 @@ export default class HotReloader {
startSpan.stop() // Stop immediately to create an artificial parent span startSpan.stop() // Stop immediately to create an artificial parent span
await this.clean(startSpan) await this.clean(startSpan)
// Ensure distDir exists before writing package.json
await fs.mkdir(this.config.distDir, { recursive: true })
// Ensure commonjs handling is used for files in the distDir (generally .next)
// Files outside of the distDir can be "type": "module"
await fs.writeFile(
join(this.config.distDir, 'package.json'),
'{"type": "commonjs"}'
)
const configs = await this.getWebpackConfig(startSpan) const configs = await this.getWebpackConfig(startSpan)
......
...@@ -125,11 +125,7 @@ export default class ResponseCache { ...@@ -125,11 +125,7 @@ export default class ResponseCache {
;(async () => { ;(async () => {
try { try {
const cachedResponse = key ? await this.incrementalCache.get(key) : null const cachedResponse = key ? await this.incrementalCache.get(key) : null
if ( if (cachedResponse && !context.isManualRevalidate) {
cachedResponse &&
(!context.isManualRevalidate ||
cachedResponse.revalidateAfter === false)
) {
resolve({ resolve({
isStale: cachedResponse.isStale, isStale: cachedResponse.isStale,
revalidate: cachedResponse.curRevalidate, revalidate: cachedResponse.curRevalidate,
......
{ {
"name": "@next/react-dev-overlay", "name": "@next/react-dev-overlay",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"description": "A development-only overlay for developing React applications.", "description": "A development-only overlay for developing React applications.",
"repository": { "repository": {
"url": "vercel/next.js", "url": "vercel/next.js",
......
...@@ -3,9 +3,9 @@ import { RefreshRuntimeGlobals } from '../runtime' ...@@ -3,9 +3,9 @@ import { RefreshRuntimeGlobals } from '../runtime'
declare const self: Window & RefreshRuntimeGlobals declare const self: Window & RefreshRuntimeGlobals
type Dictionary = { [key: string]: unknown } type Dictionary = { [key: string]: unknown }
declare const module: { declare const __webpack_module__: {
id: string id: string
__proto__: { exports: unknown } exports: unknown
hot: { hot: {
accept: () => void accept: () => void
dispose: (onDispose: (data: Dictionary) => void) => void dispose: (onDispose: (data: Dictionary) => void) => void
...@@ -27,14 +27,16 @@ export default function () { ...@@ -27,14 +27,16 @@ export default function () {
// AMP / No-JS mode does not inject these helpers: // AMP / No-JS mode does not inject these helpers:
'$RefreshHelpers$' in self '$RefreshHelpers$' in self
) { ) {
var currentExports = module.__proto__.exports // @ts-ignore __webpack_module__ is global
var prevExports = module.hot.data?.prevExports ?? null var currentExports = __webpack_module__.exports
// @ts-ignore __webpack_module__ is global
var prevExports = __webpack_module__.hot.data?.prevExports ?? null
// This cannot happen in MainTemplate because the exports mismatch between // This cannot happen in MainTemplate because the exports mismatch between
// templating and execution. // templating and execution.
self.$RefreshHelpers$.registerExportsForReactRefresh( self.$RefreshHelpers$.registerExportsForReactRefresh(
currentExports, currentExports,
module.id __webpack_module__.id
) )
// A module can be accepted automatically based on its exports, e.g. when // A module can be accepted automatically based on its exports, e.g. when
...@@ -42,12 +44,13 @@ export default function () { ...@@ -42,12 +44,13 @@ export default function () {
if (self.$RefreshHelpers$.isReactRefreshBoundary(currentExports)) { if (self.$RefreshHelpers$.isReactRefreshBoundary(currentExports)) {
// Save the previous exports on update so we can compare the boundary // Save the previous exports on update so we can compare the boundary
// signatures. // signatures.
module.hot.dispose(function (data) { __webpack_module__.hot.dispose(function (data) {
data.prevExports = currentExports data.prevExports = currentExports
}) })
// Unconditionally accept an update to this module, we'll check if it's // Unconditionally accept an update to this module, we'll check if it's
// still a Refresh Boundary later. // still a Refresh Boundary later.
module.hot.accept() // @ts-ignore importMeta is replaced in the loader
global.importMeta.webpackHot.accept()
// This field is set when the previous version of this module was a // This field is set when the previous version of this module was a
// Refresh Boundary, letting us know we need to check for invalidation or // Refresh Boundary, letting us know we need to check for invalidation or
...@@ -66,7 +69,7 @@ export default function () { ...@@ -66,7 +69,7 @@ export default function () {
currentExports currentExports
) )
) { ) {
module.hot.invalidate() __webpack_module__.hot.invalidate()
} else { } else {
self.$RefreshHelpers$.scheduleUpdate() self.$RefreshHelpers$.scheduleUpdate()
} }
...@@ -78,7 +81,7 @@ export default function () { ...@@ -78,7 +81,7 @@ export default function () {
// because we already accepted this update (accidental side effect). // because we already accepted this update (accidental side effect).
var isNoLongerABoundary = prevExports !== null var isNoLongerABoundary = prevExports !== null
if (isNoLongerABoundary) { if (isNoLongerABoundary) {
module.hot.invalidate() __webpack_module__.hot.invalidate()
} }
} }
} }
......
...@@ -2,16 +2,33 @@ import type { LoaderDefinition } from 'webpack' ...@@ -2,16 +2,33 @@ import type { LoaderDefinition } from 'webpack'
import RefreshModuleRuntime from './internal/ReactRefreshModule.runtime' import RefreshModuleRuntime from './internal/ReactRefreshModule.runtime'
let refreshModuleRuntime = RefreshModuleRuntime.toString() let refreshModuleRuntime = RefreshModuleRuntime.toString()
refreshModuleRuntime = refreshModuleRuntime.slice( refreshModuleRuntime = refreshModuleRuntime
refreshModuleRuntime.indexOf('{') + 1, .slice(
refreshModuleRuntime.lastIndexOf('}') refreshModuleRuntime.indexOf('{') + 1,
refreshModuleRuntime.lastIndexOf('}')
)
// Given that the import above executes the module we need to make sure it does not crash on `import.meta` not being allowed.
.replace('global.importMeta', 'import.meta')
let commonJsrefreshModuleRuntime = refreshModuleRuntime.replace(
'import.meta.webpackHot',
'module.hot'
) )
const ReactRefreshLoader: LoaderDefinition = function ReactRefreshLoader( const ReactRefreshLoader: LoaderDefinition = function ReactRefreshLoader(
source, source,
inputSourceMap inputSourceMap
) { ) {
this.callback(null, `${source}\n\n;${refreshModuleRuntime}`, inputSourceMap) this.callback(
null,
`${source}\n\n;${
// Account for commonjs not supporting `import.meta
this.resourcePath.endsWith('.cjs')
? commonJsrefreshModuleRuntime
: refreshModuleRuntime
}`,
inputSourceMap
)
} }
export default ReactRefreshLoader export default ReactRefreshLoader
{ {
"name": "@next/react-refresh-utils", "name": "@next/react-refresh-utils",
"version": "12.0.11-canary.15", "version": "12.0.11-canary.17",
"description": "An experimental package providing utilities for React Refresh.", "description": "An experimental package providing utilities for React Refresh.",
"repository": { "repository": {
"url": "vercel/next.js", "url": "vercel/next.js",
......
...@@ -290,6 +290,14 @@ const runTests = (dev = false) => { ...@@ -290,6 +290,14 @@ const runTests = (dev = false) => {
expect(await res.text()).toBe('hello from gssp') expect(await res.text()).toBe('hello from gssp')
}) })
it('should allow POST request for getServerSideProps page', async () => {
const res = await fetchViaHTTP(next.url, '/', undefined, {
method: 'POST',
})
expect(res.status).toBe(200)
expect(await res.text()).toMatch(/hello.*?world/)
})
it('should render correctly when notFound is false (non-dynamic)', async () => { it('should render correctly when notFound is false (non-dynamic)', async () => {
const res = await fetchViaHTTP(next.url, '/not-found') const res = await fetchViaHTTP(next.url, '/not-found')
......
...@@ -422,6 +422,14 @@ describe('Prerender', () => { ...@@ -422,6 +422,14 @@ describe('Prerender', () => {
const runTests = (dev = false) => { const runTests = (dev = false) => {
navigateTest(dev) navigateTest(dev)
it('should respond with 405 for POST to static page', async () => {
const res = await fetchViaHTTP(next.url, '/', undefined, {
method: 'POST',
})
expect(res.status).toBe(405)
expect(await res.text()).toContain('Method Not Allowed')
})
it('should SSR normal page correctly', async () => { it('should SSR normal page correctly', async () => {
const html = await renderViaHTTP(next.url, '/') const html = await renderViaHTTP(next.url, '/')
expect(html).toMatch(/hello.*?world/) expect(html).toMatch(/hello.*?world/)
...@@ -1931,7 +1939,7 @@ describe('Prerender', () => { ...@@ -1931,7 +1939,7 @@ describe('Prerender', () => {
expect($4('#time').text()).not.toBe(initialTime) expect($4('#time').text()).not.toBe(initialTime)
}) })
it('should not manual revalidate for revalidate: false', async () => { it('should manual revalidate for revalidate: false', async () => {
const html = await renderViaHTTP( const html = await renderViaHTTP(
next.url, next.url,
'/blocking-fallback-once/test-manual-1' '/blocking-fallback-once/test-manual-1'
...@@ -1967,7 +1975,7 @@ describe('Prerender', () => { ...@@ -1967,7 +1975,7 @@ describe('Prerender', () => {
'/blocking-fallback-once/test-manual-1' '/blocking-fallback-once/test-manual-1'
) )
const $4 = cheerio.load(html4) const $4 = cheerio.load(html4)
expect($4('#time').text()).toBe(initialTime) expect($4('#time').text()).not.toBe(initialTime)
}) })
it('should handle manual revalidate for fallback: false', async () => { it('should handle manual revalidate for fallback: false', async () => {
......
import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { hasRedbox, renderViaHTTP } from 'next-test-utils'
import webdriver from 'next-webdriver'
describe('Type module interop', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
export default function Page() {
return <p>hello world</p>
}
`,
},
dependencies: {},
})
const contents = await next.readFile('package.json')
const pkg = JSON.parse(contents)
await next.patchFile(
'package.json',
JSON.stringify({
...pkg,
type: 'module',
})
)
})
afterAll(() => next.destroy())
it('should render server-side', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('hello world')
})
it('should render client-side', async () => {
const browser = await webdriver(next.url, '/')
expect(await hasRedbox(browser)).toBe(false)
await browser.close()
})
})
export default function Page() { export default function Page() {
return <div>User</div> return <div>User</div>
} }
export function getServerSideProps() {
return {
props: {},
}
}
...@@ -132,8 +132,9 @@ const runTests = (isDev) => { ...@@ -132,8 +132,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
`${basePath}/gsp-blog/redirect-dest-_gsp-blog_first`, `${basePath}/gsp-blog/redirect-dest-_gsp-blog_first`,
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('#gsp') await browser.waitForElementByCss('#gsp')
...@@ -154,8 +155,9 @@ const runTests = (isDev) => { ...@@ -154,8 +155,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
`${basePath}/gsp-blog/redirect-dest-_gsp-blog_first`, `${basePath}/gsp-blog/redirect-dest-_gsp-blog_first`,
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('#gsp') await browser.waitForElementByCss('#gsp')
...@@ -178,8 +180,9 @@ const runTests = (isDev) => { ...@@ -178,8 +180,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
`${basePath}/gsp-blog/redirect-dest-_`, `${basePath}/gsp-blog/redirect-dest-_`,
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('#index') await browser.waitForElementByCss('#index')
...@@ -194,8 +197,9 @@ const runTests = (isDev) => { ...@@ -194,8 +197,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
`${basePath}/gsp-blog/redirect-dest-_`, `${basePath}/gsp-blog/redirect-dest-_`,
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('#index') await browser.waitForElementByCss('#index')
...@@ -210,8 +214,9 @@ const runTests = (isDev) => { ...@@ -210,8 +214,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
`${basePath}/gsp-blog/redirect-dest-_missing`, `${basePath}/gsp-blog/redirect-dest-_missing`,
true, {
true retryWaitHydration: true,
}
) )
await check( await check(
...@@ -231,8 +236,9 @@ const runTests = (isDev) => { ...@@ -231,8 +236,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
`${basePath}/gsp-blog/redirect-dest-external`, `${basePath}/gsp-blog/redirect-dest-external`,
true, {
true retryWaitHydration: true,
}
) )
await check( await check(
...@@ -248,8 +254,9 @@ const runTests = (isDev) => { ...@@ -248,8 +254,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
`${basePath}/gssp-blog/redirect-dest-external`, `${basePath}/gssp-blog/redirect-dest-external`,
true, {
true retryWaitHydration: true,
}
) )
await check( await check(
...@@ -279,8 +286,9 @@ const runTests = (isDev) => { ...@@ -279,8 +286,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
`${basePath}/gssp-blog/redirect-dest-_gssp-blog_first`, `${basePath}/gssp-blog/redirect-dest-_gssp-blog_first`,
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('#gssp') await browser.waitForElementByCss('#gssp')
...@@ -294,7 +302,9 @@ const runTests = (isDev) => { ...@@ -294,7 +302,9 @@ const runTests = (isDev) => {
}) })
it('should apply redirect when GSSP page is navigated to client-side (internal normal)', async () => { it('should apply redirect when GSSP page is navigated to client-side (internal normal)', async () => {
const browser = await webdriver(appPort, `${basePath}`, true, true) const browser = await webdriver(appPort, `${basePath}`, {
retryWaitHydration: true,
})
await browser.eval(`(function () { await browser.eval(`(function () {
window.next.router.push('/gssp-blog/redirect-dest-_another') window.next.router.push('/gssp-blog/redirect-dest-_another')
...@@ -307,7 +317,9 @@ const runTests = (isDev) => { ...@@ -307,7 +317,9 @@ const runTests = (isDev) => {
}) })
it('should apply redirect when GSSP page is navigated to client-side (external)', async () => { it('should apply redirect when GSSP page is navigated to client-side (external)', async () => {
const browser = await webdriver(appPort, `${basePath}`, true, true) const browser = await webdriver(appPort, `${basePath}`, {
retryWaitHydration: true,
})
await browser.eval(`(function () { await browser.eval(`(function () {
window.next.router.push('/gssp-blog/redirect-dest-_gssp-blog_first') window.next.router.push('/gssp-blog/redirect-dest-_gssp-blog_first')
...@@ -324,7 +336,9 @@ const runTests = (isDev) => { ...@@ -324,7 +336,9 @@ const runTests = (isDev) => {
}) })
it('should apply redirect when GSP page is navigated to client-side (internal)', async () => { it('should apply redirect when GSP page is navigated to client-side (internal)', async () => {
const browser = await webdriver(appPort, `${basePath}`, true, true) const browser = await webdriver(appPort, `${basePath}`, {
retryWaitHydration: true,
})
await browser.eval(`(function () { await browser.eval(`(function () {
window.next.router.push('/gsp-blog/redirect-dest-_another') window.next.router.push('/gsp-blog/redirect-dest-_another')
...@@ -337,7 +351,9 @@ const runTests = (isDev) => { ...@@ -337,7 +351,9 @@ const runTests = (isDev) => {
}) })
it('should apply redirect when GSP page is navigated to client-side (external)', async () => { it('should apply redirect when GSP page is navigated to client-side (external)', async () => {
const browser = await webdriver(appPort, `${basePath}`, true, true) const browser = await webdriver(appPort, `${basePath}`, {
retryWaitHydration: true,
})
await browser.eval(`(function () { await browser.eval(`(function () {
window.next.router.push('/gsp-blog/redirect-dest-_gsp-blog_first') window.next.router.push('/gsp-blog/redirect-dest-_gsp-blog_first')
...@@ -357,8 +373,9 @@ const runTests = (isDev) => { ...@@ -357,8 +373,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
`${basePath}/another?mark_as=root`, `${basePath}/another?mark_as=root`,
true, {
true retryWaitHydration: true,
}
) )
await browser.eval(`(function () { await browser.eval(`(function () {
...@@ -384,8 +401,9 @@ const runTests = (isDev) => { ...@@ -384,8 +401,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
`${basePath}/another?mark_as=root`, `${basePath}/another?mark_as=root`,
true, {
true retryWaitHydration: true,
}
) )
await browser.eval(`(function () { await browser.eval(`(function () {
...@@ -411,8 +429,9 @@ const runTests = (isDev) => { ...@@ -411,8 +429,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
`${basePath}/another?mark_as=root`, `${basePath}/another?mark_as=root`,
true, {
true retryWaitHydration: true,
}
) )
await browser.eval(`(function () { await browser.eval(`(function () {
...@@ -438,8 +457,9 @@ const runTests = (isDev) => { ...@@ -438,8 +457,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
`${basePath}/another?mark_as=root`, `${basePath}/another?mark_as=root`,
true, {
true retryWaitHydration: true,
}
) )
await browser.eval(`(function () { await browser.eval(`(function () {
......
...@@ -92,8 +92,9 @@ const runTests = (isDev) => { ...@@ -92,8 +92,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
'/gsp-blog/redirect-dest-_gsp-blog_first', '/gsp-blog/redirect-dest-_gsp-blog_first',
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('#gsp') await browser.waitForElementByCss('#gsp')
...@@ -113,8 +114,9 @@ const runTests = (isDev) => { ...@@ -113,8 +114,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
'/gsp-blog-blocking/redirect-dest-_gsp-blog_first', '/gsp-blog-blocking/redirect-dest-_gsp-blog_first',
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('#gsp') await browser.waitForElementByCss('#gsp')
...@@ -134,8 +136,9 @@ const runTests = (isDev) => { ...@@ -134,8 +136,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
'/gsp-blog-blocking/redirect-dest-_gsp-blog_first', '/gsp-blog-blocking/redirect-dest-_gsp-blog_first',
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('#gsp') await browser.waitForElementByCss('#gsp')
...@@ -155,8 +158,9 @@ const runTests = (isDev) => { ...@@ -155,8 +158,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
'/gsp-blog-blocking/redirect-revalidate-dest-_gsp-blog_first', '/gsp-blog-blocking/redirect-revalidate-dest-_gsp-blog_first',
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('#gsp') await browser.waitForElementByCss('#gsp')
...@@ -176,8 +180,9 @@ const runTests = (isDev) => { ...@@ -176,8 +180,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
'/gsp-blog-blocking/redirect-revalidate-dest-_gsp-blog_first', '/gsp-blog-blocking/redirect-revalidate-dest-_gsp-blog_first',
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('#gsp') await browser.waitForElementByCss('#gsp')
...@@ -198,8 +203,9 @@ const runTests = (isDev) => { ...@@ -198,8 +203,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
'/gsp-blog/redirect-dest-_gsp-blog_first', '/gsp-blog/redirect-dest-_gsp-blog_first',
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('#gsp') await browser.waitForElementByCss('#gsp')
...@@ -219,12 +225,9 @@ const runTests = (isDev) => { ...@@ -219,12 +225,9 @@ const runTests = (isDev) => {
} }
it('should apply redirect when fallback GSP page is visited directly (internal normal)', async () => { it('should apply redirect when fallback GSP page is visited directly (internal normal)', async () => {
const browser = await webdriver( const browser = await webdriver(appPort, '/gsp-blog/redirect-dest-_', {
appPort, retryWaitHydration: true,
'/gsp-blog/redirect-dest-_', })
true,
true
)
await browser.waitForElementByCss('#index') await browser.waitForElementByCss('#index')
...@@ -235,12 +238,9 @@ const runTests = (isDev) => { ...@@ -235,12 +238,9 @@ const runTests = (isDev) => {
if (!isDev) { if (!isDev) {
it('should apply redirect when fallback GSP page is visited directly (internal normal) 2nd visit', async () => { it('should apply redirect when fallback GSP page is visited directly (internal normal) 2nd visit', async () => {
const browser = await webdriver( const browser = await webdriver(appPort, '/gsp-blog/redirect-dest-_', {
appPort, retryWaitHydration: true,
'/gsp-blog/redirect-dest-_', })
true,
true
)
await browser.waitForElementByCss('#index') await browser.waitForElementByCss('#index')
...@@ -254,8 +254,9 @@ const runTests = (isDev) => { ...@@ -254,8 +254,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
'/gsp-blog/redirect-dest-_missing', '/gsp-blog/redirect-dest-_missing',
true, {
true retryWaitHydration: true,
}
) )
await check( await check(
...@@ -275,8 +276,9 @@ const runTests = (isDev) => { ...@@ -275,8 +276,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
'/gsp-blog/redirect-dest-external', '/gsp-blog/redirect-dest-external',
true, {
true retryWaitHydration: true,
}
) )
await check( await check(
...@@ -292,8 +294,9 @@ const runTests = (isDev) => { ...@@ -292,8 +294,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
'/gssp-blog/redirect-dest-external', '/gssp-blog/redirect-dest-external',
true, {
true retryWaitHydration: true,
}
) )
await check( await check(
...@@ -323,8 +326,9 @@ const runTests = (isDev) => { ...@@ -323,8 +326,9 @@ const runTests = (isDev) => {
const browser = await webdriver( const browser = await webdriver(
appPort, appPort,
'/gssp-blog/redirect-dest-_gssp-blog_first', '/gssp-blog/redirect-dest-_gssp-blog_first',
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('#gssp') await browser.waitForElementByCss('#gssp')
...@@ -338,7 +342,9 @@ const runTests = (isDev) => { ...@@ -338,7 +342,9 @@ const runTests = (isDev) => {
}) })
it('should apply redirect when GSSP page is navigated to client-side (internal normal)', async () => { it('should apply redirect when GSSP page is navigated to client-side (internal normal)', async () => {
const browser = await webdriver(appPort, '/', true, true) const browser = await webdriver(appPort, '/', {
retryWaitHydration: true,
})
await browser.eval(`(function () { await browser.eval(`(function () {
window.next.router.push('/gssp-blog/redirect-dest-_another') window.next.router.push('/gssp-blog/redirect-dest-_another')
...@@ -351,7 +357,9 @@ const runTests = (isDev) => { ...@@ -351,7 +357,9 @@ const runTests = (isDev) => {
}) })
it('should apply redirect when GSSP page is navigated to client-side (external)', async () => { it('should apply redirect when GSSP page is navigated to client-side (external)', async () => {
const browser = await webdriver(appPort, '/', true, true) const browser = await webdriver(appPort, '/', {
retryWaitHydration: true,
})
await browser.eval(`(function () { await browser.eval(`(function () {
window.next.router.push('/gssp-blog/redirect-dest-_gssp-blog_first') window.next.router.push('/gssp-blog/redirect-dest-_gssp-blog_first')
...@@ -368,7 +376,9 @@ const runTests = (isDev) => { ...@@ -368,7 +376,9 @@ const runTests = (isDev) => {
}) })
it('should apply redirect when GSP page is navigated to client-side (internal)', async () => { it('should apply redirect when GSP page is navigated to client-side (internal)', async () => {
const browser = await webdriver(appPort, '/', true, true) const browser = await webdriver(appPort, '/', {
retryWaitHydration: true,
})
await browser.eval(`(function () { await browser.eval(`(function () {
window.next.router.push('/gsp-blog/redirect-dest-_another') window.next.router.push('/gsp-blog/redirect-dest-_another')
...@@ -381,7 +391,9 @@ const runTests = (isDev) => { ...@@ -381,7 +391,9 @@ const runTests = (isDev) => {
}) })
it('should apply redirect when GSP page is navigated to client-side (external)', async () => { it('should apply redirect when GSP page is navigated to client-side (external)', async () => {
const browser = await webdriver(appPort, '/', true, true) const browser = await webdriver(appPort, '/', {
retryWaitHydration: true,
})
await browser.eval(`(function () { await browser.eval(`(function () {
window.next.router.push('/gsp-blog/redirect-dest-_gsp-blog_first') window.next.router.push('/gsp-blog/redirect-dest-_gsp-blog_first')
...@@ -398,12 +410,9 @@ const runTests = (isDev) => { ...@@ -398,12 +410,9 @@ const runTests = (isDev) => {
}) })
it('should not replace history of the origin page when GSSP page is navigated to client-side (internal normal)', async () => { it('should not replace history of the origin page when GSSP page is navigated to client-side (internal normal)', async () => {
const browser = await webdriver( const browser = await webdriver(appPort, '/another?mark_as=root', {
appPort, retryWaitHydration: true,
'/another?mark_as=root', })
true,
true
)
await browser.eval(`(function () { await browser.eval(`(function () {
window.next.router.push('/') window.next.router.push('/')
...@@ -425,12 +434,9 @@ const runTests = (isDev) => { ...@@ -425,12 +434,9 @@ const runTests = (isDev) => {
}) })
it('should not replace history of the origin page when GSSP page is navigated to client-side (external)', async () => { it('should not replace history of the origin page when GSSP page is navigated to client-side (external)', async () => {
const browser = await webdriver( const browser = await webdriver(appPort, '/another?mark_as=root', {
appPort, retryWaitHydration: true,
'/another?mark_as=root', })
true,
true
)
await browser.eval(`(function () { await browser.eval(`(function () {
window.next.router.push('/') window.next.router.push('/')
...@@ -452,12 +458,9 @@ const runTests = (isDev) => { ...@@ -452,12 +458,9 @@ const runTests = (isDev) => {
}) })
it('should not replace history of the origin page when GSP page is navigated to client-side (internal)', async () => { it('should not replace history of the origin page when GSP page is navigated to client-side (internal)', async () => {
const browser = await webdriver( const browser = await webdriver(appPort, '/another?mark_as=root', {
appPort, retryWaitHydration: true,
'/another?mark_as=root', })
true,
true
)
await browser.eval(`(function () { await browser.eval(`(function () {
window.next.router.push('/') window.next.router.push('/')
...@@ -479,12 +482,9 @@ const runTests = (isDev) => { ...@@ -479,12 +482,9 @@ const runTests = (isDev) => {
}) })
it('should not replace history of the origin page when GSP page is navigated to client-side (external)', async () => { it('should not replace history of the origin page when GSP page is navigated to client-side (external)', async () => {
const browser = await webdriver( const browser = await webdriver(appPort, '/another?mark_as=root', {
appPort, retryWaitHydration: true,
'/another?mark_as=root', })
true,
true
)
await browser.eval(`(function () { await browser.eval(`(function () {
window.next.router.push('/') window.next.router.push('/')
......
...@@ -2354,12 +2354,9 @@ export function runTests(ctx) { ...@@ -2354,12 +2354,9 @@ export function runTests(ctx) {
}) })
it('should render 404 for fallback page that returned 404 on client transition', async () => { it('should render 404 for fallback page that returned 404 on client transition', async () => {
const browser = await webdriver( const browser = await webdriver(ctx.appPort, `${ctx.basePath}/en`, {
ctx.appPort, retryWaitHydration: true,
`${ctx.basePath}/en`, })
true,
true
)
await browser.eval(`(function() { await browser.eval(`(function() {
next.router.push('/not-found/fallback/first') next.router.push('/not-found/fallback/first')
})()`) })()`)
...@@ -2395,8 +2392,9 @@ export function runTests(ctx) { ...@@ -2395,8 +2392,9 @@ export function runTests(ctx) {
const browser = await webdriver( const browser = await webdriver(
ctx.appPort, ctx.appPort,
`${ctx.basePath}/en/not-found/fallback/first`, `${ctx.basePath}/en/not-found/fallback/first`,
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('h1') await browser.waitForElementByCss('h1')
await browser.eval('window.beforeNav = 1') await browser.eval('window.beforeNav = 1')
...@@ -2427,12 +2425,9 @@ export function runTests(ctx) { ...@@ -2427,12 +2425,9 @@ export function runTests(ctx) {
}) })
it('should render 404 for blocking fallback page that returned 404 on client transition', async () => { it('should render 404 for blocking fallback page that returned 404 on client transition', async () => {
const browser = await webdriver( const browser = await webdriver(ctx.appPort, `${ctx.basePath}/en`, {
ctx.appPort, retryWaitHydration: true,
`${ctx.basePath}/en`, })
true,
true
)
await browser.eval(`(function() { await browser.eval(`(function() {
next.router.push('/not-found/blocking-fallback/first') next.router.push('/not-found/blocking-fallback/first')
})()`) })()`)
...@@ -2468,8 +2463,9 @@ export function runTests(ctx) { ...@@ -2468,8 +2463,9 @@ export function runTests(ctx) {
const browser = await webdriver( const browser = await webdriver(
ctx.appPort, ctx.appPort,
`${ctx.basePath}/en/not-found/blocking-fallback/first`, `${ctx.basePath}/en/not-found/blocking-fallback/first`,
true, {
true retryWaitHydration: true,
}
) )
await browser.waitForElementByCss('h1') await browser.waitForElementByCss('h1')
await browser.eval('window.beforeNav = 1') await browser.eval('window.beforeNav = 1')
......
...@@ -62,7 +62,9 @@ describe('react-virtualized wrapping next/image', () => { ...@@ -62,7 +62,9 @@ describe('react-virtualized wrapping next/image', () => {
it('should not cancel requests for images', async () => { it('should not cancel requests for images', async () => {
// TODO: this test doesnt work unless we can set `disableCache: true` // TODO: this test doesnt work unless we can set `disableCache: true`
let browser = await webdriver(appPort, '/', undefined, undefined, true) let browser = await webdriver(appPort, '/', {
disableCache: true,
})
expect(cancelCount).toBe(0) expect(cancelCount).toBe(0)
await browser.eval('window.scrollTo({ top: 100, behavior: "smooth" })') await browser.eval('window.scrollTo({ top: 100, behavior: "smooth" })')
await waitFor(100) await waitFor(100)
......
...@@ -156,11 +156,15 @@ describe('pnpm support', () => { ...@@ -156,11 +156,15 @@ describe('pnpm support', () => {
await renderViaHTTP(appPort, '/') await renderViaHTTP(appPort, '/')
browser = await webdriver(appPort, '/', false) browser = await webdriver(appPort, '/', {
waitHydration: false,
})
expect(await browser.waitForElementByCss('#world').text()).toBe('World') expect(await browser.waitForElementByCss('#world').text()).toBe('World')
await browser.close() await browser.close()
browser = await webdriver(appPort, '/about', false) browser = await webdriver(appPort, '/about', {
waitHydration: false,
})
expect(await browser.waitForElementByCss('#world').text()).toBe('World') expect(await browser.waitForElementByCss('#world').text()).toBe('World')
await browser.close() await browser.close()
} finally { } finally {
......
...@@ -69,6 +69,14 @@ describe('Production Usage', () => { ...@@ -69,6 +69,14 @@ describe('Production Usage', () => {
) )
}) })
it('should respond with 405 for POST to static page', async () => {
const res = await fetchViaHTTP(appPort, '/', undefined, {
method: 'POST',
})
expect(res.status).toBe(405)
expect(await res.text()).toContain('Method Not Allowed')
})
it('should contain generated page count in output', async () => { it('should contain generated page count in output', async () => {
const pageCount = 40 const pageCount = 40
expect(output).toContain(`Generating static pages (0/${pageCount})`) expect(output).toContain(`Generating static pages (0/${pageCount})`)
...@@ -369,7 +377,7 @@ describe('Production Usage', () => { ...@@ -369,7 +377,7 @@ describe('Production Usage', () => {
it('should render 200 for POST on page', async () => { it('should render 200 for POST on page', async () => {
const res = await fetchViaHTTP( const res = await fetchViaHTTP(
`http://localhost:${appPort}`, `http://localhost:${appPort}`,
'/about', '/fully-dynamic',
undefined, undefined,
{ {
method: 'POST', method: 'POST',
......
...@@ -30,6 +30,25 @@ export default function (context, { runtime, env }) { ...@@ -30,6 +30,25 @@ export default function (context, { runtime, env }) {
expect(homeHTML).toContain('foo.client') expect(homeHTML).toContain('foo.client')
}) })
it('should reuse the inline flight response without sending extra requests', async () => {
let hasFlightRequest = false
let requestsCount = 0
await webdriver(context.appPort, '/', {
beforePageLoad(page) {
page.on('request', (request) => {
requestsCount++
const url = request.url()
if (/__flight__=1/.test(url)) {
hasFlightRequest = true
}
})
},
})
expect(requestsCount).toBeGreaterThan(0)
expect(hasFlightRequest).toBe(false)
})
it('should support multi-level server component imports', async () => { it('should support multi-level server component imports', async () => {
const html = await renderViaHTTP(context.appPort, '/multi') const html = await renderViaHTTP(context.appPort, '/multi')
expect(html).toContain('bar.server.js:') expect(html).toContain('bar.server.js:')
...@@ -127,14 +146,13 @@ export default function (context, { runtime, env }) { ...@@ -127,14 +146,13 @@ export default function (context, { runtime, env }) {
const content = 'custom-404-page' const content = 'custom-404-page'
const page404HTML = await renderViaHTTP(context.appPort, '/404') const page404HTML = await renderViaHTTP(context.appPort, '/404')
const pageUnknownHTML = await renderViaHTTP(context.appPort, '/no.where') const pageUnknownHTML = await renderViaHTTP(context.appPort, '/no.where')
let browser = await webdriver(context.appPort, '/404')
const hydrated404Content = await browser.waitForElementByCss(id).text()
browser = await webdriver(context.appPort, '/no.where')
const hydratedUnknownContent = await browser.waitForElementByCss(id).text()
const page404Browser = await webdriver(context.appPort, '/404') expect(hydrated404Content).toBe(content)
const pageUnknownBrowser = await webdriver(context.appPort, '/no.where') expect(hydratedUnknownContent).toBe(content)
expect(await page404Browser.waitForElementByCss(id).text()).toBe(content)
expect(await pageUnknownBrowser.waitForElementByCss(id).text()).toBe(
content
)
expect(getNodeBySelector(page404HTML, id).text()).toBe(content) expect(getNodeBySelector(page404HTML, id).text()).toBe(content)
expect(getNodeBySelector(pageUnknownHTML, id).text()).toBe(content) expect(getNodeBySelector(pageUnknownHTML, id).text()).toBe(content)
......
...@@ -72,7 +72,10 @@ export class BrowserInterface { ...@@ -72,7 +72,10 @@ export class BrowserInterface {
} }
on(event: Event, cb: (...args: any[]) => void) {} on(event: Event, cb: (...args: any[]) => void) {}
off(event: Event, cb: (...args: any[]) => void) {} off(event: Event, cb: (...args: any[]) => void) {}
async loadPage(url: string, { disableCache: boolean }): Promise<any> {} async loadPage(
url: string,
{ disableCache: boolean, beforePageLoad: Function }
): Promise<void> {}
async get(url: string): Promise<void> {} async get(url: string): Promise<void> {}
async getValue(): Promise<any> {} async getValue(): Promise<any> {}
......
...@@ -64,7 +64,10 @@ class Playwright extends BrowserInterface { ...@@ -64,7 +64,10 @@ class Playwright extends BrowserInterface {
return page.goto(url) as any return page.goto(url) as any
} }
async loadPage(url: string, opts?: { disableCache: boolean }) { async loadPage(
url: string,
opts?: { disableCache: boolean; beforePageLoad?: (...args: any[]) => void }
) {
if (this.activeTrace) { if (this.activeTrace) {
const traceDir = path.join(__dirname, '../../traces') const traceDir = path.join(__dirname, '../../traces')
const traceOutputPath = path.join( const traceOutputPath = path.join(
...@@ -136,6 +139,8 @@ class Playwright extends BrowserInterface { ...@@ -136,6 +139,8 @@ class Playwright extends BrowserInterface {
}) })
}) })
opts?.beforePageLoad?.(page)
if (tracePlaywright) { if (tracePlaywright) {
await context.tracing.start({ await context.tracing.start({
screenshots: true, screenshots: true,
......
...@@ -40,19 +40,33 @@ if (typeof afterAll === 'function') { ...@@ -40,19 +40,33 @@ if (typeof afterAll === 'function') {
* *
* @param appPort can either be the port or the full URL * @param appPort can either be the port or the full URL
* @param url the path/query to append when using appPort * @param url the path/query to append when using appPort
* @param waitHydration whether to wait for react hydration to finish * @param options.waitHydration whether to wait for react hydration to finish
* @param retryWaitHydration allow retrying hydration wait if reload occurs * @param options.retryWaitHydration allow retrying hydration wait if reload occurs
* @param options.disableCache disable cache for page load
* @param options.beforePageLoad the callback receiving page instance before loading page
* @returns thenable browser instance * @returns thenable browser instance
*/ */
export default async function webdriver( export default async function webdriver(
appPortOrUrl: string | number, appPortOrUrl: string | number,
url: string, url: string,
waitHydration = true, options?: {
retryWaitHydration = false, waitHydration?: boolean
disableCache = false retryWaitHydration?: boolean
disableCache?: boolean
beforePageLoad?: (page: any) => void
}
): Promise<BrowserInterface> { ): Promise<BrowserInterface> {
let CurrentInterface: typeof BrowserInterface let CurrentInterface: typeof BrowserInterface
const defaultOptions = {
waitHydration: true,
retryWaitHydration: false,
disableCache: false,
}
options = Object.assign(defaultOptions, options)
const { waitHydration, retryWaitHydration, disableCache, beforePageLoad } =
options
// we import only the needed interface // we import only the needed interface
if ( if (
process.env.LEGACY_SAFARI || process.env.LEGACY_SAFARI ||
...@@ -81,7 +95,7 @@ export default async function webdriver( ...@@ -81,7 +95,7 @@ export default async function webdriver(
console.log(`\n> Loading browser with ${fullUrl}\n`) console.log(`\n> Loading browser with ${fullUrl}\n`)
await browser.loadPage(fullUrl, { disableCache }) await browser.loadPage(fullUrl, { disableCache, beforePageLoad })
console.log(`\n> Loaded browser with ${fullUrl}\n`) console.log(`\n> Loaded browser with ${fullUrl}\n`)
// Wait for application to hydrate // Wait for application to hydrate
......
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