react-universal-component icon indicating copy to clipboard operation
react-universal-component copied to clipboard

onAfter called after preload in V3 but not V4

Open Radi-Mortada opened this issue 5 years ago • 6 comments

In V4.0.0 onAfter is not being called if we called preload. V4.0.0 Sandbox

but in V3.0.3 onAfter is called correctly after we call preload. V3.0.3 Sandbox

is it expected?

Radi-Mortada avatar May 20 '19 09:05 Radi-Mortada

Likely not. Can you investigate more and possibly open a PR?

ScriptedAlchemy avatar May 20 '19 13:05 ScriptedAlchemy

I can confirm its not being called serverside render either.

jamesjjk avatar Jul 11 '19 17:07 jamesjjk

Anyone help in debugging. I’ll try and find some time to give RUC some TLC

ScriptedAlchemy avatar Jul 27 '19 03:07 ScriptedAlchemy

I also confirm this is happening in 4.0.0. Just started digging into it, see what I can find

UPDATE: This is happening for me only on the initial mount. Subsequent mounts do call onAfter, but the first one does not. e.g. navigating to a second page will run onAfter

mattrabe avatar Jan 07 '20 01:01 mattrabe

After analyzing 3c21ffa45c I found that this was caused during the refactor from componentWillMount() to init().

Previously, componentWillMount set _mounted to true and then subsequently fired update(). After 3c21ffa45c, we instead have constructor() calling init() which in turn calls __update() - but _initialized (formerly _mounted) is not set until componentDidMount() which takes place AFTER constructor(). Therefore, _initialized will always be false on the first run of __update() triggered by constructor() -> init(), which causes __handleAfter() to not be called.

My solution is to move the init() call from constructor to componentDidMount, after _initialized is set to true. PR coming soon

mattrabe avatar Jan 07 '20 21:01 mattrabe

@mattrabe I'm not sure if I'm using it correctly but I employed the same sandbox with the updated package but it is still re-occurring sandbox

edit, it still fails the test case.

AndrewThian avatar Feb 05 '20 10:02 AndrewThian