Repository: GraphiteEditor/Graphite (language: rust)

Issue:
Having no artboard crashes the editor
Either:

1. Make a new document with the default artboard
2. Open the graph, select the artboard, and delete it

or:

1. Make a new document without an artboard by enabling "Infinite Canvas"

It looks like this regression was introduced in #2028.

Crash log:

```
panicked at editor/src/messages/portfolio/document/document_message_handler.rs:2235:9:
The parent targets should always be empty (since we have left all layers)

Error
    at https://dev.graphite.rs/assets/index-DuUmgc5P.js:701:1169
    at g (https://dev.graphite.rs/assets/index-DuUmgc5P.js:686:5194)
    at Object.handleJsMessage (https://dev.graphite.rs/assets/index-DuUmgc5P.js:686:5342)
    at https://dev.graphite.rs/assets/index-DuUmgc5P.js:687:66749
    at https://dev.graphite.rs/assets/index-DuUmgc5P.js:687:39724
    at rt (https://dev.graphite.rs/assets/index-DuUmgc5P.js:687:2062)
    at R0.o.wbg.__wbg_call_5fb7c8066a4a4825 (https://dev.graphite.rs/assets/index-DuUmgc5P.js:687:39690)
    at graphite_wasm.wasm._ZN13graphite_wasm10editor_api12EditorHandle27send_frontend_message_to_js17ha25fea14a03bc37dE (https://dev.graphite.rs/assets/graphite_wasm_bg-FAZobSHR.wasm:wasm-function[3460]:0x7a5f06)
    at graphite_wasm.wasm._ZN4core3ops8function2Fn4call17h0b6e80a882797c3eE (https://dev.graphite.rs/assets/graphite_wasm_bg-FAZobSHR.wasm:wasm-function[12804]:0xa52b59)
    at graphite_wasm.wasm._ZN3std9panicking20rust_panic_with_hook17h33fe77d38d305ca3E (https://dev.graphite.rs/assets/graphite_wasm_bg-FAZobSHR.wasm:wasm-function[6456]:0x930366)
    at graphite_wasm.wasm._ZN4core9panicking9panic_fmt17hde8b7aa66e2831e1E (https://dev.graphite.rs/assets/graphite_wasm_bg-FAZobSHR.wasm:wasm-function[9756]:0xa0d88a)
    at graphite_wasm.wasm._ZN146_$LT$graphite_editor..messages..portfolio..document..document_message_handler..ClickXRayIter$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17hb7f34416b8af9d99E (https://dev.graphite.rs/assets/graphite_wasm_bg-FAZobSHR.wasm:wasm-function[688]:0x38aa6e)
    at graphite_wasm.wasm._ZN15graphite_editor8messages9portfolio8document24document_message_handler22DocumentMessageHandler5click17h0ab727e21aa2c03aE (https://dev.graphite.rs/assets/graphite_wasm_bg-FAZobSHR.wasm:wasm-function[1778]:0x5e8892)
    at graphite_wasm.wasm._ZN289_$LT$graphite_editor..messages..tool..tool_messages..select_tool..SelectTool$u20$as$u20$graphite_editor..utility_traits..MessageHandler$LT$graphite_editor..messages..tool..tool_message..ToolMessage$C$$RF$mut$u20$graphite_editor..messages..tool..utility_types..ToolActionHandlerData$GT$$GT$15process_message17h73ef76ac2ab60bf6E (https://dev.graphite.rs/assets/graphite_wasm_bg-FAZobSHR.wasm:wasm-function[2165]:0x670136)
    at graphite_wasm.wasm._ZN280_$LT$graphite_editor..messages..tool..tool_message_handler..ToolMessageHandler$u20$as$u20$graphite_editor..utility_traits..MessageHandler$LT$graphite_editor..messages..tool..tool_message..ToolMessage$C$graphite_editor..messages..tool..tool_message_handler..ToolMessageData$GT$$GT$15process_message17h3c9a67c11d1a60aaE (https://dev.graphite.rs/assets/graphite_wasm_bg-FAZobSHR.wasm:wasm-function[408]:0x205f97)
    at graphite_wasm.wasm._ZN15graphite_editor10dispatcher10Dispatcher14handle_message17h1ecc4f83899b780cE (https://dev.graphite.rs/assets/graphite_wasm_bg-FAZobSHR.wasm:wasm-function[441]:0x237227)
    at graphite_wasm.wasm._ZN13graphite_wasm10editor_api12EditorHandle8dispatch17hd95fc3cf7142e92cE (https://dev.graphite.rs/assets/graphite_wasm_bg-FAZobSHR.wasm:wasm-function[4082]:0x827236)
    at graphite_wasm.wasm.editorhandle_onKeyDown (https://dev.graphite.rs/assets/graphite_wasm_bg-FAZobSHR.wasm:wasm-function[6133]:0x915664)
    at ga.onKeyDown (https://dev.graphite.rs/assets/index-DuUmgc5P.js:687:8016)
    at g (https://dev.graphite.rs/assets/index-DuUmgc5P.js:690:2304)
```


Discussion / hints:

Fix patch:
diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs
index b1e0dfc120..8650b69061 100644
--- a/editor/src/messages/portfolio/document/document_message_handler.rs
+++ b/editor/src/messages/portfolio/document/document_message_handler.rs
@@ -2140,10 +2140,18 @@ fn click_targets_to_path_lib_segments<'a>(click_targets: impl Iterator<Item = &'
 
 impl<'a> ClickXRayIter<'a> {
 	fn new(network_interface: &'a NodeNetworkInterface, target: XRayTarget) -> Self {
-		Self {
-			next_layer: LayerNodeIdentifier::ROOT_PARENT.first_child(network_interface.document_metadata()),
-			network_interface,
-			parent_targets: vec![(LayerNodeIdentifier::ROOT_PARENT, target)],
+		if let Some(first_layer) = LayerNodeIdentifier::ROOT_PARENT.first_child(network_interface.document_metadata()) {
+			Self {
+				network_interface,
+				next_layer: Some(first_layer),
+				parent_targets: vec![(LayerNodeIdentifier::ROOT_PARENT, target)],
+			}
+		} else {
+			Self {
+				network_interface,
+				next_layer: Default::default(),
+				parent_targets: Default::default(),
+			}
 		}
 	}
 


Test patch: