No ones deeds are accepted if they do shirk

That is the guidance of Allah by which He guides whomever He wills of His servants. But if they had associated others with Allah, then worthless for them would be whatever they were doing.

Qur'aan 6:88



That guidance is the tawfiiq of Allaah which He gives to whom He Wills from His slaves. And Had these Prophets done shirk with Allaah - hypothetically speaking - their deeds would have gone to waste.

Because Allah does not accept any deeds (from anyone) when the person does shirk with Allaah.

تفسير المیسر

ذلك الهدى هو توفيق الله، الذي يوفق به من يشاء من عباده. ولو أن هؤلاء الأنبياء أشركوا بالله -على سبيل الفرض والتقدير- لبطل عملهم؛ لأن الله تعالى لا يقبل مع الشرك عملا