Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix style compilation for file paths containing webpack template stri…
…ngs (#1247)
- Loading branch information
Showing
21 changed files
with
186 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@vanilla-extract/webpack-plugin': patch | ||
--- | ||
|
||
Fixes a bug that was causing style compilation to fail on paths containing [webpack template strings] such as `[id]` or [Next.js dynamic routes] such as `[slug]`. | ||
|
||
[webpack template strings]: https://webpack.js.org/configuration/output/#template-strings | ||
[next.js dynamic routes]: https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="./src/index.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@fixtures/template-string-paths", | ||
"version": "0.0.1", | ||
"main": "src/index.ts", | ||
"sideEffects": true, | ||
"author": "SEEK", | ||
"private": true, | ||
"dependencies": { | ||
"@vanilla-extract/css": "1.14.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const catchAllSegment = style({ color: 'lime' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const optionalCatchAllSegment = style({ color: 'orchid' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const doubleSquareBracketId = style({ color: 'darkkhaki' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const emptySquareBrackets = style({ color: 'blue' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const singleSquareBracketsId = style({ color: 'tomato' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { emptySquareBrackets } from './[]/index.css'; | ||
import { singleSquareBracketsId } from './[id]/index.css'; | ||
import { doubleSquareBracketId } from './[[id]]/index.css'; | ||
import { catchAllSegment } from './[...slug]/index.css'; | ||
import { optionalCatchAllSegment } from './[[...slug]]/index.css'; | ||
|
||
// Fixture for testing escaping of webpack template strings and Next.js dyanmic routes | ||
// https://webpack.js.org/configuration/output/#template-strings | ||
// https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes | ||
function render() { | ||
document.body.innerHTML = ` | ||
<div class="${emptySquareBrackets}">[] path</div> | ||
<div class="${singleSquareBracketsId}">[id] path</div> | ||
<div class="${doubleSquareBracketId}">[[id]] path</div> | ||
<div class="${catchAllSegment}">[...slug] path</div> | ||
<div class="${optionalCatchAllSegment}">[[...slug]] path</div> | ||
`; | ||
} | ||
|
||
render(); |
7 changes: 7 additions & 0 deletions
7
packages/webpack-plugin/src/__snapshots__/compiler.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`escapeWebpackTemplateString() /some/path/[...slug].js pattern 1`] = `"/some/path/[...slug].js"`; | ||
|
||
exports[`escapeWebpackTemplateString() /some/path/[[...slug]]/index.js pattern 1`] = `"/some/path/[[...slug]]/index.js"`; | ||
|
||
exports[`escapeWebpackTemplateString() /some/path[]/[slug]/[[foo]]/index.js pattern 1`] = `"/some/path[]/[\\slug\\]/[[\\foo\\]]/index.js"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { escapeWebpackTemplateString } from './compiler'; | ||
|
||
describe('escapeWebpackTemplateString()', () => { | ||
test.each([ | ||
'/some/path/[...slug].js', | ||
'/some/path/[[...slug]]/index.js', | ||
'/some/path[]/[slug]/[[foo]]/index.js', | ||
])('%s pattern', (filePath) => { | ||
expect(escapeWebpackTemplateString(filePath)).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { expect } from '@playwright/test'; | ||
import { | ||
getStylesheet, | ||
startFixture, | ||
TestServer, | ||
} from '@vanilla-extract-private/test-helpers'; | ||
|
||
import test from './fixture'; | ||
import { webpack as testCases } from './testCases'; | ||
|
||
testCases.forEach(({ type, mode, snapshotCss = true }) => { | ||
test.describe(`template-string-paths - ${type} (${mode})`, () => { | ||
let server: TestServer; | ||
|
||
test.beforeAll(async ({ port }) => { | ||
server = await startFixture('template-string-paths', { | ||
type, | ||
mode, | ||
basePort: port, | ||
}); | ||
}); | ||
|
||
test('screenshot', async ({ page }) => { | ||
await page.goto(server.url); | ||
|
||
expect(await page.screenshot()).toMatchSnapshot( | ||
'template-string-paths.png', | ||
); | ||
}); | ||
|
||
if (snapshotCss) { | ||
test('CSS @agnostic', async () => { | ||
expect( | ||
await getStylesheet(server.url, server.stylesheet), | ||
).toMatchSnapshot(`template-string-paths-${type}--${mode}.css`); | ||
}); | ||
} | ||
|
||
test.afterAll(async () => { | ||
await server.close(); | ||
}); | ||
}); | ||
}); |
Binary file added
BIN
+14.3 KB
...ths.playwright.ts-snapshots/template-string-paths-Desktop---Chromium-darwin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.2 KB
...aths.playwright.ts-snapshots/template-string-paths-Mobile---Chromium-darwin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions
15
...ing-paths.playwright.ts-snapshots/template-string-paths-mini-css-extract--development.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.\[\]_emptySquareBrackets__13abg9g0 { | ||
color: blue; | ||
} | ||
.\[id\]_singleSquareBracketsId__1d2wsrw0 { | ||
color: tomato; | ||
} | ||
.\[\[id\]\]_doubleSquareBracketId__1aosxxv0 { | ||
color: darkkhaki; | ||
} | ||
.\[\.\.\.slug\]_catchAllSegment__169etlp0 { | ||
color: lime; | ||
} | ||
.\[\[\.\.\.slug\]\]_optionalCatchAllSegment__1kvknas0 { | ||
color: orchid; | ||
} |
15 changes: 15 additions & 0 deletions
15
...ring-paths.playwright.ts-snapshots/template-string-paths-mini-css-extract--production.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
._13abg9g0 { | ||
color: blue; | ||
} | ||
._1d2wsrw0 { | ||
color: tomato; | ||
} | ||
._1aosxxv0 { | ||
color: darkkhaki; | ||
} | ||
._169etlp0 { | ||
color: lime; | ||
} | ||
._1kvknas0 { | ||
color: orchid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters