This hits some OS-level bugs, and while I think it's a valuable user experience improvement, it seems best to just revert it for now. Issues I've uncovered since it was merged:
1. Rapidly hiding and showing a dock icon results in multiple icons for the same app. Those icons persist after the app exits, and if you click on them then, they disappear. I've seen this in a few applications, most reliably the Notepad++ installer, after selecting a language in the first dialog. 2. Removing a dock icon deactivates the app and reactivates the most recently active one. If it still has windows open, those move behind whatever app becomes active. And, we can't reliably work around that because... 3. With the cooperative app activation added in Sonoma, any requests to bring forward an app with no dock icon seem to fail. One illustratively bad case is Notepad++'s in-app modal update message box. It's from another process (which gets no taskbar icon on Windows and thus no dock icon with this patch). But since it can't be brought forward, and since it's modal, the result is that the Notepad++ main window is disabled for no apparent reason, and there's no way to select the dialog.
This reverts commit f0efb2e46a7fb2a00f85196a4a06bd50eda560b2.