Unverified Commit 564eac47 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix styled-jsx not rendering when used in node_modules (#7697)

* Don't transpile styled-jsx in server mode

* Add test fo styled-jsx-module

* Add styled-jsx as dependency of next-server
parent 15bcdab5
......@@ -49,6 +49,7 @@
"raw-body": "2.4.0",
"react-is": "16.8.6",
"send": "0.16.1",
"styled-jsx": "3.2.1",
"url": "0.11.0"
},
"peerDependencies": {
......
......@@ -231,11 +231,6 @@ export default async function getBaseWebpackConfig(
return callback()
}
// styled-jsx has to be transpiled
if (res.match(/node_modules[/\\]styled-jsx/)) {
return callback()
}
if (res.match(/node_modules[/\\].*\.js$/)) {
return callback(undefined, `commonjs ${request}`)
}
......
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var _JSXStyle = _interopDefault(require('styled-jsx/style'));
var React = require('react');
function Button() {
return React.createElement("button", {
className: "jsx-451104437"
}, "hello", React.createElement(_JSXStyle, {
id: "451104437"
}, ".jsx-451104437{color:cyan;}\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkJ1dHRvbi50c3giXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBTWtCLEFBRW1CLFVBQ1oiLCJmaWxlIjoiQnV0dG9uLnRzeCIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCAqIGFzIFJlYWN0IGZyb20gJ3JlYWN0JztcblxuZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24gQnV0dG9uKCkge1xuICByZXR1cm4gKFxuICAgIDxidXR0b24+XG4gICAgICBoZWxsb1xuICAgICAgPHN0eWxlIGpzeD57YFxuICAgICAgICBjb2xybzogcmVkO1xuICAgICAgYH08L3N0eWxlPlxuICAgIDwvYnV0dG9uPlxuICApO1xufVxuIl19 */\n/*@ sourceURL=Button.tsx */"));
}
/**
* @class ExampleComponent
*/
exports.Button = Button;
\ No newline at end of file
{
"name": "my-comps",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
{
"name": "styled-jsx-module",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
import { Button } from 'my-comps/button'
export const config = { amp: true }
const Index = () => (
<>
<p>Hello world</p>
<Button>Click me</Button>
</>
)
export default Index
import { Button } from 'my-comps/button'
const Index = () => (
<>
<p>Hello world</p>
<Button>Click me</Button>
</>
)
export default Index
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import webdriver from 'next-webdriver'
import {
killApp,
findPort,
nextStart,
nextBuild,
launchApp,
renderViaHTTP
} from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
const appDir = join(__dirname, '../app')
let appPort
let app
function runTests () {
it('should render styles during CSR', async () => {
const browser = await webdriver(appPort, '/')
const color = await browser.eval(
`getComputedStyle(document.querySelector('button')).color`
)
expect(color).toMatch('0, 255, 255')
})
it('should render styles during CSR (AMP)', async () => {
const browser = await webdriver(appPort, '/amp')
const color = await browser.eval(
`getComputedStyle(document.querySelector('button')).color`
)
expect(color).toMatch('0, 255, 255')
})
it('should render styles during SSR', async () => {
const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/color:.*?cyan/)
})
it('should render styles during SSR (AMP)', async () => {
const html = await renderViaHTTP(appPort, '/amp')
expect(html).toMatch(/color:.*?cyan/)
})
}
describe('styled-jsx using in node_modules', () => {
describe('Production', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
describe('Development', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
})
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