Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
ab4ba041
Unverified
Commit
ab4ba041
authored
Apr 10, 2020
by
JJ Kasper
Committed by
GitHub
Apr 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace brackets in CSS classes for dynamic routes (#11795)
parent
0648c355
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
136 additions
and
13 deletions
+136
-13
getCssModuleLocalIdent.ts
...bpack/config/blocks/css/loaders/getCssModuleLocalIdent.ts
+18
-13
index.js
...n/css-fixtures/dynamic-route-module/pages/[post]/index.js
+7
-0
index.module.css
...xtures/dynamic-route-module/pages/[post]/index.module.css
+3
-0
index.test.js
test/integration/css-modules/test/index.test.js
+49
-0
index.js
.../scss-fixtures/dynamic-route-module/pages/[post]/index.js
+7
-0
index.module.scss
...tures/dynamic-route-module/pages/[post]/index.module.scss
+3
-0
index.test.js
test/integration/scss-modules/test/index.test.js
+49
-0
No files found.
packages/next/build/webpack/config/blocks/css/loaders/getCssModuleLocalIdent.ts
View file @
ab4ba041
...
...
@@ -29,17 +29,22 @@ export function getCssModuleLocalIdent(
)
// Have webpack interpolate the `[folder]` or `[name]` to its real value.
return
loaderUtils
.
interpolateName
(
context
,
fileNameOrFolder
+
'_'
+
exportName
+
'__'
+
hash
,
options
)
.
replace
(
// Webpack name interpolation returns `about.module_root__2oFM9` for
// `.root {}` inside a file named `about.module.css`. Let's simplify
// this.
/
\.
module_/
,
'_'
)
return
(
loaderUtils
.
interpolateName
(
context
,
fileNameOrFolder
+
'_'
+
exportName
+
'__'
+
hash
,
options
)
.
replace
(
// Webpack name interpolation returns `about.module_root__2oFM9` for
// `.root {}` inside a file named `about.module.css`. Let's simplify
// this.
/
\.
module_/
,
'_'
)
// replace `[` and `]` from dynamic routes as they aren't valid
// characters for CSS names
.
replace
(
/
(\[
|
\])
/g
,
'_'
)
)
}
test/integration/css-fixtures/dynamic-route-module/pages/[post]/index.js
0 → 100644
View file @
ab4ba041
import
styles
from
'./index.module.css'
export
default
()
=>
(
<
div
className
=
{
styles
.
home
}
id
=
"my-div"
>
hello
world
<
/div
>
)
test/integration/css-fixtures/dynamic-route-module/pages/[post]/index.module.css
0 → 100644
View file @
ab4ba041
.home
{
background
:
#f00
;
}
test/integration/css-modules/test/index.test.js
View file @
ab4ba041
...
...
@@ -449,3 +449,52 @@ describe('CSS Module Composes Usage (External)', () => {
)
})
})
describe
(
'Dynamic Route CSS Module Usage'
,
()
=>
{
// This is a very bad feature. Do not use it.
const
appDir
=
join
(
fixturesDir
,
'dynamic-route-module'
)
let
stdout
let
code
let
app
let
appPort
beforeAll
(
async
()
=>
{
await
remove
(
join
(
appDir
,
'.next'
))
;({
code
,
stdout
}
=
await
nextBuild
(
appDir
,
[],
{
stdout
:
true
,
}))
appPort
=
await
findPort
()
app
=
await
nextStart
(
appDir
,
appPort
)
})
afterAll
(()
=>
killApp
(
app
))
it
(
'should have compiled successfully'
,
()
=>
{
expect
(
code
).
toBe
(
0
)
expect
(
stdout
).
toMatch
(
/Compiled successfully/
)
})
it
(
'should apply styles correctly'
,
async
()
=>
{
const
browser
=
await
webdriver
(
appPort
,
'/post-1'
)
const
background
=
await
browser
.
elementByCss
(
'#my-div'
)
.
getComputedCss
(
'background-color'
)
expect
(
background
).
toMatch
(
/rgb
(
a|
)\(
255, 0, 0/
)
})
it
(
`should've emitted a single CSS file`
,
async
()
=>
{
const
cssFolder
=
join
(
appDir
,
'.next/static/css'
)
const
files
=
await
readdir
(
cssFolder
)
const
cssFiles
=
files
.
filter
(
f
=>
/
\.
css$/
.
test
(
f
))
expect
(
cssFiles
.
length
).
toBe
(
1
)
const
cssContent
=
await
readFile
(
join
(
cssFolder
,
cssFiles
[
0
]),
'utf8'
)
expect
(
cssContent
.
replace
(
/
\/\*
.*
?\*\/
/g
,
''
).
trim
()).
toMatchInlineSnapshot
(
`"._post__home__2Cy-L{background:red}"`
)
})
})
test/integration/scss-fixtures/dynamic-route-module/pages/[post]/index.js
0 → 100644
View file @
ab4ba041
import
styles
from
'./index.module.scss'
export
default
()
=>
(
<
div
className
=
{
styles
.
home
}
id
=
"my-div"
>
hello
world
<
/div
>
)
test/integration/scss-fixtures/dynamic-route-module/pages/[post]/index.module.scss
0 → 100644
View file @
ab4ba041
.home
{
background
:
#f00
;
}
test/integration/scss-modules/test/index.test.js
View file @
ab4ba041
...
...
@@ -448,3 +448,52 @@ describe('CSS Module Composes Usage (External)', () => {
)
})
})
describe
(
'Dynamic Route CSS Module Usage'
,
()
=>
{
// This is a very bad feature. Do not use it.
const
appDir
=
join
(
fixturesDir
,
'dynamic-route-module'
)
let
stdout
let
code
let
app
let
appPort
beforeAll
(
async
()
=>
{
await
remove
(
join
(
appDir
,
'.next'
))
;({
code
,
stdout
}
=
await
nextBuild
(
appDir
,
[],
{
stdout
:
true
,
}))
appPort
=
await
findPort
()
app
=
await
nextStart
(
appDir
,
appPort
)
})
afterAll
(()
=>
killApp
(
app
))
it
(
'should have compiled successfully'
,
()
=>
{
expect
(
code
).
toBe
(
0
)
expect
(
stdout
).
toMatch
(
/Compiled successfully/
)
})
it
(
`should've emitted a single CSS file`
,
async
()
=>
{
const
cssFolder
=
join
(
appDir
,
'.next/static/css'
)
const
files
=
await
readdir
(
cssFolder
)
const
cssFiles
=
files
.
filter
(
f
=>
/
\.
css$/
.
test
(
f
))
expect
(
cssFiles
.
length
).
toBe
(
1
)
const
cssContent
=
await
readFile
(
join
(
cssFolder
,
cssFiles
[
0
]),
'utf8'
)
expect
(
cssContent
.
replace
(
/
\/\*
.*
?\*\/
/g
,
''
).
trim
()).
toMatchInlineSnapshot
(
`"._post__home__3F5yW{background:red}"`
)
})
it
(
'should apply styles correctly'
,
async
()
=>
{
const
browser
=
await
webdriver
(
appPort
,
'/post-1'
)
const
background
=
await
browser
.
elementByCss
(
'#my-div'
)
.
getComputedCss
(
'background-color'
)
expect
(
background
).
toMatch
(
/rgb
(
a|
)\(
255, 0, 0/
)
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment