-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: preserve classes created by explicit
tw
calls during SSR
- Loading branch information
Showing
9 changed files
with
294 additions
and
167 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,42 @@ | ||
--- | ||
'twind': patch | ||
--- | ||
|
||
feat: preserve classes created by explicit `tw` calls during SSR | ||
|
||
Previously `inline` and `extract` cleared the `tw` instance before parsing the html assuming that all classes are available via `class` attributes. That led to missing styles from `injectGlobal` or explicit `tw` calls. | ||
|
||
This change introduces a `snaphot` method on `tw` and sheet instances which allows to preserve the classes that are created by explicit `tw` calls. | ||
|
||
**Default Mode** _(nothing changed here)_ | ||
|
||
```js | ||
import { inline } from 'twind' | ||
|
||
function render() { | ||
return inline(renderApp()) | ||
} | ||
``` | ||
|
||
**Library Mode** | ||
|
||
```js | ||
import { tw, stringify } from 'twind' | ||
|
||
function render() { | ||
// remember global classes | ||
const restore = tw.snapshot() | ||
|
||
// generated html | ||
const html = renderApp() | ||
|
||
// create CSS | ||
const css = stringify(tw.target) | ||
|
||
// restore global classes | ||
restore() | ||
|
||
// inject as last element into the head | ||
return html.replace('</head>', `<style data-twind>${css}</style></head>`) | ||
} | ||
``` |
This file was deleted.
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 was deleted.
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
Oops, something went wrong.