Skip to content

Commit 48411b4

Browse files
Fix effects breaking in SSR due to missing _renderCallbacks (#124)
Fix effects breaking in SSR due to missing _renderCallbacks
2 parents e726143 + 6705b39 commit 48411b4

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"eslint-config-developit": "^1.1.1",
7878
"microbundle": "^0.6.0",
7979
"mocha": "^5.2.0",
80-
"preact": "^10.0.0-alpha.0",
80+
"preact": "^10.0.4",
8181
"sinon": "^1.17.5",
8282
"sinon-chai": "^2.8.0",
8383
"typescript": "^3.4.1"

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ function renderToString(vnode, context, opts, inner, isSvgMode, selectValue) {
7676
else {
7777
let rendered;
7878

79-
let c = vnode.__c = { __v: vnode, context, props: vnode.props };
79+
let c = vnode.__c = { __v: vnode, context, props: vnode.props, __h: [] };
80+
8081
// options.render
8182
if (options.__r) options.__r(vnode);
8283

test/render.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { render, shallowRender } from '../src';
22
import { h, Component, createContext, Fragment } from 'preact';
3-
import { useState, useContext, useEffect } from 'preact/hooks';
3+
import { useState, useContext, useEffect, useLayoutEffect } from 'preact/hooks';
44
import chai, { expect } from 'chai';
55
import { spy, stub, match } from 'sinon';
66
import sinonChai from 'sinon-chai';
@@ -711,6 +711,25 @@ describe('render', () => {
711711
}).to.not.throw();
712712
});
713713

714+
it('should not crash with effectful hooks', () => {
715+
function Foo() {
716+
useEffect(() => {
717+
// Nothing
718+
}, []);
719+
720+
useLayoutEffect(() => {
721+
// Nothing
722+
}, []);
723+
724+
return <div />;
725+
}
726+
727+
// eslint-disable-next-line prefer-arrow-callback
728+
expect(function() {
729+
render(<Foo />);
730+
}).to.not.throw();
731+
});
732+
714733
it('should work with useContext and default value', () => {
715734
let Ctx = createContext('foo');
716735
function Foo() {

0 commit comments

Comments
 (0)