Google's John Mueller said that if your website is www.domain.com and then you decide to canonicalize it to the non-www, so it goes to domain.com from www.domain.com - that change would not have a big impact on your rankings. He wrote on Reddit, "This won't cause problems with search visibility / rankings / indexing: when the canonical URL switches, it just switches."
The issue posted on Reddit read:
I joined CloudFlare and set my site up to their CDN. In doing so, I had an issue with 'too many redirects' and had to work with my hosting provider to resolve it. Turns out, they fixed that redirect error, but in doing so, they changed my 'home' and 'siteurl' values in my wp_options table from "https://www.example.com" to "https://example.com" (my site is a WordPress site). This caused my canonical URLs to change on all of my pages and redirected the www URLs of my site to non-www URLs. Before, my site was redirecting the non-www URLs to www URLs.
John said that would not cause a big ranking change. John Mueller wrote:
This won't cause problems with search visibility / rankings / indexing: when the canonical URL switches, it just switches. You might see a little blip, but it goes to normal very quickly. At most you'd see it in whatever analytics you use, if you separate out www/non-www usage. The only time it would cause bigger changes is if you switch canonicals to a different domain, and the domains have something different set up (eg country-TLD, removed from search, different crawl settings, etc) - with a www/non-www switch it's all within the same domain and you should be fine.
John Mueller added that the change might be coincidental with the March 2024 Google core update or maybe some other reason. John added:
If you're seeing a ranking or indexing drop, that would be due to other reasons. Also, if you're focusing on the last 5 days, you'd probably see fluctuations just from normal fluctuations - things always go up & down a bit, there's a lot involved with search. And if you're thinking of the core update, keep in mind that it's not marked as complete yet.
John said this before, that going from www to non www won't change much and using www or non-www is no difference to Google Search.
Forum discussion at Reddit.