[Segment Cache] Fix: canonicalURL omits origin (#76444)
The canonical URL is the href without the origin. I think historically the reason for this is because the initial canonical URL gets passed as a prop to the top-level React component, which means it needs to be computed during SSR. If it were to include the origin, it would need to always be same as location.origin on the client, to prevent a hydration mismatch. To sidestep this complexity, we omit the origin. However, since this is neither a native URL object nor a fully qualified URL string, we need to be careful about how we use it. To prevent subtle mistakes, we should create a special type for it, instead of just string. Or, we should just use a (readonly) URL object instead. The type of the prop that we pass to seed the initial state does not need to be the same type as the state itself. For now, I've left the type as-is and fixed its handling in the Segment Cache. This fixes a test that was failing because the origin was not being removed from the canonicalURL field. I'll refactor the type as a follow-up.
Showing
Please
register
or
sign in
to comment