File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use strict' ;
22
3- exports . addon = function ( renderer , id ) {
4- id = id || 'nano-css' ;
5-
3+ exports . addon = function ( renderer ) {
64 if ( process . env . NODE_ENV !== 'production' ) {
75 require ( './__dev__/warnOnMissingDependencies' ) ( 'hydrate' , renderer , [ 'put' ] ) ;
86 }
97
108 if ( renderer . client ) {
119 var hydrated = { } ;
12- var stylesheet = document . getElementById ( id ) ;
10+ var stylesheet = renderer . sh ;
1311
1412 if ( ! stylesheet ) {
1513 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.' ) ;
1715 }
1816
1917 return ;
Original file line number Diff line number Diff line change @@ -12,8 +12,12 @@ html += `<style>${nano.raw}</style>`;
1212## Re-hydrating
1313
1414` 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 .
1616
1717``` js
18+ const nano = create ({
19+ sh: typeof document === ' object' ? document .getElementById (' nano-css' ) : null
20+ });
21+
1822html += ` <style id="nano-css">${ nano .raw } </style>` ;
1923```
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
66html += ` <style id="nano-css">${ nano .raw } </style>` ;
77```
88
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.
1610
1711``` 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+ } );
2115```
2216
17+ That's it!
18+
2319
2420## Installation
2521
Original file line number Diff line number Diff line change @@ -39,7 +39,8 @@ exports.create = function (config) {
3939 } , config ) ;
4040
4141 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' ) ) ;
4344
4445 renderer . putRaw = function ( rawCssRule ) {
4546 if ( process . env . NODE_ENV === 'production' ) {
You can’t perform that action at this time.
0 commit comments