Self hosting doesn’t make you immune, though. See how Plex evolved, for example. Self hosting plus free software that isn’t abandoned or compromised is the way, but idealistic developers need to take bread to the table too.
So the way maybe is self-hosted + libre software + a non-profit supporting the project. And that can too be corrupted, for example, the Mozilla Foundation and Google’s influence.
Always be ready to migrate.