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): correctly pull the ssr entry during build #9380

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/honest-bats-own.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading