question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support for defer: true

See original GitHub issue

In redux-async-connect I was able to utilize a defer: true option in order to defer the fetching of the data until after the view has transitioned. After switching to redux-connect it seems like that use case is no longer supported.

Are there plans to add this functionality back in? My specific use case is that when I fetch an external entity I keep its data in my store along with a loaded flag and only fetch the data if loaded is false . In some cases when I transition away from this entity’s view I will set its loaded flag back to false, but not clear out the data. The result is that if I navigate back to that view I’m able to immediately display previously loaded data while the fresh data is fetched from the server, resulting in a much faster perceived page speed.

Admittedly, I’m not sure how much of that logic was built into redux-async-connect and how much of it was manually implemented via the react-redux-universal-hot-example that my app is based off of. All I can say for sure is that when switching to redux-connect if you navigate to a page with deferred: true then the data loads fine if its coming from the server, but if its a page transition in the client the data never loads.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

11reactions
jaraquistaincommented, May 16, 2016

^ That’s essentially what I ended up with and it’s been working OK for me so far.

Only difference with mine is that my linter enforces a consistent return statement so my promise is:

const result = !isLoaded(getState()) ? dispatch(load()) : null;
return __CLIENT__ ? null : result;
2reactions
AVVScommented, May 8, 2016

@jaraquistain if you supply key alongside promise - you will be able to check loaded data easier:

use getState().reduxAsyncConnect.loadState[key] to check for loading state, it has 3 props:

{
  loading: Boolean,
  loaded: Boolean,
  error: Object,
}

Also, the response data would be stored at getState().reduxAsyncConnect[key]

Logic for this is here: https://github.com/makeomatic/redux-connect/blob/master/modules/store.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

"defer" | Can I use... Support tables for HTML5, CSS3, etc
The boolean defer attribute on script elements allows the external JavaScript file to run when the DOM is loaded, without delaying page load...
Read more >
HTML script defer Attribute - W3Schools
If the defer attribute is set, it specifies that the script is downloaded in parallel to parsing the page, and executed after the...
Read more >
Browser Compatibility of defer attribute for external scripts
defer attribute for external scripts shows a browser compatibility score of 97. This is a collective score out of 100 to represent browser ......
Read more >
Scripts: async, defer - The Modern JavaScript Tutorial
The defer attribute tells the browser not to wait for the script. Instead, the browser will continue to process the HTML, build DOM....
Read more >
defer attribute (script) HTML & XHTML - Dottoro Web Reference
defer attribute (script) ... Sets whether the script is going to generate any document content. If set to true, then the browser no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found