headstartwp icon indicating copy to clipboard operation
headstartwp copied to clipboard

fetchRedirect not working on handleError with Polylang translated slugs

Open lucymtc opened this issue 1 year ago • 2 comments
trafficstars

Describe the bug

When having the Polylang integration enabled and slugs for post types are translated, the fetchRedirect pathname is not matching the translated slug in handleError, therefore a redirect added for a different locale in WP is not detected.

Steps to Reproduce

  1. Create custom post type., slug example 'programmes'
  2. Add translation to the post type slug in polylang, for example PT 'programas'
  3. Add rewrite in middleware so NextJS knows programas translated path is programmes/
  4. Add a redirect from from WP with Safe Redirect Manager from '/pt/programas/foo' that returns 404 to an existing page
  5. Within handleError function pathname is the ctx resolvedUrl which is programmes/foo
  6. See redirect not working.
  7. Inside handleError to test, hardcode pathname in fetchRedirect to '/pt/programas/foo' and see redirect working.

Screenshots, screen recording, code snippet

No response

Environment information

WP 6.4.3 Safe Redirect Manager 2.1.0 Polylang Pro 3.3.2 @headstartwp/core 1.1.2 @headstartwp/next 1.1.5

WordPress information

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

lucymtc avatar Feb 06 '24 13:02 lucymtc

I think we need better support for Polylang translated slugs featured. I'll look into how this could be better supported in general.

nicholasio avatar Mar 07 '24 21:03 nicholasio

@lucymtc was your fix essentially skip using ctx.resovledUrl at all even when using getStaticProps?

nicholasio avatar Mar 07 '24 21:03 nicholasio