### Godot version

v4.1.beta.custom_build [dbd482faa]

### System information

macOS 13.3.0 - Vulkan (Forward+) - integrated Apple M1 Pro - Apple M1 Pro (8 Threads)

### Issue description

Some editor action like changing type will replace the node by another node. Right now Node properties will still point to the old Node. 

### Steps to reproduce

1. create a scene with a root node 
2. attach a script that exports a node property
3. set the property to point to the root node 
4. change the type of the root node
5. look at the property it will error out and the editor will be blank

### Minimal reproduction project

[Test.zip](https://github.com/godotengine/godot/files/11764206/Test.zip)
with MRP you can start at step 4
#ifndef SCENE_TREE_DOCK_H
#define SCENE_TREE_DOCK_H
#include "editor/gui/scene_tree_editor.h"
#include "editor/script_create_dialog.h"
#include "scene/gui/box_container.h"
#include "scene/resources/animation.h"
class CheckBox;
class EditorData;
class EditorSelection;
class EditorQuickOpen;
class MenuButton;
class ReparentDialog;
class ShaderCreateDialog;
class TextureRect;
#include "modules/modules_enabled.gen.h" 
#ifdef MODULE_REGEX_ENABLED
class RenameDialog;
#endif 
class SceneTreeDock : public VBoxContainer {
	GDCLASS(SceneTreeDock, VBoxContainer);
	enum Tool {