You can use this code:
Code:
hooksecurefunc("CompactUnitFrame_UpdateVisible", function(frame)
if ( UnitExists(frame.unit) or UnitExists(frame.displayedUnit) ) and frame.unit == "player" then
CompactUnitFrame_ClearWidgetSet(frame)
frame:Hide()
frame.unitExists = false
end
end)