Skip to content

[Bug]: locales no longer working #1897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 2 tasks
EmmaDawsonDev opened this issue Jan 22, 2023 · 10 comments
Closed
1 of 2 tasks

[Bug]: locales no longer working #1897

EmmaDawsonDev opened this issue Jan 22, 2023 · 10 comments
Assignees

Comments

@EmmaDawsonDev
Copy link

EmmaDawsonDev commented Jan 22, 2023

Summary

I work for a Nordic Company and we currently have our website on netlify composed of 2 next apps and it uses domain-based locales for Sweden, Norway, Finland and Denmark. website.se is the default, and website.no, website.fi and website.dk are all set up to show the locale-specific version of the site. These all route to the second next app when a user clicks a "Book Now" button where website.se/booking is the default and website.no/booking, website.fi/booking and website.dk/booking are the locales.

Everything was working fine. However, when we made a production release last week the next plugin for netlify updated to 4.30.0 from 4.29.4. This caused all our locales to default to the .se/booking site when a user clicked the "Book Now" button even though the url was still showing the correct domain locale and this prevented customers in Norway, Finland and Denmark from being able to make bookings.

We've currently rolled back to 4.29.4 but it would be good to know what the issue is that caused this, if there's some extra config needed on our end (everything is set up according to the nextJS i18n documentation) and not have to worry that updates to this plugin will cause issues for us in the future.

Steps to reproduce

This happened when we made a production release last week and the plugin updated to 4.30.0.

A link to a reproduction repository

No response

Next Runtime version

4.30.0

More information about your build

  • I am building using the CLI
  • I am building using file-based configuration (netlify.toml)

What OS are you using?

None

Your netlify.toml file

`netlify.toml`
[[plugins]]
  package = "@netlify/plugin-nextjs"

[[plugins]]
  package = "./plugins/netlify/stop-build"

[[plugins]]
  package = "./plugins/netlify/copy-public-files"

# Pausing this until we have a solid suite of e2e tests
# [[context.production.plugins]]
#   package = "./plugins/netlify/run-cypress"

[context.deploy-preview.environment]
  NEXT_PUBLIC_RELESE_STAGE = "deploy-preview"

[build.environment]
  NODE_VERSION = "14"

Your public/_redirects file

`_redirects`
Redirects for the main app
#######################
# domain setup for hosts
#######################
http://website.se/* https://www.website.se/:splat 301!
http://website.fi/* https://www.website.fi/:splat 301!
http://website.dk/* https://www.website.dk/:splat 301!
http://website.no/* https://www.website.no/:splat 301!

https://website.se/* https://www.website.se/:splat 301!
https://website.fi/* https://www.website.fi/:splat 301!
https://website.dk/* https://www.website.dk/:splat 301!
https://website.no/* https://www.website.no/:splat 301!

http://www.website.se/* https://www.website.se/:splat 301!
http://www.website.fi/* https://www.website.fi/:splat 301!
http://www.website.dk/* https://www.website.dk/:splat 301!
http://www.website.no/* https://www.website.no/:splat 301!


###########################
# Prevent localised domains from accessing other unsuported locales through subpath
###########################
https://www.website.dk/fi/* https://www.website.dk/:splat 301!
https://www.website.dk/sv-FI/* https://www.website.dk/:splat 301!
https://www.website.dk/nb/* https://www.website.dk/:splat 301!
https://www.website.dk/sv/* https://www.website.dk/:splat 301!

https://www.website.fi/da/* https://www.website.fi/:splat 301!
https://www.website.fi/nb/* https://www.website.fi/:splat 301!
https://www.website.fi/sv/* https://www.website.fi/:splat 301!

https://www.website.no/da/* https://www.website.no/:splat 301!
https://www.website.no/fi/* https://www.website.no/:splat 301!
https://www.website.no/sv-FI/* https://www.website.no/:splat 301!
https://www.website.no/sv/* https://www.website.no/:splat 301!

https://www.website.se/da/* https://www.website.se/:splat 301!
https://www.website.se/fi/* https://www.website.se/:splat 301!
https://www.website.se/sv-FI/* https://www.website.se/:splat 301!
https://www.website.se/nb/* https://www.website.se/:splat 301!

https://staging.website.dk/fi/* https://staging.website.dk/:splat 301!
https://staging.website.dk/sv-FI/* https://staging.website.dk/:splat 301!
https://staging.website.dk/nb/* https://staging.website.dk/:splat 301!
https://staging.website.dk/sv/* https://staging.website.dk/:splat 301!

https://staging.website.fi/da/* https://staging.website.fi/:splat 301!
https://staging.website.fi/nb/* https://staging.website.fi/:splat 301!
https://staging.website.fi/sv/* https://staging.website.fi/:splat 301!

https://staging.website.no/da/* https://staging.website.no/:splat 301!
https://staging.website.no/fi/* https://staging.website.no/:splat 301!
https://staging.website.no/sv-FI/* https://staging.website.no/:splat 301!
https://staging.website.no/sv/* https://staging.website.no/:splat 301!

https://staging.website.se/da/* https://staging.website.se/:splat 301!
https://staging.website.se/fi/* https://staging.website.se/:splat 301!
https://staging.website.se/sv-FI/* https://staging.website.se/:splat 301!
https://staging.website.se/nb/* https://staging.website.se/:splat 301!

###########################
# Redirects for locale paths
###########################
https://www.website.se/sv/* https://www.website.se/:splat 301!
https://www.website.dk/da/* https://www.website.dk/:splat 301!
https://www.website.no/nb/* https://www.website.no/:splat 301!
https://www.website.fi/fi/* https://www.website.fi/:splat 301!
https://staging.website.se/sv/* https://staging.website.se/:splat 301!
https://staging.website.dk/da/* https://staging.website.dk/:splat 301!
https://staging.website.no/nb/* https://staging.website.no/:splat 301!
https://staging.website.fi/fi/* https://staging.website.fi/:splat 301!

#####################
# Proxy to Booking app
#####################
https://www.website.se/booking partnerId=:partnerId https://www.website.se/booking/:partnerId 301!
https://www.website.dk/booking partnerId=:partnerId https://www.website.dk/booking/:partnerId 301!
https://www.website.no/booking partnerId=:partnerId https://www.website.no/booking/:partnerId 301!
https://www.website.fi/booking partnerId=:partnerId https://www.website.fi/booking/:partnerId 301!
https://www.website.fi/booking/sv-FI partnerId=:partnerId https://www.website.fi/booking/sv-FI/:partnerId 301!

https://staging.website.se/booking partnerId=:partnerId https://staging.website.se/booking/:partnerId 301!
https://staging.website.dk/booking partnerId=:partnerId https://staging.website.dk/booking/:partnerId 301!
https://staging.website.no/booking partnerId=:partnerId https://staging.website.no/booking/:partnerId 301!
https://staging.website.fi/booking partnerId=:partnerId https://staging.website.fi/booking/:partnerId 301!
https://staging.website.fi/booking/sv-FI partnerId=:partnerId https://staging.website.fi/booking/sv-FI/:partnerId 301!

https://www.website.dk/booking/* https://booking.website.dk/booking/:splat 200!
https://www.website.fi/booking/* https://booking.website.fi/booking/:splat 200!
https://www.website.no/booking/* https://booking.website.no/booking/:splat 200!
https://www.website.se/booking/* https://booking.website.se/booking/:splat 200!

https://staging.website.dk/booking/* https://staging.booking.website.dk/booking/:splat 200!
https://staging.website.fi/booking/* https://staging.booking.website.fi/booking/:splat 200!
https://staging.website.no/booking/* https://staging.booking.website.no/booking/:splat 200!
https://staging.website.se/booking/* https://staging.booking.website.se/booking/:splat 200!


##############################
# Content preview rewrites
# Needs to come before legacy /api/ handler
##############################
/api/preview /.netlify/functions/___netlify-handler 200!
/api/exit-preview /.netlify/functions/___netlify-handler 200!


##############################
# Serve correct SSG landing page
##############################
# Make landing page work in preview mode
https://staging.website.dk/ /.netlify/functions/___netlify-handler 200! Cookie=__prerender_bypass,__next_preview_data
https://staging.website.fi/ /.netlify/functions/___netlify-handler 200! Cookie=__prerender_bypass,__next_preview_data
https://staging.website.fi/sv-FI /.netlify/functions/___netlify-handler 200! Cookie=__prerender_bypass,__next_preview_data
https://staging.website.no/ /.netlify/functions/___netlify-handler 200! Cookie=__prerender_bypass,__next_preview_data
https://staging.website.se/ /.netlify/functions/___netlify-handler 200! Cookie=__prerender_bypass,__next_preview_data

https://www.website.dk/ /.netlify/functions/___netlify-handler 200! Cookie=__prerender_bypass,__next_preview_data
https://www.website.fi/ /.netlify/functions/___netlify-handler 200! Cookie=__prerender_bypass,__next_preview_data
https://www.website.fi/sv-FI /.netlify/functions/___netlify-handler 200! Cookie=__prerender_bypass,__next_preview_data
https://www.website.no/ /.netlify/functions/___netlify-handler 200! Cookie=__prerender_bypass,__next_preview_data
https://www.website.se/ /.netlify/functions/___netlify-handler 200! Cookie=__prerender_bypass,__next_preview_data

https://staging.website.dk/ https://staging.website.dk/da.html 200!
https://staging.website.fi/ https://staging.website.fi/fi.html 200!
https://staging.website.fi/sv-FI https://staging.website.fi/sv-FI.html 200!
https://staging.website.no/ https://staging.website.no/nb.html 200!
https://staging.website.se/ https://staging.website.se/sv.html 200!

https://www.website.dk/ https://www.website.dk/da.html 200!
https://www.website.fi/ https://www.website.fi/fi.html 200!
https://www.website.fi/sv-FI https://www.website.fi/sv-FI.html 200!
https://www.website.no/ https://www.website.no/nb.html 200!
https://www.website.se/ https://www.website.se/sv.html 200!



Redirects for /booking app
#######################
# basePath redirect
#######################
/ /booking  301!

##############################
# Content preview rewrites to turn on preview mode
##############################
/booking/api/preview /.netlify/functions/___netlify-handler 200!
/booking/api/exit-preview /.netlify/functions/___netlify-handler 200!


##############################
# Serve correct SSG page and not use netlify function to render
##############################
https://booking.website.dk/booking https://booking.website.dk/booking/da.html 200!
https://booking.website.fi/booking https://booking.website.fi/booking/fi.html 200!
https://booking.website.fi/booking/sv-FI https://booking.website.fi/booking/sv-FI.html 200!
https://booking.website.no/booking https://booking.website.no/booking/nb.html 200!
https://booking.website.se/booking https://booking.website.se/booking/sv.html 200!

https://staging.booking.website.dk/booking https://staging.booking.website.dk/booking/da.html 200!
https://staging.booking.website.fi/booking https://staging.booking.website.fi/booking/fi.html 200!
https://staging.booking.website.fi/booking/sv-FI https://staging.booking.website.fi/booking/sv-FI.html 200!
https://staging.booking.website.no/booking https://staging.booking.website.no/booking/nb.html 200!
https://staging.booking.website.se/booking https://staging.booking.website.se/booking/sv.html 200!

##############################
# Rewrite partner params to its unique page
##############################
https://booking.website.se/booking/:partnerId https://booking.website.se/booking/sv/:partnerId 200
https://booking.website.dk/booking/:partnerId https://booking.website.dk/booking/da/:partnerId 200
https://booking.website.no/booking/:partnerId https://booking.website.no/booking/nb/:partnerId 200
https://booking.website.fi/booking/:partnerId https://booking.website.fi/booking/fi/:partnerId 200

https://staging.booking.website.se/booking/:partnerId https://staging.booking.website.se/booking/sv/:partnerId 200
https://staging.booking.website.dk/booking/:partnerId https://staging.booking.website.dk/booking/da/:partnerId 200
https://staging.booking.website.no/booking/:partnerId https://staging.booking.website.no/booking/nb/:partnerId 200
https://staging.booking.website.fi/booking/:partnerId https://staging.booking.website.fi/booking/fi/:partnerId 200

Your next.config.js file

`next.config.js`
Home page config:
const developmentEnvs = ['staging', 'development'];
const isDev = developmentEnvs.includes(process.env.NODE_ENV);
const withNx = require('@nrwl/next/plugins/with-nx');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
  openAnalyzer: false,
});

module.exports = withNx(
  withBundleAnalyzer({
    nx: {
      // Set this to false if you do not want to use SVGR
      // See: https://github.com/gregberge/svgr
      svgr: true,
    },
    images: {
      domains: ['images.ctfassets.net'],
    },
    i18n: {
      locales: ['da', 'fi', 'nb', 'sv', 'sv-FI'],
      defaultLocale: 'sv',
      localeDetection: false,
      domains: isDev
  ? [
      {
        domain: 'staging.website.se',
        defaultLocale: 'sv',
      },
      {
        domain: 'staging.website.no',
        defaultLocale: 'nb',
      },
      {
        domain: 'staging.website.dk',
        defaultLocale: 'da',
      },
      {
        domain: 'staging.website.fi',
        defaultLocale: 'fi',
        locales: ['sv-FI'],
      },
    ]
  : [
      {
        domain: 'www.website.se',
        defaultLocale: 'sv',
      },
      {
        domain: 'www.website.no',
        defaultLocale: 'nb',
      },
      {
        domain: 'www.website.dk',
        defaultLocale: 'da',
      },
      {
        domain: 'www.website.fi',
        defaultLocale: 'fi',
        locales: ['sv-FI'],
      },
    ];
    },
    
    },
  })
);

/booking config
const withNx = require('@nrwl/next/plugins/with-nx');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
  openAnalyzer: false,
});

module.exports = withNx(
  withBundleAnalyzer({
    basePath: '/booking',
    nx: {
      // Set this to false if you do not want to use SVGR
      // See: https://github.com/gregberge/svgr
      svgr: true,
    },
    images: {
      domains: ['images.ctfassets.net'],
    },
    i18n: {
      locales: ['da', 'fi', 'nb', 'sv', 'sv-FI'],
      defaultLocale: 'sv',
      localeDetection: false,
      // This is a list of locale domains and the default locale they
      // should handle (these are only required when setting up domain routing)
      // Note: subdomains must be included in the domain value to be matched e.g. "fr.example.com".
      domains: [
        {
          domain: 'staging.booking.website.se',
          defaultLocale: 'sv',
        },
        {
          domain: 'staging.booking.website.no',
          defaultLocale: 'nb',
        },
        {
          domain: 'staging.booking.website.dk',
          defaultLocale: 'da',
        },
        {
          domain: 'staging.booking.website.fi',
          defaultLocale: 'fi',
        },
      ],
    },
  })
);

Builds logs (or link to your logs)

Build logs
# Paste logs here

Function logs

Function logs
# Paste logs here

.next JSON files

generated .next JSON files
# Paste file contents here. Please check there isn't any private info in them
# You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.
@EmmaDawsonDev EmmaDawsonDev added the type: bug code to address defects in shipped code label Jan 22, 2023
@ascorbic
Copy link
Contributor

Thanks for the report. Can I confirm the steps:

  • The Norwegian user was on example.no which worked fine.
  • They clicked on "book now" which was a link to booking.example.no.
  • When they went to booking.example.no, the site was in Swedish.

Is that correct?

@ascorbic ascorbic added the i18n label Jan 23, 2023
@EmmaDawsonDev
Copy link
Author

That is correct. The url for booking.example.no was showing correctly as example.no/booking but the Swedish site was being shown and it was fetching data from the Swedish API which is controlled by an environment variable based on locale

@orinokai orinokai self-assigned this Jan 24, 2023
@orinokai
Copy link
Contributor

Sorry you've run into this issue! It is related to #1867 which was introduced in 4.30.0 and appears to be incorrectly matching root-level named locale pages as index pages. We are currently working on a fix and will update here when ready.

@orinokai
Copy link
Contributor

@EmmaDawsonDev can I please confirm a few things about your booking site to help us diagnose the issue further?

  • do you have a single index.js page at the root?
  • if so, is it a static SSG page or do you use getServerSideProps or getStaticProps with revalidate?

@EmmaDawsonDev
Copy link
Author

@EmmaDawsonDev can I please confirm a few things about your booking site to help us diagnose the issue further?

  • do you have a single index.js page at the root?
  • if so, is it a static SSG page or do you use getServerSideProps or getStaticProps with revalidate?

Yes, both the apps have a single index.tsx page at the root and are using getStaticProps. The only thing different with the booking.example.se is that we use a basepath of /booking so that it becomes example.se/booking as the url for the index page of the booking app. The landing page has a redirect set up so that when the user presses the "Book now" button they are redirected from example.se to booking.example.se but the URL shows example.se => example.se/booking

@orinokai
Copy link
Contributor

Thanks @EmmaDawsonDev, and just to be sure... are you using revalidate in your getStaticProps?

@EmmaDawsonDev
Copy link
Author

Thanks @EmmaDawsonDev, and just to be sure... are you using revalidate in your getStaticProps?

No, we're not currently using revalidate in either app.

@orinokai
Copy link
Contributor

It turns out the error is not related to the fix I mentioned above as that fix went out in 4.30.1.

I attempted to reproduce the error, without success, by creating a Next.js build with i18n, a single SSG index page and a basePath of 'booking' (I've assumed that the link from the first site is reaching the second site at https://booking.website.[country]/booking/[locale].html).

At this point I'm not certain exactly what is causing the problem. Would it be possible to create a minimal reproduction repo for us to take a look at?

@EmmaDawsonDev
Copy link
Author

Unfortunately it's quite a big project and I don't even know where to start in order to make a reproduction or have the time to set up all the hosting and env variables for the two apps.

@orinokai
Copy link
Contributor

orinokai commented Feb 8, 2023

Hi @EmmaDawsonDev, we've not had any similar reports so unfortunately I can't identify it as a Runtime bug or diagnose it any further without a reproduction. Let me know if you are able to narrow it down in the future and we can take a deeper look. Please feel free to put a message on our support forum if you need further help.

@orinokai orinokai closed this as completed Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants