Skip to content

Commit 1156e82

Browse files
Merge pull request #193 from preactjs/JoviDeCroock-patch-1
2 parents 1da1bdb + f1c0313 commit 1156e82

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,21 @@ const EMPTY_ARR = [];
4747
function renderToString(vnode, context, opts) {
4848
context = context || {};
4949
opts = opts || {};
50+
51+
// Performance optimization: `renderToString` is synchronous and we
52+
// therefore don't execute any effects. To do that we pass an empty
53+
// array to `options._commit` (`__c`). But we can go one step further
54+
// and avoid a lot of dirty checks and allocations by setting
55+
// `options._skipEffects` (`__s`) too.
56+
const previousSkipEffects = options.__s;
57+
options.__s = true;
58+
5059
const res = _renderToString(vnode, context, opts);
60+
5161
// options._commit, we don't schedule any effects in this library right now,
5262
// so we can pass an empty queue to this hook.
5363
if (options.__c) options.__c(vnode, EMPTY_ARR);
64+
options.__s = previousSkipEffects;
5465
return res;
5566
}
5667

0 commit comments

Comments
 (0)