Skip to content

Commit a9c5cb7

Browse files
author
Ben Jervis
authored
Update browser runtime (#409)
1 parent e250423 commit a9c5cb7

File tree

23 files changed

+219
-123
lines changed

23 files changed

+219
-123
lines changed

.changeset/chilled-goats-fold.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@vanilla-extract/vite-plugin': patch
3+
---
4+
5+
Fix plugin for watch mode.
6+
7+
The vite plugin previously relied on a one to one matching of resolve to load calls, and would clean up the CSS stored in memory after it was loaded.
8+
9+
This isn't true in `--watch` mode, as the same file can be loaded on the rebuild without having to be resolved, which the plugin now handles.

.changeset/khaki-taxis-tell.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@vanilla-extract/css': patch
3+
---
4+
5+
Improve the browser runtime dev experience.
6+
7+
The vanilla browser runtime now creates style tags containing the CSS itself, rather than injecting it directly into the CSSOM.
8+
9+
This helps with debugability, as the generated CSS can actually be seen in the devtools.
10+
There are also some new attributes set on the style tags, making it easier to identify the source of each style.

.changeset/polite-rings-nail.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@vanilla-extract/vite-plugin': patch
3+
---
4+
5+
Update the "vanilla-extract" devStyleRuntime option.
6+
7+
When using the vanilla browser runtime in vite, it now operates on a new model where a .css.js file is generated, that uses @vanilla-extract/css/injectStyles to add the css to the browser.
8+
9+
This allows for hot reloading of styles, and makes styles a bit easier to debug at dev time (because they're actually visible).

.changeset/pretty-carrots-drive.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@vanilla-extract/babel-plugin': patch
3+
'@vanilla-extract/vite-plugin': patch
4+
---
5+
6+
Handle vite 2.6.
7+
8+
As of vite 2.6 and greater, `?used` gets appended to css imports, which causes the file imports to be not what we expected.
9+
10+
This caused mismatching classnames in the vite plugin, and it caused the babel plugin to not add filescopes when it should have.

.changeset/strong-zebras-prove.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@vanilla-extract/vite-plugin': patch
3+
---
4+
5+
Automatically optimize deps.
6+
7+
When using the new vanilla browser runtime, the new `injectStyles` dependency gets injected at runtime, so vite can't discover it ahead of time and pre-bundle it.
8+
9+
The plugin will now add the dependency to optimizeDeps if the vanilla runtime is being used so that it's optimized up front.
10+
It also ensures that some relevant vanilla packages are externalised in SSR mode.

.changeset/tiny-baboons-roll.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@vanilla-extract/integration': patch
3+
---
4+
5+
Export the fileScope functions.
6+
7+
`stringifyFileScope` and `parseFileScope` are now exported to be used in other packages.

packages/babel-plugin/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { relative, posix, sep } from 'path';
22
import { types as t, PluginObj, PluginPass, NodePath } from '@babel/core';
33
import template from '@babel/template';
4-
import { getPackageInfo } from '@vanilla-extract/integration';
4+
import { cssFileFilter, getPackageInfo } from '@vanilla-extract/integration';
55

66
const packageIdentifiers = new Set([
77
'@vanilla-extract/css',
@@ -183,7 +183,7 @@ export default function (): PluginObj<Context> {
183183
}
184184

185185
this.isESM = false;
186-
this.isCssFile = /\.css\.(js|ts|jsx|tsx)$/.test(opts.filename);
186+
this.isCssFile = cssFileFilter.test(opts.filename);
187187
this.alreadyCompiled = false;
188188

189189
this.importIdentifiers = new Map();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"main": "dist/vanilla-extract-css-injectStyles.cjs.js",
3+
"module": "dist/vanilla-extract-css-injectStyles.esm.js",
4+
"browser": {
5+
"./dist/vanilla-extract-css-injectStyles.cjs.js": "./dist/vanilla-extract-css-injectStyles.browser.cjs.js",
6+
"./dist/vanilla-extract-css-injectStyles.esm.js": "./dist/vanilla-extract-css-injectStyles.browser.esm.js"
7+
}
8+
}

packages/css/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"adapter.ts",
1818
"transformCss.ts",
1919
"fileScope.ts",
20+
"injectStyles.ts",
2021
"disableRuntimeStyles.ts"
2122
]
2223
},
@@ -27,6 +28,7 @@
2728
"/adapter",
2829
"/transformCss",
2930
"/fileScope",
31+
"/injectStyles",
3032
"/disableRuntimeStyles"
3133
],
3234
"repository": {
@@ -43,12 +45,11 @@
4345
"css-what": "^5.0.1",
4446
"cssesc": "^3.0.0",
4547
"csstype": "^3.0.7",
46-
"dedent": "^0.7.0",
4748
"deep-object-diff": "^1.1.0",
48-
"deepmerge": "^4.2.2"
49+
"deepmerge": "^4.2.2",
50+
"outdent": "^0.8.0"
4951
},
5052
"devDependencies": {
51-
"@types/cssesc": "^3.0.0",
52-
"@types/dedent": "^0.7.0"
53+
"@types/cssesc": "^3.0.0"
5354
}
5455
}

packages/css/src/fileScope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import dedent from 'dedent';
1+
import outdent from 'outdent';
22
import { onEndFileScope } from './adapter';
33
import type { FileScope } from './types';
44

@@ -27,7 +27,7 @@ export function hasFileScope() {
2727
export function getFileScope(): FileScope {
2828
if (fileScopes.length === 0) {
2929
throw new Error(
30-
dedent`
30+
outdent`
3131
Styles were unable to be assigned to a file. This is generally caused by one of the following:
3232
3333
- You may have created styles outside of a '.css.ts' context

0 commit comments

Comments
 (0)