Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reexports styled-jsx JSXStyle in nextjs #36585

Merged
merged 8 commits into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,9 @@ jobs:
- run: xvfb-run node run-tests.js --timings -g ${{ matrix.group }}/18
if: ${{needs.build.outputs.docsChange != 'docs only change'}}

- run: NEXT_TEST_MODE=start PKG_MANAGER=pnpm xvfb-run node run-tests.js test/e2e/styled-jsx/index.test.ts
if: ${{needs.build.outputs.docsChange != 'docs only change'}}

- name: Upload test trace
if: always()
uses: actions/upload-artifact@v2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default function Foo() {
return /*#__PURE__*/ React.createElement("div", {
render: function(v) {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/styled_jsx/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ pub fn styled_jsx_import_decl(style_import_name: &str) -> ModuleItem {
})],
src: Str {
span: DUMMY_SP,
value: "styled-jsx/style".into(),
value: "next/dist/shared/lib/styled-jsx".into(),
raw: None,
},
}))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=><div >

<style jsx>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default {
styles: <_JSXStyle id={"71f03d42ea0ec6"}>{".container.jsx-71f03d42ea0ec6{background:#000;color:white;font-weight:700;height:100px}"}</_JSXStyle>,
className: "jsx-71f03d42ea0ec6"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=><div >

<style jsx>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=><div >

<style jsx>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=><div >

<style jsx>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=>{
const Element = 'div';
return <div className={"jsx-abb4c2202db1a207"}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
import styles from './styles';
const styles2 = require('./styles2');
// external only
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default class {
render() {
return <div className={"jsx-b2b86d63f35d25ee"}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default class {
render() {
return <div className={"jsx-1952086b0a5ae64c"}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
const Test = ()=><div className={"jsx-a9535d7d5f32c3c4"}>

<span className={"jsx-a9535d7d5f32c3c4"}>test</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
function NavigationItem({ active , className , }) {
return <span className={"jsx-2342aae4628612c6" + " " + (cn({
active
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (({ children })=><div className={`jsx-${styles.__hash}`}>

<p className={`jsx-${styles.__hash}`}>{children}</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
const color = 'red';
const otherColor = 'green';
const A = ()=><div className={"jsx-498d4e86e548e679"}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default class {
render() {
const Element = 'div';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
import styles from './styles2';
export default (({ level =1 })=>{
const Element = `h${level}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (({ level =1 })=>{
const Element = `h${level}`;
return <Element className={"jsx-fca64cc3f069b519" + " " + "root"}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
const darken = (c)=>c
;
const color = 'red';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
function test() {
({
styles: <_JSXStyle id={"abb4c2202db1a207"}>{"div.jsx-abb4c2202db1a207{color:red}"}</_JSXStyle>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
import styles, { foo as styles3 } from './styles';
const styles2 = require('./styles2');
export default (()=><div >
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
import styles from './styles';
export default (()=><div className={`jsx-${styles.__hash}`}>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
import styles from './styles';
const styles2 = require('./styles2');
import { foo as styles3 } from './styles';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
import React from 'react';
export default (()=><>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
const Test = ()=><div className={"jsx-5a206f122d1cb32e"}>

<span className={"jsx-5a206f122d1cb32e"}>test</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default function IndexPage() {
return <div className={"jsx-b6abd0684ba81871"}>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
const Test = ()=><div className={"jsx-d47d6adadf14e957"}>

<_JSXStyle id={"d47d6adadf14e957"}>{"body{color:red}:hover{color:red;display:-webkit-box;display:-webkit-flex;display:-moz-box;display:-ms-flexbox;display:flex;-webkit-animation:foo 1s ease-out;-moz-animation:foo 1s ease-out;-o-animation:foo 1s ease-out;animation:foo 1s ease-out}div a{display:none}[data-test]>div{color:red}"}</_JSXStyle>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (({ breakPoint })=><div className={_JSXStyle.dynamic([
[
"1568e0a11702cf40",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default function IndexPage() {
return (
<div>
<h1>Hello World.</h1>

<style jsx global>{`
@supports (display: flex) {
h1 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default function IndexPage() {
return <div className={"jsx-bbdada4ef17d18ef"}>

<h1 className={"jsx-bbdada4ef17d18ef"}>Hello World.</h1>



<_JSXStyle id={"bbdada4ef17d18ef"}>{"@supports(display:flex){h1{color:hotpink}}"}</_JSXStyle>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default class {
render() {
return <div className={_JSXStyle.dynamic([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
const Test = ()=><_JSXStyle id={"94239b6d6b42c9b5"}>{"p{color:red}"}</_JSXStyle>
;
export default (()=><div className={"jsx-3822e6e1fb9fa41a"}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
const attrs = {
id: 'test'
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=><div className={"jsx-94239b6d6b42c9b5"}>

<p className={"jsx-94239b6d6b42c9b5"}>woot</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
import Link from "next/link";
export default function IndexPage() {
return <div className={"jsx-2339e3d61ab4470c"}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=><div className={"jsx-c7c3a8e231c9215a"}>

<p className={"jsx-c7c3a8e231c9215a"}>test</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=><div className={"jsx-94239b6d6b42c9b5"}>

<p className={"jsx-94239b6d6b42c9b5"}>test</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
import colors, { size } from './constants';
const color = 'red';
const bar = new String("div.jsx-aaed0341accea8f{font-size:3em}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export const Red = ({ Component ='button' , })=>{
return <Component className={_JSXStyle.dynamic([
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default class {
render() {
return <div className={"jsx-1f6cef12199c3a8f"}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default function Home({ fontFamily }) {
return <div className={_JSXStyle.dynamic([
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default class {
render() {
return <div className={_JSXStyle.dynamic([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default class {
render() {
return <div className={_JSXStyle.dynamic([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default class {
render() {
return <div className={_JSXStyle.dynamic([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default class {
render() {
return <div className={_JSXStyle.dynamic([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default class {
render() {
return <div className={_JSXStyle.dynamic([
Expand Down

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=><div className={"jsx-53fd644ab080300c"}>

<p className={"jsx-53fd644ab080300c"}>test</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=><div className={"jsx-1f7963ae04c6466a"}>

<p className={"jsx-1f7963ae04c6466a"}>test</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=><div className={"jsx-1a19bb4817c105dd"}>

<p className={"jsx-1a19bb4817c105dd"}>test</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=><div className={"jsx-938ca197692ef624"}>

<p className={"jsx-938ca197692ef624"}>test</p>
Expand Down

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _JSXStyle from "styled-jsx/style";
import _JSXStyle from "next/dist/shared/lib/styled-jsx";
export default (()=><div className={"jsx-94239b6d6b42c9b5"}>

<p className={"jsx-94239b6d6b42c9b5"}>test</p>
Expand Down
6 changes: 3 additions & 3 deletions packages/next/build/babel/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ type StyledJsxPlugin = [string, any] | string
type StyledJsxBabelOptions =
| {
plugins?: StyledJsxPlugin[]
styleModule?: string
'babel-test'?: boolean
}
| undefined

// Resolve styled-jsx plugins
function styledJsxOptions(options: StyledJsxBabelOptions) {
if (!options) {
return {}
}
options = options || {}
options.styleModule = 'next/dist/shared/lib/styled-jsx'

if (!Array.isArray(options.plugins)) {
return options
Expand Down
1 change: 1 addition & 0 deletions packages/next/shared/lib/styled-jsx.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function JSXStyle(props: any): null
1 change: 1 addition & 0 deletions packages/next/shared/lib/styled-jsx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('styled-jsx/style')
35 changes: 35 additions & 0 deletions test/e2e/styled-jsx/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils'
import cheerio from 'cheerio'

describe('styled-jsx', () => {
let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
export default function Page() {
return (
<div>
<style jsx>{'p { color: red; }'}</style>
<p>hello world</p>
</div>
)
}
`,
},
...(!!process.env.PKG_MANAGER && {
installCommand: `${process.env.PKG_MANAGER} install`,
}),
})
})
afterAll(() => next.destroy())

it('should contain styled-jsx styles in html', async () => {
const html = await renderViaHTTP(next.url, '/')
const $ = cheerio.load(html)
expect($('head').text()).toContain('color:red')
})
})