Skip to content

Commit

Permalink
[docs] Don't redirect on deploy preview
Browse files Browse the repository at this point in the history
  • Loading branch information
m4theushw committed Apr 20, 2022
1 parent 17b3695 commit a1e4808
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ if (reactStrictMode) {
}
const l10nPRInNetlify = /^l10n_/.test(process.env.HEAD) && process.env.NETLIFY === 'true';
const vercelDeploy = Boolean(process.env.VERCEL);
const isDeployPreview = process.env.PULL_REQUEST === 'true';
// For crowdin PRs we want to build all locales for testing.
const buildOnlyEnglishLocale = isDeployPreview && !l10nPRInNetlify && !vercelDeploy;

const staging =
process.env.REPOSITORY_URL === undefined || /mui\/material-ui$/.test(process.env.REPOSITORY_URL);
Expand Down Expand Up @@ -172,6 +175,7 @@ module.exports = {
SOURCE_CODE_ROOT_URL: 'https://github.com/mui/material-ui/blob/master',
SOURCE_CODE_REPO: 'https://github.com/mui/material-ui',
STAGING: staging,
BUILD_ONLY_ENGLISH_LOCALE: buildOnlyEnglishLocale,
},
// Next.js provides a `defaultPathMap` argument, we could simplify the logic.
// However, we don't in order to prevent any regression in the `findPages()` method.
Expand Down Expand Up @@ -218,8 +222,8 @@ module.exports = {
}

// We want to speed-up the build of pull requests.
// For crowdin PRs we want to build all locales for testing.
if (process.env.PULL_REQUEST === 'true' && !l10nPRInNetlify && !vercelDeploy) {
// For this, consider only English language on deploy previews, except for crowdin PRs.
if (buildOnlyEnglishLocale) {
// eslint-disable-next-line no-console
console.log('Considering only English for SSR');
traverse(pages, 'en');
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function LanguageNegotiation() {
acceptLanguage.get(navigator.language) ||
userLanguage;

if (userLanguage !== preferedLanguage) {
if (userLanguage !== preferedLanguage && !process.env.BUILD_ONLY_ENGLISH_LOCALE) {
window.location =
preferedLanguage === 'en' ? canonicalAs : `/${preferedLanguage}${canonicalAs}`;
}
Expand Down

0 comments on commit a1e4808

Please sign in to comment.