Google clarified that canonicalization happens twice on JavaScript sites: once on raw HTML, and again after JS rendering. If your HTML and JavaScript set different canonicals, Google may get conflicting signals and index the wrong URL.
Best practice:Set the canonical in the initial HTML and keep it identical after rendering. If JS must control it, don’t include a canonical in the raw HTML. Always ensure only one canonical tag exists after render.
Important for React, Vue, and Angular sites, check raw vs rendered HTML in Search Console if canonicals look off.