Skip to content

Commit

Permalink
mark the twind style sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
sastan committed Jan 31, 2022
1 parent 7e9d1ce commit 39001d2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .changeset/fresh-mails-whisper.md
@@ -0,0 +1,12 @@
---
'twind': patch
---

mark the twind style sheet

```html
<!-- the SSR stylesheet -->
<style data-twind="ssr"></style>
<!-- the client stylesheet -->
<style data-twind></style>
```
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -50,13 +50,13 @@
"path": "packages/twind/dist/twind.esnext.js",
"import": "{ setup }",
"brotli": true,
"limit": "4.4kb"
"limit": "4.45kb"
},
{
"name": "@twind/cdn",
"path": "packages/cdn/dist/cdn.esnext.js",
"brotli": true,
"limit": "14.65kb"
"limit": "14.7kb"
},
{
"name": "@twind/tailwind",
Expand Down
2 changes: 1 addition & 1 deletion packages/cdn/package.json
Expand Up @@ -29,7 +29,7 @@
"name": "@twind/cdn",
"path": "dist/cdn.esnext.js",
"brotli": true,
"limit": "14.65kb"
"limit": "14.7kb"
}
],
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/twind/package.json
Expand Up @@ -36,7 +36,7 @@
"path": "dist/twind.esnext.js",
"import": "{ setup }",
"brotli": true,
"limit": "4.4kb"
"limit": "4.45kb"
},
{
"name": "twind (twind + cssom)",
Expand Down
3 changes: 2 additions & 1 deletion packages/twind/src/sheets.ts
Expand Up @@ -7,14 +7,15 @@ declare global {
}
}

let el: HTMLStyleElement
function createStyleElement(
// 1. look for existing style element — usually from SSR
// 2. append to document.head — this assumes that document.head has at least one child node
referenceNode = document.querySelector('style[data-twind]') || (document.head.lastChild as Node),
): HTMLStyleElement {
// insert new style element after existing element which allows to override styles
return (referenceNode.parentNode as Node).insertBefore(
document.createElement('style'),
((el = document.createElement('style')), (el.dataset.twind = ''), el),
referenceNode.nextSibling,
)
}
Expand Down

0 comments on commit 39001d2

Please sign in to comment.