Repository: unoplatform/uno
File: src/Uno.UI.Runtime.Skia.WebAssembly.Browser/ts/Runtime/BrowserPointerInputSource.ts (TypeScript)

Code before:
		// Uses identity comparisons only; avoids selector matching, allocations, and redundant lookups.
		private isEventFromNativeElementHost(eventTarget: EventTarget | null) {
			const hostElement = this.getNativeElementHostCached();
			if (hostElement === null) {
				return false; // No host exists; nothing to filter.
			}

			let currentNode = eventTarget as Node | null;

			while (currentNode !== null) {
				// Fast identity comparison.
				if (currentNode === hostElement) {
					return true;
				}

				// Normal DOM climb first (fastest path)
				const parent = (currentNode as any).parentNode as Node | null;
				if (parent) {
					currentNode = parent;
					continue;
				}

				// Only if parentNode is null, check for a shadow boundary.
				const rootNode: any = typeof (currentNode as any).getRootNode === "function"
					? (currentNode as any).getRootNode()
					: null;

				// If we're inside a shadow root, jump to its host to continue traversal
				if (rootNode instanceof ShadowRoot && rootNode.host) {
					currentNode = rootNode.host as Node; // cross shadow boundary
					continue;
				}

				// Reached the top (Document or no further nodes)
				break;
			}

			return false;
		}

		private onPointerEventReceived(evt: PointerEvent): void {
			let id = (evt.target as HTMLElement)?.id;
			if (id === "uno-enable-accessibility") {
				// We have a div to enable accessibility (see enableA11y in WebAssemblyWindowWrapper).
				// Pressing space on keyboard to click it will trigger pointer event which we want to ignore.
				return;
			}

			if (this.isEventFromNativeElementHost(evt.target)) {
				// Events from the native host are handled by the native control directly.
				// We don't want to interfere with them.

Review comment (suggestion):
According to the support table, [the `getRootNode` is supported by all modern browser](https://caniuse.com/mdn-api_node_getrootnode), IMO we can safely use it without performing check:


```suggestion
				const rootNode = currentNode.getRootNode();
```

Code after:
		// Uses identity comparisons only; avoids selector matching, allocations, and redundant lookups.
		private isEventFromNativeElementHost(eventTarget: EventTarget | null) {
			const hostElement = this.getNativeElementHostCached();
			if (hostElement === null) {
				return false; // No host exists; nothing to filter.
			}

			let currentNode = eventTarget as Node | null;

			while (currentNode !== null) {
				// Fast identity comparison.
				if (currentNode === hostElement) {
					return true;
				}

				// Normal DOM climb first (fastest path)
				const parent = (currentNode as any).parentNode as Node | null;
				if (parent) {
					currentNode = parent;
					continue;
				}

				// Only if parentNode is null, check for a shadow boundary.
				const rootNode = currentNode.getRootNode();

				// If we're inside a shadow root, jump to its host to continue traversal
				if (rootNode instanceof ShadowRoot && rootNode.host) {
					currentNode = rootNode.host as Node; // cross shadow boundary
					continue;
				}

				// Reached the top (Document or no further nodes)
				break;
			}

			return false;
		}

		private onPointerEventReceived(evt: PointerEvent): void {
			let id = (evt.target as HTMLElement)?.id;
			if (id === "uno-enable-accessibility") {
				// We have a div to enable accessibility (see enableA11y in WebAssemblyWindowWrapper).
				// Pressing space on keyboard to click it will trigger pointer event which we want to ignore.
				return;
			}

			if (this.isEventFromNativeElementHost(evt.target)) {
				// Events from the native host are handled by the native control directly.
				// We don't want to interfere with them.
				return;
			}