Bug: Class component is mounted/unmounted when a parent suspend

This issue has been created since 2022-11-23.

React version: 18.2.0

Steps To Reproduce

  1. Start the app and check console, both (class and function) component were mounted.
  2. Click the button to make a parent component to suspend (uses react-freeze).
  3. Check the console, class component has been unmounted.

Link to code example:

https://codesandbox.io/s/freeze-lyxqd6?file=/src/App.js

The current behavior

When the parent component suspend, the children Class component are "mounted" and "unmounted", while Function components are not triggering the similar "useEffect" and its "cleanup".

The expected behavior

Suspended children should not fire "mount" and "unmount".

artola wrote this answer on 2022-11-26

Using Offscreen it behaves a bit different, either class or function component trigger the "same" lifecycle methods/hooks.

https://codesandbox.io/s/offscreen-kjfyji?file=/src/App.js

But, I am looking to this thing because I would like to implement some stack routing navigation, where the covered layers in the stack should be kinda detached to avoid unnecessary computation while not visible to the user and reattached just later when needed.
For such reason it would be better if the lifecycle methods are not fired at all when going in or out of suspend mode.

More Details About Repo
Owner Name facebook
Repo Name react
Full Name facebook/react
Language JavaScript
Created Date 2013-05-24
Updated Date 2022-12-10
Star Count 198882
Watcher Count 6638
Fork Count 41302
Issue Count 1120

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
How to track on individual pictures and save the results as pictures and not video 2 2022-07-25 2022-10-21
`maple-minibuffer:parameters` not always honored 2 2020-03-09 2022-04-22
How to make grasscutter run in the background? 2 2022-04-25 2022-10-12
yofi is blank and unresponsive 4 2022-03-31 2022-11-14
about real-time edge detection 2 2020-07-20 2022-11-14
Potential AY.122/BA.2* recombinant (7 seqs as of 2022-08-19, Russia) 25 2022-08-01 2022-09-19
Noticeably reduced performance with version 2 5 2021-02-19 2022-11-08
Overrides ftdetect from filetype plugins 3 2021-11-08 2022-09-18
Possible bug with paths 9 2021-09-22 2022-11-28
make test failed in Fedora Rawhide 9 2021-09-11 2022-11-28
new grid: 'br_state_grid' 0 2021-12-14 2022-11-12
[apps.paint_annotations] Close figures after plotting images 1 2020-07-30 2022-11-21
Update evaluation docs 1 2021-02-11 2022-11-21
Update requirement packages version 2 2021-02-07 2022-11-21
H5连接成功后无法获取成功后取成的回调函数 1 2021-07-22 2022-11-06
Streamedian not getting domain name 3 2021-10-20 2022-11-06
payload can be null in ResetRetroMeetingToGroupStageMutation 4 2021-09-08 2022-10-30
Expose request headers 4 2022-08-16 2022-12-08
Error in evaluation script 1 2021-11-18 2022-11-13
How many train_iters/hours is needed to reproduce the results in the paper? 0 2021-12-21 2022-11-19
Complete screenshot (no scroll) 5 2015-11-02 2022-12-04
Relaunch editor if message is invalid or save to tempoarary file? 4 2019-06-10 2022-12-10
[CKEditor] The CKEditor adds no code tags for subscript and superscript 2 2021-12-23 2022-11-07
Command flags completion parser issues 1 2022-05-18 2022-10-08
Some mod commands are not correctly registered 3 2022-05-23 2022-12-09
Expressions in arithmetic operators are evaluated in a nested path 1 2022-12-04 2022-12-02
Make search querying experience more predictable 1 2022-06-06 2022-09-15
Enable GitHub Actions 0 2022-06-03 2022-10-15
`/proc/fbX` not created 3 2021-07-04 2022-10-26
VS Code 1.61 will no longer have ability to extend Markdown outline 1 2021-09-09 2022-11-24
Big Blue Button screen share doesn't work on desktop app 2 2022-08-02 2022-08-31
Stack button for co wesbite doesn't work on mobile 0 2022-08-03 2022-09-24
Using the My Groups sidebar menu item highlights both Home and My Team menu items 6 2022-05-10 2022-11-06
docs & hack: make hack-new-kind-cluster 0 2021-08-09 2022-10-31
Is it possible to ban an ip realtime? 0 2021-04-17 2022-12-04
Termux:Boot doesn't work on andriod v9.0.0. 7 2019-09-29 2022-12-06
There is no error when typing an invalid query in the text editor for one table 1 2021-11-11 2022-10-03
Save waterfall plot 1 2021-08-23 2022-10-25
lcache_index 缓存的idx会失效 0 2022-04-20 2022-12-01
Properties marked as Computed, Optional and ForceNew cause unexpected Replaces 9 2019-02-15 2022-11-26
Python explicit provider configuration broken on Linux and Mac 10 2022-08-05 2022-10-30
resizing canvas and up down scrollbar 2 2022-02-16 2022-11-28
make_traced() doesn't respect setting the seed 0 2022-09-15 2022-10-02
Splash Screen does not appear on first launch with Android 12 (cordova-android-11) 4 2022-08-29 2022-12-02
Code analysis gives an error when c++23 is used 0 2022-06-04 2022-12-06
Missing protocol scheme in docker_host. When I use a lot of certificaties 0 2022-11-03 2022-11-23
More informative KeyError messages in converter 2 2020-12-18 2022-11-19
Alexnet benchmark 1.12 performance poor on V100S 2GPU 1 2020-08-19 2022-12-06
Support --concat flag for row level comparison 2 2022-06-17 2022-10-30
Examples don't show up when loading from an existing Space 3 2022-11-18 2022-12-05