Remove safeRenderCompletion and setImmediate hacks
See original GitHub issueThis is a proposal for V2 project, where’s the chance to get rid of setImmediate hacks regarding setState:
- replace calls to custom
setStatewrapper (which usessetImmediatehack) with proper ReactsetStatecalls and with callback where appropriate, and eliminatesetStatewrapper. - remove
safeRenderCompletion - remove any other
setImmediatehacks (at least outside of testing code)
The code to be removed makes assumptions about React behaviour and JS engine performance which don’t work as they changed (and will change) over time.
See discussion at #891 (older: #562)
Related currently open issues: #1164, #1023 (maybe), #544, #513 (maybe), #446 I’m sure there are many other (potentially obscure) errors, mostly race-conditions, coming from this hack. See for example my PR #1068.
There’s the possibility that bugs are raised or performance is degraded by that change, but these problems should always be fixable without a false setImmediate “fix”.
P.S: nice to see that the project gains traction again, thanks for all working on it. We’re happy to contribute!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5 (4 by maintainers)

Top Related StackOverflow Question
After just spending three hours debugging why some keystrokes were skipped when typing rapidly in our complex form and then discovering the need for
safeRenderCompletion={true}, big 👍 for removing these hacks.No, I don’t know why.
Some forensics:
setStatewrapper was introduced in 6159cb4834a082b2af2154e6f978b9ad57e96d51, but this mostly refactored existingsetImmediatehacks into this wrapper to enable central circumvention ofsetImmediateviasafeRenderCompletion.setImmediatecalls (all of them?) were introduced in PR #153 “Improved async rendering strategy” by @n1k0If I understand everything correctly:
setStatewas used properly, withonChangewithin callback (so no problems with correctness, race conditions)react-jsonschema-formis too slow: many components are stateless and there is no memoization. See #147. The examples linked there demonstrating the performance degradation are still working…setImmediatecalls)setImmediateshowed so much promise that PR #152 was aborted in favor of PR #153Regarding backwards compatibility:
In theory, after eliminating
setStatewrapper andsetImmediateand after fixing the performance problems, everything should still just work™. But most definitely, some behavior will change slightly, people are relying on timings, and so on. So I would consider this a breaking change.This is even more true if we take new React hooks into consideration, which could be a solution for the performance problem, since this requires upgrading the peer dependency on React to 16.8.0.