Refreshing the content tree is not consistant

Hi,
I’ve been trying to copy content via a custom modal and looking at the src in core.
Github Repo

I have copied the code for duplicating and as you can see from the screen recording, it sometimes refreshes the tree, other times it doesnt. I can’t workout why it sometimes works and sometimes doesnt.

copyRefreshContentTree

My code for the submit is :

async #onSubmit(e?: SubmitEvent) {
	if (e && typeof (e as Event).preventDefault === 'function') {
		e.preventDefault();
	}

	const enabledSelectedIds = this.getEnabledSelectedIds(this.treeData);

	if (enabledSelectedIds.length === 0) {
		this._handleNotification('warning', 'Error', 'Please select at least one item to copy.');
		return;
	}
	try {
		var response = await tryExecuteAndNotify(this, TenpinCopyService.postUmbracoManagementApiV1CopyfromPrimaryCopy({
			body: {
				copyToLocation: this.data?.selectedContent ?? "",
				selectedContentIds: enabledSelectedIds
			}
		}));

		if (response.error) {
			throw new Error('Failed to copy content');
		}

		this._handleNotification('positive', 'Copy request has been queued successfully', 'The copy process will run in the background and you will be notified when it is complete.');

		this._submitModal();

		const entityContext = await this.getContext(UMB_ENTITY_CONTEXT);
		if (!entityContext) throw new Error('Entity Context is not available');

		const entityType = entityContext.getEntityType();
		const unique = entityContext.getUnique();

		if (entityType && unique !== undefined) {
			const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
			if (!eventContext) throw new Error('Event Context is not available');

			const args = { entityType, unique };

			const reloadChildren = new UmbRequestReloadChildrenOfEntityEvent(args);
			eventContext.dispatchEvent(reloadChildren);

			const reloadStructure = new UmbRequestReloadStructureForEntityEvent(args);
			eventContext.dispatchEvent(reloadStructure);
		}
	} catch (error) {
		this._handleNotification('danger', 'Copy failed', (error as Error).message);
	}
}

What might I be missing?

Just wondering if anyone has any examples of code that actually works :smiley: I feel it should be a notification or something that I can hook in to to refresh the left hand content tree on save / publish of a node