Well, you should have offer before you put your notice. I usually wait until I have the new contract signed. But the notice should not be a surprise to anybody.
I tell my boss that I am actively searching, don't yet have an offer or a concrete date. I also tell him not to worry and reassure I will try to give him as much notice as possible and will cooperate to close whatever projects we can close and do necessary transfers gracefully.
This lets him plan some things like grooming my replacement or put more emphasis on closing projects rather than starting new ones. Which is additional benefit for me because there aren't many things worse for me than working on a project that I know I will never be able to finish.
Also here in Poland notice period is 1 month minimum. Since it is calendar month it can even be almost two months. But I also work as tech lead which means there is way more projects I am involved in and way more technical stuff to pass.
I try as much as I can not to be a bus factor 1 employee but somehow there is always a bunch of things that people realise would like to get done before I leave because they know otherwise they will have to wait forever for them.