Lua UI layout children removal leaves dangling pointers leading to reloading crashes

Happens in 0.49 and 0.50

local ui = require('openmw.ui')
local input = require('openmw.input')

local el = ui.create({})

return {
    engineHandlers = {
        onKeyPress = function(e)
            if e.code == input.KEY.Z then
                el.layout.content = ui.content {
                    {
                        type = ui.TYPE.Widget,
                        content = ui.content {
                            ui.create {
                                type = ui.TYPE.Widget
                            },
                        }
                    }
                }
                el:update()
            end
            if e.code == input.KEY.X then
                el.layout.content = ui.content {
                    {
                        type = ui.TYPE.Flex
                    }
                }
                el:update()
            end
        end
    },
}

Press z than press x then reloadlua:

[00:02:29.584 I] Reload Lua                                                                                                                                          
[00:02:29.585 E] Error in frame: MyGUI EXCEPTION : Widget '' not found
[00:02:29.585 E]  in MyGUI at /home/openmwbuild/deps/mygui/mygui-MyGUI3.4.3/MyGUIEngine/src/MyGUI_Gui.cpp (line 212)                                                 
[00:02:29.601 I] Reload Lua                                                                                                                                          
[00:02:29.601 E] Error in frame: MyGUI EXCEPTION : Widget '' not found
[00:02:29.601 E]  in MyGUI at /home/openmwbuild/deps/mygui/mygui-MyGUI3.4.3/MyGUIEngine/src/MyGUI_Gui.cpp (line 212)                                                 
[00:02:29.618 I] Reload Lua                                                                                                                                          
[00:02:29.618 E] Error in frame: MyGUI EXCEPTION : Widget '' not found
[00:02:29.618 E]  in MyGUI at /home/openmwbuild/deps/mygui/mygui-MyGUI3.4.3/MyGUIEngine/src/MyGUI_Gui.cpp (line 212) 
Edited by stuckInVsCode