makeomatic / makeomatic/redux-connect

Component attempts to render before asyncConnect promise is fired/resolved

Open
#136 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
545
Forks
61
PR merge metrics
No merged PRs in 30d

Description

I'm exporting my component as follows:
```
export default asyncConnect([{ promise: loadAsyncProps }])(
connect(
mapStateToProps,
mapDispatchToProps,
)(MyComponent),
);
```
And using it in router config like this:
```
[
{
path: '/',
component: Root,
routes: [
{
path: '/',
exact: true,
component: Home,
},
{
path: '/my-route',
exact: true,
component: MyAsyncConnectedComponent,
},
},
];
```

Home component doesn't use asyncConnect. It works fine. MyComponent works only when clicking to /my-route through a link in Home.

When entering /my-route in any other way (address bar, hot reload etc.), the inner component, in this case the react-redux connected MyComponent, is rendered without the promise even firing.

MyComponent uses data fetched with asyncConnect, and the component crashes because props are null.

I'm not using SSR.

Library versions:
```
redux-connect: 9.0.0
react-redux: 7.0.0
react-router: 5.0.0
react: 16.8.6
redux: 4.0.1
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the router configuration and asyncConnect usage shown in the issue, then reproduce direct navigation or hot reload versus clicking through from Home. Trace when the promise is invoked relative to MyComponent rendering; done means the promise runs before the connected component needs its data and the null-props crash no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.