File tree Expand file tree Collapse file tree 4 files changed +16
-17
lines changed Expand file tree Collapse file tree 4 files changed +16
-17
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- exports . addon = function ( renderer , id ) {
4
- id = id || 'nano-css' ;
5
-
3
+ exports . addon = function ( renderer ) {
6
4
if ( process . env . NODE_ENV !== 'production' ) {
7
5
require ( './__dev__/warnOnMissingDependencies' ) ( 'hydrate' , renderer , [ 'put' ] ) ;
8
6
}
9
7
10
8
if ( renderer . client ) {
11
9
var hydrated = { } ;
12
- var stylesheet = document . getElementById ( id ) ;
10
+ var stylesheet = renderer . sh ;
13
11
14
12
if ( ! stylesheet ) {
15
13
if ( process . env . NODE_ENV !== 'production' ) {
16
- console . error ( 'Hydration stylesheet with id "' + id + '" was not found.') ;
14
+ console . error ( 'Hydration style sheet was not found.' ) ;
17
15
}
18
16
19
17
return ;
Original file line number Diff line number Diff line change @@ -12,8 +12,12 @@ html += `<style>${nano.raw}</style>`;
12
12
## Re-hydrating
13
13
14
14
` nano-css ` can re-hydrate server-side generated CSS. To do that, you need to install [ ` hydrate ` addon] ( hydrate.md ) ;
15
- and set ` nano-css ` id on your ` <style> ` element .
15
+ and provide style sheet you want to hydrate to the ` nano-css ` instance when creating it .
16
16
17
17
``` js
18
+ const nano = create ({
19
+ sh: typeof document === ' object' ? document .getElementById (' nano-css' ) : null
20
+ });
21
+
18
22
html += ` <style id="nano-css">${ nano .raw } </style>` ;
19
23
```
Original file line number Diff line number Diff line change @@ -6,20 +6,16 @@ Re-hydrates CSS styles generated on the server. On the server add `nano-css` id
6
6
html += ` <style id="nano-css">${ nano .raw } </style>` ;
7
7
```
8
8
9
- That's it! ` hydrate ` addon will find this stylesheet in the browser and will not emit CSS
10
- rules that were already generated by the server.
11
-
12
-
13
- ## Configuration
14
-
15
- You can set a custom id for you style sheet.
9
+ And when creating ` nano-css ` instance provide that style sheet in configuration.
16
10
17
11
``` js
18
- import { addon as addonHydrate } from ' nano-css/addon/hydrate ' ;
19
-
20
- addonHydrate (nano, ' custom-id ' );
12
+ const nano = create ({
13
+ sh : typeof document === ' object ' ? document . getElementById ( ' nano-css ' ) : null
14
+ } );
21
15
```
22
16
17
+ That's it!
18
+
23
19
24
20
## Installation
25
21
Original file line number Diff line number Diff line change @@ -39,7 +39,8 @@ exports.create = function (config) {
39
39
} , config ) ;
40
40
41
41
if ( renderer . client ) {
42
- document . head . appendChild ( renderer . sh = document . createElement ( 'style' ) ) ;
42
+ if ( ! renderer . sh )
43
+ document . head . appendChild ( renderer . sh = document . createElement ( 'style' ) ) ;
43
44
44
45
renderer . putRaw = function ( rawCssRule ) {
45
46
if ( process . env . NODE_ENV === 'production' ) {
You can’t perform that action at this time.
0 commit comments