-
Notifications
You must be signed in to change notification settings - Fork 293
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
Update browser runtime #409
Merged
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
42c4294
Inject styles experiment
mattcompiles f9d1a15
Get basic inject working
mattcompiles d2fd45c
Add the inject styles entry point
b668abe
Switch to injecting styles
5dcdb77
Deunescape the CSS
b7446ee
Set optimised deps in the plugin
daa2789
Use the integration regex
1375ba9
Strip ?used from ids for fileScope
69f2ff2
Add a changeset for the used stuff
c98ad55
Remove the initial drafts of inject styles
e9f7575
Add a changeset for injectStyles
9de50c9
Add a changeset for the cssMap.delete thing
6f3b817
Clean up the injectStyles from integration
322ff6f
Also update vanilla specific ssr config in vite plugin
7754d15
Clean up the package json from the integration version of injectStyles
bcbae34
More cleanup
83dadee
Remove a word
29594b9
Separate out the vite/browser thing
68219f8
Add a changeset about the deps
dd9d095
Small cleanups in vite plugin
c35d5ad
Merge branch 'master' into inject
ccb8e11
JSBench has spoken
8477c38
Address PR comments
0003de4
Switch to dedent
98bbdf5
Add changeset for integration
e3108b2
Explicitly throw if the filescope is missing
4acd159
Strip the `?used` everywhere
0f4f14e
Add an explanatory comment
8b18442
Migrate everything to outdent
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,9 @@ | ||
--- | ||
'@vanilla-extract/vite-plugin': patch | ||
--- | ||
|
||
Fix plugin for watch mode. | ||
|
||
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. | ||
|
||
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. |
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,10 @@ | ||
--- | ||
'@vanilla-extract/css': patch | ||
--- | ||
|
||
Improve the browser runtime dev experience. | ||
|
||
The vanilla browser runtime now creates style tags containing the CSS itself, rather than injecting it directly into the CSSOM. | ||
|
||
This helps with debugability, as the generated CSS can actually be seen in the devtools. | ||
There are also some new attributes set on the style tags, making it easier to identify the source of each style. |
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,9 @@ | ||
--- | ||
'@vanilla-extract/vite-plugin': patch | ||
--- | ||
|
||
Update the "vanilla-extract" devStyleRuntime option. | ||
|
||
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. | ||
|
||
This allows for hot reloading of styles, and makes styles a bit easier to debug at dev time (because they're actually visible). |
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,10 @@ | ||
--- | ||
'@vanilla-extract/babel-plugin': patch | ||
'@vanilla-extract/vite-plugin': patch | ||
--- | ||
|
||
Handle vite 2.6. | ||
|
||
As of vite 2.6 and greater, `?used` gets appended to css imports, which causes the file imports to be not what we expected. | ||
|
||
This caused mismatching classnames in the vite plugin, and it caused the babel plugin to not add filescopes when it should have. |
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,10 @@ | ||
--- | ||
'@vanilla-extract/vite-plugin': patch | ||
--- | ||
|
||
Automatically optimize deps. | ||
|
||
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. | ||
|
||
The plugin will now add the dependency to optimizeDeps if the vanilla runtime is being used so that it's optimized up front. | ||
It also ensures that some relevant vanilla packages are externalised in SSR mode. |
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 @@ | ||
--- | ||
'@vanilla-extract/integration': patch | ||
--- | ||
|
||
Export the fileScope functions. | ||
|
||
`stringifyFileScope` and `parseFileScope` are now exported to be used in other packages. |
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,8 @@ | ||
{ | ||
"main": "dist/vanilla-extract-css-injectStyles.cjs.js", | ||
"module": "dist/vanilla-extract-css-injectStyles.esm.js", | ||
"browser": { | ||
"./dist/vanilla-extract-css-injectStyles.cjs.js": "./dist/vanilla-extract-css-injectStyles.browser.cjs.js", | ||
"./dist/vanilla-extract-css-injectStyles.esm.js": "./dist/vanilla-extract-css-injectStyles.browser.esm.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
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,30 @@ | ||
import type { FileScope } from './types'; | ||
|
||
const stylesheets: Record<string, HTMLElement> = {}; | ||
|
||
interface InjectStylesOptions { | ||
fileScope: FileScope; | ||
css: string; | ||
} | ||
export const injectStyles = ({ fileScope, css }: InjectStylesOptions) => { | ||
const fileScopeId = fileScope.packageName | ||
? [fileScope.packageName, fileScope.filePath].join('/') | ||
: fileScope.filePath; | ||
|
||
let stylesheet = stylesheets[fileScopeId]; | ||
|
||
if (!stylesheet) { | ||
const styleEl = document.createElement('style'); | ||
|
||
if (fileScope.packageName) { | ||
styleEl.setAttribute('data-package', fileScope.packageName); | ||
} | ||
|
||
styleEl.setAttribute('data-file', fileScope.filePath); | ||
styleEl.setAttribute('type', 'text/css'); | ||
stylesheet = stylesheets[fileScopeId] = styleEl; | ||
document.head.appendChild(styleEl); | ||
} | ||
|
||
stylesheet.innerHTML = 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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add a changeset for the integration package