diff options
author | 2023-12-11 10:10:59 +0000 | |
---|---|---|
committer | 2023-12-11 10:10:59 +0000 | |
commit | ea0918259964947523827bac6abe88ad3841dbb9 (patch) | |
tree | 59f3cc5acc00d3338f40e09d7b9114dbb6f37cbe | |
parent | a0dc4a43572f45c5e26f5a470cb7f9c47fb9f542 (diff) | |
download | astro-ea0918259964947523827bac6abe88ad3841dbb9.tar.gz astro-ea0918259964947523827bac6abe88ad3841dbb9.tar.zst astro-ea0918259964947523827bac6abe88ad3841dbb9.zip |
fix(i18n): correctly pull the ssr entry during build (#9380)
-rw-r--r-- | .changeset/honest-bats-own.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/build/buildPipeline.ts | 19 | ||||
-rw-r--r-- | packages/astro/test/i18n-routing.test.js | 21 |
3 files changed, 43 insertions, 2 deletions
diff --git a/.changeset/honest-bats-own.md b/.changeset/honest-bats-own.md new file mode 100644 index 000000000..3755e7572 --- /dev/null +++ b/.changeset/honest-bats-own.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Correctly handle the rendering of i18n routes when `output: "hybrid"` is set diff --git a/packages/astro/src/core/build/buildPipeline.ts b/packages/astro/src/core/build/buildPipeline.ts index 623e89630..166e42a2f 100644 --- a/packages/astro/src/core/build/buildPipeline.ts +++ b/packages/astro/src/core/build/buildPipeline.ts @@ -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'; @@ -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); + } } } diff --git a/packages/astro/test/i18n-routing.test.js b/packages/astro/test/i18n-routing.test.js index 4b9a03230..567dc040e 100644 --- a/packages/astro/test/i18n-routing.test.js +++ b/packages/astro/test/i18n-routing.test.js @@ -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', () => { |