
Security News
Scaling Socket from Zero to 10,000+ Organizations
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.
universal-redux-thunk
Advanced tools
A replacement for Redux's built-in middleware store enhancer to build universal apps.
A Redux store enhancer taking care of promise resolution for building universal apps.
Rendering a Redux application on the server requires you to give up on certain programming patterns. For once you can't use singletons on the server as they would be shared between multiple users. Another issue we encountered is resolving Promises trigger from actions within components. While many Redux boilerplates use custom routers to handle data fetching on the client & server we decided to approach it differently. Our goal was to surface a minimal API that can be plugged into any existing Redux application without adding limitations in the way people built their applications.
To install the stable version run:
npm install --save univeral-redux-thunk
Universal Redux Thunk will catch any Promise returned by redux-thunk middleware. Calling renderUniversal returns a Promise which is fulfilled once all Promises are resolved. It is important to note that mutiple rendering loops will be run on the server depending on how your components are nested. For example if ComponentA has ComponentB as a child and ComponentB has ComponentC as a child, several loops will be run resolving promises in sequence on the way to the leaf child. Try not to deeply nest components with multiple slow running asynchronous actions on the way down.
This library works with a specific set of action types. This allows the library to filter actions in an attempt to detect infinte loops while rendering components, preventing excessive asynchronous actions (API calls, database queries, etc.). Before dispatching an asynchronous action the action.type should contain the word "LOADING", on a succesful response your action.type should contain "LOAD_SUCCESS" and on failure "LOAD_FAILED". This allows coverage for the three possible states of an asynchronous action.
If the same action containing "LOADING", "LOAD_SUCCESS" or "LOAD_FAILED" is detected, the rendering cycle will be aborted and an error thrown. Other action types will be ignored by the the library so you can freely dispatch as many other actions as required. All promises are tracked (promises should have corresponding actions for each of its states which can be tracked).
A small example application is provided at: https://github.com/tom-drake/universal-redux-thunk-example
####Faster Perceived Load Time
The network roundtrips to load all the resources take time. By already pre-rendering the first page impression the user experience can be improved. This becomes even more important in places with high internet latency.
####Search Engine Indexability
Many search engines only rely on server side rendering for indexing. Google have improved their search crawler to index client side rendered content but by rendering the page on the server you simply remove a potential point of failure in indexing.
####Code Reusability & Maintainability
Libraries can be shared between the backend & front-end.
Caching definitely helps to reduce the loading times and can be done easily for the HTML as well as for the code.
JavaScript code is already loaded when starting the server. From experience I saw this can take a couple hundred milliseconds.
While with the initial site can be serve faster with client-side rendering there is no relvant content for the user. The network roundtrips increase the time until the user actually sees relevant content. While with the universal approach it takes a bit longer until the user receives the first page it already comes with the content and the total loading time is faster.
Given the user of redux-thunk it should just work. You may have to do some work to remove the infinite loop issue such as checking that a promise action has not already been dispatched, but this should be no more than a simple if check to check the loading/loaded state of your reducer leaf.
All tools must be ready to work with server-side rendering. Luckily that's the case in the React/Redux eco-sytem:
MIT
FAQs
A replacement for Redux's built-in middleware store enhancer to build universal apps.
We found that universal-redux-thunk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.

Research
Socket Threat Research maps a rare inside look at OtterCookie’s npm-Vercel-GitHub chain, adding 197 malicious packages and evidence of North Korean operators.

Research
Socket researchers identified a malicious Chrome extension that manipulates Raydium swaps to inject an undisclosed SOL transfer, quietly routing fees to an attacker wallet.