Skip to content
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

fix(i18n): review fallback system #9119

Merged
merged 4 commits into from
Nov 17, 2023
Merged

fix(i18n): review fallback system #9119

merged 4 commits into from
Nov 17, 2023

Conversation

ematipico
Copy link
Member

@ematipico ematipico commented Nov 16, 2023

Changes

This PR closes #9108

The was a big flaw in the logic of the fallback, so I went back, and restored how the routes were stored before the introduction of the fallback logic.

The new change involves the introduction of fallbackRoutes as part of the RouteData object, very very similar to how we do it for redirectRoutes.

Although, now the generation of the pages is different, and each RouteData could create more than one page (itself + fallbackRoutes), hence I create a generator function called eachRouteInRouteData, which returns all the routes we need to create.

EDIT:

In SSR, the middleware already has the logic for doing the redirect, although we need to tell it somehow. So I updated the logic of app/index.ts.

The match function now considers' fallbackRoutes' when matching a route. However, when returning a Response, we set a status code 302 because we want the fallback to apply.

Example:

  • Fallback it to en
  • Request a /it/blog/article route
  • We match the route /en/blog/article, because it contains a fallback route that has a pathname that matches /it/blog/article
  • We then return a 302 status code. The middleware catches the status code and returns a redirect to /en/blog/article

Testing

I added a new case where we check the presence of a hoisted script.

The other rests should still pass.

Docs

Copy link

changeset-bot bot commented Nov 16, 2023

🦋 Changeset detected

Latest commit: 517ffa3

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review labels Nov 16, 2023
@ematipico ematipico force-pushed the fix/fallback-routing branch from 750c04e to 72dfaf7 Compare November 16, 2023 21:27
`[${staticPaths.length} ${label}]`
)}`
);
for (const route of eachRouteInRouteData(pageData)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we loop over all the routes: the main ones and the fallback routes associated to it

const matchedRoute = matchRoute(staticPath, opts.manifest);
return matchedRoute === route;
});
paths.push(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We chain all the generated routes all together

}

pipeline.getEnvironment().logger.debug('build', `Generating: ${pathname}`);
for (const route of eachRouteInRouteData(pageData)) {
Copy link
Member Author

@ematipico ematipico Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only relevant change is that the whole logic is inside this loop now, and instead of doing pageData.route, we pass the route from this loop

@ematipico ematipico marked this pull request as ready for review November 16, 2023 21:33
@ematipico ematipico merged commit 3067817 into main Nov 17, 2023
12 of 14 checks passed
@ematipico ematipico deleted the fix/fallback-routing branch November 17, 2023 19:18
@astrobot-houston astrobot-houston mentioned this pull request Nov 17, 2023
FredKSchott pushed a commit that referenced this pull request Nov 18, 2023
natemoo-re pushed a commit that referenced this pull request Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting a i18n.fallback option that maps to the defaultLocale leads to client-side js been removed.
3 participants