Skip to content
This repository was archived by the owner on Mar 27, 2018. It is now read-only.

Commit e36cb30

Browse files
author
Ian Wensink
committed
fix(entity-mapper): check for existing state on asyncBootstrap
In the rare case of an entity being rendered twice with the same mapper, in the old situation this would cause the component from being loaded twice. Now, before loading, we check if there was already a state.
1 parent e9d695f commit e36cb30

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/components/EntityMapper.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ class EntityMapper extends Component {
7979
async asyncBootstrap() {
8080
const { mapper, asyncMapper } = this.props;
8181
const { uuid, entityProps } = this.state;
82+
83+
// If this mapper + uuid combination is already in state, use that state
84+
const state = getNested(
85+
() =>
86+
this.context.hnContext.state.entities.find(
87+
e => e.mapper === mapper && e.uuid === uuid,
88+
).componentState,
89+
);
90+
91+
if (state) return true;
92+
8293
this.context.hnContext.state.entities.push({
8394
componentState: await this.loadComponent({
8495
asyncMapper,

0 commit comments

Comments
 (0)