Skip to content

Commit

Permalink
fix(i18n): correctly pull the ssr entry during build (#9380)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Dec 11, 2023
1 parent a0dc4a4 commit ea09182
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-bats-own.md
@@ -0,0 +1,5 @@
---
'astro': patch
---

Correctly handle the rendering of i18n routes when `output: "hybrid"` is set
19 changes: 17 additions & 2 deletions packages/astro/src/core/build/buildPipeline.ts
Expand Up @@ -8,7 +8,10 @@ import { routeIsFallback, routeIsRedirect } from '../redirects/helpers.js';
import { createEnvironment } from '../render/index.js';
import { createAssetLink } from '../render/ssr-element.js';
import type { BuildInternals } from './internal.js';
import { ASTRO_PAGE_RESOLVED_MODULE_ID } from './plugins/plugin-pages.js';
import {
ASTRO_PAGE_RESOLVED_MODULE_ID,
getVirtualModulePageNameFromPath,
} from './plugins/plugin-pages.js';
import { RESOLVED_SPLIT_MODULE_ID } from './plugins/plugin-ssr.js';
import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js';
import type { PageBuildData, StaticBuildOptions } from './types.js';
Expand Down Expand Up @@ -172,7 +175,19 @@ export class BuildPipeline extends Pipeline {
(i18nHasFallback(this.getConfig()) ||
(routeIsFallback(pageData.route) && pageData.route.route === '/'))
) {
pages.set(pageData, path);
// The original component is transformed during the first build, so we have to retrieve
// the actual `.mjs` that was created.
// During the build, we transform the names of our pages with some weird name, and those weird names become the keys of a map.
// The values of the map are the actual `.mjs` files that are generated during the build

// Here, we take the component path and transform it in the virtual module name
const moduleSpecifier = getVirtualModulePageNameFromPath(path);
// We retrieve the original JS module
const filePath = this.#internals.entrySpecifierToBundleMap.get(moduleSpecifier);
if (filePath) {
// it exists, added it to pages to render, using the file path that we jus retrieved
pages.set(pageData, filePath);
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions packages/astro/test/i18n-routing.test.js
Expand Up @@ -1380,6 +1380,27 @@ describe('[SSR] i18n routing', () => {
});
});
});

describe('i18n routing should work with hybrid rendering', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/i18n-routing-prefix-always/',
output: 'hybrid',
adapter: testAdapter(),
});
await fixture.build();
app = await fixture.loadTestAdapterApp();
});

it('and render the index page, which is static', async () => {
const html = await fixture.readFile('/client/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/new-site/en');
});
});
});

describe('i18n routing does not break assets and endpoints', () => {
Expand Down

0 comments on commit ea09182

Please sign in to comment.