Anas (May Allah be pleased with him) reported:
The Prophet ﷺ passed by a woman who was crying over a grave and said, "Fear Allah and be patient." She said, "Away from me! My calamity has not befallen you and you are not aware of it." The woman was later told that it was the Prophet ﷺ (who had advised her). She came to his door where she found no doorkeeper. She said, "(I am sorry) I did not know you." Messenger of Allah ﷺ said, "Patience is (becoming) only at the first (stroke) of grief".
[Al-Bukhari and Muslim].
Another narration in Muslim says: The woman was crying over her son.
وعن أنس رضي الله عنه قال: مر النبي ﷺ بامرأة تبكي عند قبر فقال : "اتقي الله واصبري" فقالت : إليك عني ، فإنك لم تصب بمصيبتي ( ولم تعرفه، فقيل لها : إنه النبي ﷺ ، فأتت باب النبي ﷺ، فلم تجد عنده بوابين، فقالت: لم أعرفك، فقال: "إنما الصبر عند الصدمة الأولى" ((متفق عليه)) .