Skip to content

Commit 662feda

Browse files
viacheslafffahad19
authored andcommitted
Fix conflict between render and component props in Route component (#379)
* Fix conflict between render and component props in Route component * Ignore code coverage for dummy prop function in test
1 parent 389b9c7 commit 662feda

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

packages/frint-router-component-handlers/src/createRouteHandler.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ const RouteHandler = {
5151
},
5252

5353
_calculateComponentState(nextProps, appChanged = false) {
54-
if (nextProps.component) {
54+
if (nextProps.render) {
55+
// render
56+
this.setData('component', null);
57+
} else if (nextProps.component) {
5558
// component
5659
this._destroyRouteApp();
5760

packages/frint-router-component-handlers/src/createRouteHandler.spec.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,58 @@ describe('frint-router-component-handlers › createRouteHandler', function () {
9494
});
9595
});
9696

97+
describe('RouteHandler functions properly with render() throughout lifecycle', function () {
98+
const router = new MemoryRouterService();
99+
100+
const component = createComponent();
101+
const componentToRender = createComponent();
102+
103+
component.props = {
104+
path: '/',
105+
exact: true,
106+
render: function () {
107+
/* istanbul ignore next */
108+
return null;
109+
}
110+
};
111+
112+
const handler = createRouteHandler(
113+
ComponentHandler,
114+
createTestAppInstance(router),
115+
component
116+
);
117+
118+
router.push('/');
119+
120+
it('initially component data is set to null', function () {
121+
component.data = handler.getInitialData();
122+
123+
expect(component.data.component).to.be.null;
124+
});
125+
126+
it('when component prop is set, component data keeps null value', function () {
127+
component.props.component = componentToRender;
128+
handler.propsChange(component.props, false, false, false);
129+
130+
expect(component.data.component).to.be.null;
131+
});
132+
133+
it('when render() prop is removed, component data is equal to component prop', function () {
134+
component.props.render = undefined;
135+
handler.propsChange(component.props, false, false, false);
136+
137+
expect(component.data.component).to.equal(componentToRender);
138+
});
139+
140+
it('when render() prop is set and component prop removed, component data equals to null', function () {
141+
component.props.component = undefined;
142+
component.props.render = () => null;
143+
handler.propsChange(component.props, false, false, false);
144+
145+
expect(component.data.component).to.be.null;
146+
});
147+
});
148+
97149
describe('RouteHandler functions properly with computedMatch throughout lifecycle', function () {
98150
const router = new MemoryRouterService();
99151

0 commit comments

Comments
 (0)