diff --git a/packages/runtime/plugin-i18n/src/runtime/context.tsx b/packages/runtime/plugin-i18n/src/runtime/context.tsx
index 185d523fe201..54e305ca2300 100644
--- a/packages/runtime/plugin-i18n/src/runtime/context.tsx
+++ b/packages/runtime/plugin-i18n/src/runtime/context.tsx
@@ -169,7 +169,10 @@ export const useModernI18n = (
// Use history API to navigate without page reload
window.history.pushState(null, '', newUrl);
- } else if (updateLanguage) {
+ }
+
+ // Update language state after URL update
+ if (updateLanguage) {
updateLanguage(newLang);
}
} catch (error) {
diff --git a/tests/integration/alias-set/tests/index.test.ts b/tests/integration/alias-set/tests/index.test.ts
index 2d550a2c2400..ec994543d87d 100644
--- a/tests/integration/alias-set/tests/index.test.ts
+++ b/tests/integration/alias-set/tests/index.test.ts
@@ -20,7 +20,7 @@ describe('alias set build', () => {
const buildRes = await modernBuild(appDir);
expect(buildRes.code === 0).toBe(true);
expect(existsSync('route.json')).toBe(true);
- expect(existsSync('html/main/index.html')).toBe(true);
+ expect(existsSync('html/index/index.html')).toBe(true);
});
});
diff --git a/tests/integration/asset-prefix/tests/index.test.ts b/tests/integration/asset-prefix/tests/index.test.ts
index 32b27645b1a4..da2d41be0d40 100644
--- a/tests/integration/asset-prefix/tests/index.test.ts
+++ b/tests/integration/asset-prefix/tests/index.test.ts
@@ -35,7 +35,7 @@ describe('asset prefix', () => {
});
test(`should generate assetPrefix correctly when dev.assetPrefix is true`, async () => {
const HTML = readFileSync(
- path.join(appDir, 'dist/html/main/index.html'),
+ path.join(appDir, 'dist/html/index/index.html'),
'utf-8',
);
expect(
@@ -47,7 +47,7 @@ describe('asset prefix', () => {
const expected = `http://${DEFAULT_DEV_HOST}:${appPort}`;
const mainJs = readFileSync(
- path.join(appDir, 'dist/static/js/main.js'),
+ path.join(appDir, 'dist/static/js/index.js'),
'utf-8',
);
diff --git a/tests/integration/async-entry/tests/index.test.ts b/tests/integration/async-entry/tests/index.test.ts
index 7443bbe07de6..0dca6ac7b59b 100644
--- a/tests/integration/async-entry/tests/index.test.ts
+++ b/tests/integration/async-entry/tests/index.test.ts
@@ -10,16 +10,16 @@ describe('generate async entry', () => {
expect(
readFileSync(
- path.resolve(appDir, `node_modules/.modern-js/main/index.jsx`),
+ path.resolve(appDir, `node_modules/.modern-js/index/index.jsx`),
'utf8',
),
).toContain(`import { createRoot } from '@modern-js/runtime/react';`);
expect(
readFileSync(
- path.resolve(appDir, `node_modules/.modern-js/main/bootstrap.jsx`),
+ path.resolve(appDir, `node_modules/.modern-js/index/bootstrap.jsx`),
'utf8',
),
- ).toContain(`import(/* webpackChunkName: "async-main" */ './index');`);
+ ).toContain(`import(/* webpackChunkName: "async-index" */ './index');`);
});
});
diff --git a/tests/integration/basic-app/tests/index.test.ts b/tests/integration/basic-app/tests/index.test.ts
index b1ca61c31a0e..bc1c4edcee89 100644
--- a/tests/integration/basic-app/tests/index.test.ts
+++ b/tests/integration/basic-app/tests/index.test.ts
@@ -103,7 +103,7 @@ describe('test build', () => {
test(`should get right alias build!`, async () => {
expect(buildRes.code === 0).toBe(true);
expect(existsSync('route.json')).toBe(true);
- expect(existsSync('html/main/index.html')).toBe(true);
+ expect(existsSync('html/index/index.html')).toBe(true);
});
test('should visit page correctly', async () => {
diff --git a/tests/integration/clean-dist-path/tests/index.test.ts b/tests/integration/clean-dist-path/tests/index.test.ts
index b206180d23fc..f9f6e3860f2a 100644
--- a/tests/integration/clean-dist-path/tests/index.test.ts
+++ b/tests/integration/clean-dist-path/tests/index.test.ts
@@ -6,7 +6,7 @@ describe('clean dist path', () => {
test(`should not clean dist path when output.cleanDistPath is false`, async () => {
const appDir = path.resolve(__dirname, '..');
const tempFile = path.join(appDir, 'dist/foo.txt');
- const htmlFile = path.join(appDir, 'dist/html/main/index.html');
+ const htmlFile = path.join(appDir, 'dist/html/index/index.html');
fs.outputFileSync(tempFile, 'foo');
await modernBuild(appDir);
expect(fs.existsSync(tempFile)).toBeTruthy();
diff --git a/tests/integration/compatibility/tests/index.test.ts b/tests/integration/compatibility/tests/index.test.ts
index 3fb35d422ab7..2368273f06f8 100644
--- a/tests/integration/compatibility/tests/index.test.ts
+++ b/tests/integration/compatibility/tests/index.test.ts
@@ -11,6 +11,6 @@ function existsSync(filePath: string) {
test('should generate es5 artifact and pass check syntax by default', async () => {
const appDir = path.resolve(__dirname, '..');
await modernBuild(appDir);
- expect(existsSync('html/main/index.html')).toBeTruthy();
- expect(existsSync('static/js/main.js')).toBeTruthy();
+ expect(existsSync('html/index/index.html')).toBeTruthy();
+ expect(existsSync('static/js/index.js')).toBeTruthy();
});
diff --git a/tests/integration/custom-dist-path/tests/index.test.ts b/tests/integration/custom-dist-path/tests/index.test.ts
index a9fe46bb0dd0..b6c4435aac36 100644
--- a/tests/integration/custom-dist-path/tests/index.test.ts
+++ b/tests/integration/custom-dist-path/tests/index.test.ts
@@ -8,7 +8,7 @@ test(`should allow distPath.root to be an absolute path`, async () => {
const distPath = path.join(appDir, 'dist/foo');
const configFile = path.join(distPath, OUTPUT_CONFIG_FILE);
- const htmlFile = path.join(distPath, 'html/main/index.html');
+ const htmlFile = path.join(distPath, 'html/index/index.html');
expect(fs.existsSync(configFile)).toBeTruthy();
expect(fs.existsSync(htmlFile)).toBeTruthy();
});
diff --git a/tests/integration/custom-template/tests/__snapshots__/index.test.ts.snap b/tests/integration/custom-template/tests/__snapshots__/index.test.ts.snap
index 1c296fde9d2d..516adc997ec7 100644
--- a/tests/integration/custom-template/tests/__snapshots__/index.test.ts.snap
+++ b/tests/integration/custom-template/tests/__snapshots__/index.test.ts.snap
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`custom template should allow to custom template by html.template option 1`] = `"
Hello World"`;
+exports[`custom template should allow to custom template by html.template option 1`] = `"Hello World"`;
diff --git a/tests/integration/custom-template/tests/index.test.ts b/tests/integration/custom-template/tests/index.test.ts
index 753f491bc3c2..14c49a641a51 100644
--- a/tests/integration/custom-template/tests/index.test.ts
+++ b/tests/integration/custom-template/tests/index.test.ts
@@ -9,7 +9,7 @@ describe('custom template', () => {
await modernBuild(appDir);
expect(
- readFileSync(path.resolve(appDir, `dist/html/main/index.html`), 'utf8'),
+ readFileSync(path.resolve(appDir, `dist/html/index/index.html`), 'utf8'),
).toMatchSnapshot();
});
});
diff --git a/tests/integration/disable-html/tests/index.test.ts b/tests/integration/disable-html/tests/index.test.ts
index bfa3013f7974..27be20962cf2 100644
--- a/tests/integration/disable-html/tests/index.test.ts
+++ b/tests/integration/disable-html/tests/index.test.ts
@@ -8,6 +8,6 @@ test(`should not generate html files when tools.htmlPlugin is false`, async () =
await modernBuild(appDir);
expect(
- existsSync(path.resolve(appDir, `dist/html/main/index.html`)),
+ existsSync(path.resolve(appDir, `dist/html/index/index.html`)),
).toBeFalsy();
});
diff --git a/tests/integration/entries/fixtures/app-custom-entries/modern.config.ts b/tests/integration/entries/fixtures/app-custom-entries/modern.config.ts
index 3d0862ac02a5..b008313f3e0f 100644
--- a/tests/integration/entries/fixtures/app-custom-entries/modern.config.ts
+++ b/tests/integration/entries/fixtures/app-custom-entries/modern.config.ts
@@ -4,7 +4,7 @@ export default defineConfig({
source: {
disableDefaultEntries: true,
entries: {
- main: 'src/app-custom-entries/App.tsx',
+ index: 'src/app-custom-entries/App.tsx',
'entry-1': {
entry: 'src/entry-1/App.tsx',
customEntry: true,
diff --git a/tests/integration/i18n/app-ssr/tests/ssg.test.ts b/tests/integration/i18n/app-ssr/tests/ssg.test.ts
index c60fa989ba4a..54d106e8b06e 100644
--- a/tests/integration/i18n/app-ssr/tests/ssg.test.ts
+++ b/tests/integration/i18n/app-ssr/tests/ssg.test.ts
@@ -11,8 +11,8 @@ describe('ssg', () => {
const appDir = projectDir;
await modernBuild(appDir, ['--config', 'modern.ssg.config.ts']);
- const zhHtmlPath = path.join(appDir, './dist-ssg/html/main/zh/index.html');
- const enHtmlPath = path.join(appDir, './dist-ssg/html/main/en/index.html');
+ const zhHtmlPath = path.join(appDir, './dist/html/index/zh/index.html');
+ const enHtmlPath = path.join(appDir, './dist/html/index/en/index.html');
const zhContent = fs.readFileSync(zhHtmlPath, 'utf-8');
const enContent = fs.readFileSync(enHtmlPath, 'utf-8');
expect(zhContent).toMatch('你好,世界');
diff --git a/tests/integration/i18n/routes-ssr/test/ssg.test.ts b/tests/integration/i18n/routes-ssr/test/ssg.test.ts
index 0bd2c6b86428..c5fd6bf6f658 100644
--- a/tests/integration/i18n/routes-ssr/test/ssg.test.ts
+++ b/tests/integration/i18n/routes-ssr/test/ssg.test.ts
@@ -13,11 +13,11 @@ describe('ssg', () => {
const zhAboutHtmlPath = path.join(
appDir,
- './dist-ssg/html/main/zh/about/index.html',
+ './dist/html/index/zh/about/index.html',
);
const enAboutHtmlPath = path.join(
appDir,
- './dist-ssg/html/main/en/about/index.html',
+ './dist/html/index/en/about/index.html',
);
const zhAboutContent = fs.readFileSync(zhAboutHtmlPath, 'utf-8');
const enAboutContent = fs.readFileSync(enAboutHtmlPath, 'utf-8');
diff --git a/tests/integration/image-component/modern.config.ts b/tests/integration/image-component/modern.config.ts
index 9f6e3b480ac6..a7e54b958559 100644
--- a/tests/integration/image-component/modern.config.ts
+++ b/tests/integration/image-component/modern.config.ts
@@ -6,7 +6,7 @@ export default defineConfig({
router: true,
},
source: {
- mainEntryName: 'main',
+ mainEntryName: 'index',
},
output: {
// disable polyfill and ts checker to make test faster
diff --git a/tests/integration/image-component/tests/index.test.ts b/tests/integration/image-component/tests/index.test.ts
index 6901d5dc1b3e..c242674a8f5e 100644
--- a/tests/integration/image-component/tests/index.test.ts
+++ b/tests/integration/image-component/tests/index.test.ts
@@ -27,7 +27,7 @@ describe.skip('build', () => {
const buildRes = await modernBuild(appDir);
expect(buildRes.code === 0).toBe(true);
expect(existsSync('route.json')).toBe(true);
- expect(existsSync('html/main/index.html')).toBe(true);
+ expect(existsSync('html/index/index.html')).toBe(true);
const pageName = resolveDist('static/js/async/page.js');
const pageContent = await fs.promises.readFile(pageName, 'utf-8');
diff --git a/tests/integration/load-config/tests/async-config-function.test.ts b/tests/integration/load-config/tests/async-config-function.test.ts
index db00a3f8b6e9..e1516c63698d 100644
--- a/tests/integration/load-config/tests/async-config-function.test.ts
+++ b/tests/integration/load-config/tests/async-config-function.test.ts
@@ -10,7 +10,7 @@ describe('local config', () => {
await modernBuild(appDir);
expect(
- existsSync(path.join(appDir, 'dist/foo/html/main/index.html')),
+ existsSync(path.join(appDir, 'dist/foo/html/index/index.html')),
).toBeTruthy();
});
});
diff --git a/tests/integration/load-config/tests/basic-local-config.test.ts b/tests/integration/load-config/tests/basic-local-config.test.ts
index d9dd602dc23c..8f3f0e0a1631 100644
--- a/tests/integration/load-config/tests/basic-local-config.test.ts
+++ b/tests/integration/load-config/tests/basic-local-config.test.ts
@@ -16,7 +16,7 @@ describe('basic local config', () => {
const appPort = await getPort();
const app = await launchApp(appDir, appPort);
expect(
- existsSync(path.join(appDir, 'dist/bar/html/main/index.html')),
+ existsSync(path.join(appDir, 'dist/bar/html/index/index.html')),
).toBeTruthy();
await killApp(app);
});
@@ -24,7 +24,7 @@ describe('basic local config', () => {
test(`should not load local config when running build command`, async () => {
await modernBuild(appDir);
expect(
- existsSync(path.join(appDir, 'dist/foo/html/main/index.html')),
+ existsSync(path.join(appDir, 'dist/foo/html/index/index.html')),
).toBeTruthy();
});
});
diff --git a/tests/integration/load-config/tests/local-config-function.test.ts b/tests/integration/load-config/tests/local-config-function.test.ts
index 0cd5691ac209..2193c88179ec 100644
--- a/tests/integration/load-config/tests/local-config-function.test.ts
+++ b/tests/integration/load-config/tests/local-config-function.test.ts
@@ -11,7 +11,7 @@ describe('local config', () => {
const app = await launchApp(appDir, appPort);
expect(
- existsSync(path.join(appDir, 'dist/bar/html/main/index.html')),
+ existsSync(path.join(appDir, 'dist/bar/html/index/index.html')),
).toBeTruthy();
await killApp(app);
});
diff --git a/tests/integration/server-prod/tests/index.test.ts b/tests/integration/server-prod/tests/index.test.ts
index 30348c6cc80c..8454fcff9bc7 100644
--- a/tests/integration/server-prod/tests/index.test.ts
+++ b/tests/integration/server-prod/tests/index.test.ts
@@ -33,7 +33,7 @@ describe('test basic usage', () => {
expect(fs.existsSync(favicon1)).toBe(true);
expect(fs.existsSync(appIcon)).toBe(true);
- const mainEntry = path.resolve(appPath, './dist/html/main/index.html');
+ const mainEntry = path.resolve(appPath, './dist/html/index/index.html');
const activityEntry = path.resolve(
appPath,
'./dist/html/activity/index.html',
diff --git a/tests/integration/server-routes/modern.config.ts b/tests/integration/server-routes/modern.config.ts
index c50ccb093d09..dfb838a1497e 100644
--- a/tests/integration/server-routes/modern.config.ts
+++ b/tests/integration/server-routes/modern.config.ts
@@ -7,7 +7,7 @@ export default applyBaseConfig({
},
server: {
routes: {
- main: {
+ index: {
route: ['/a', '/b', '/main/:id'],
},
},
diff --git a/tests/integration/ssg/fixtures/nested-routes/modern.config.ts b/tests/integration/ssg/fixtures/nested-routes/modern.config.ts
index d50dc893209d..3fd3706105a6 100644
--- a/tests/integration/ssg/fixtures/nested-routes/modern.config.ts
+++ b/tests/integration/ssg/fixtures/nested-routes/modern.config.ts
@@ -7,7 +7,7 @@ export default defineConfig({
},
output: {
ssgByEntries: {
- main: {
+ index: {
routes: [
'/user',
{
diff --git a/tests/integration/ssg/tests/mega-list-routes.test.ts b/tests/integration/ssg/tests/mega-list-routes.test.ts
index 898d43a9d05c..0bf7331479ce 100644
--- a/tests/integration/ssg/tests/mega-list-routes.test.ts
+++ b/tests/integration/ssg/tests/mega-list-routes.test.ts
@@ -12,7 +12,7 @@ it('should render static mega list routes', async () => {
const ids = [0, 100, 9999];
for (const id of ids) {
- const htmlPath = path.join(appDir, `dist/html/main/user/${id}/index.html`);
+ const htmlPath = path.join(appDir, `dist/html/index/user/${id}/index.html`);
const content = fs.readFileSync(htmlPath, 'utf-8');
expect(content).toContain(
`/user/${id}
`,
diff --git a/tests/integration/ssg/tests/nested-routes.test.ts b/tests/integration/ssg/tests/nested-routes.test.ts
index 82fc72befc30..f0a2973cac62 100644
--- a/tests/integration/ssg/tests/nested-routes.test.ts
+++ b/tests/integration/ssg/tests/nested-routes.test.ts
@@ -25,19 +25,19 @@ describe('ssg', () => {
});
test('should nested-routes ssg access / work correctly', async () => {
- const htmlPath = path.join(distDir, 'html/main/index.html');
+ const htmlPath = path.join(distDir, 'html/index/index.html');
const html = (await fs.readFile(htmlPath)).toString();
expect(html.includes('Hello, Home')).toBe(true);
});
test('should nested-routes ssg access /user work correctly', async () => {
- const htmlPath = path.join(distDir, 'html/main/user/index.html');
+ const htmlPath = path.join(distDir, 'html/index/user/index.html');
const html = (await fs.readFile(htmlPath)).toString();
expect(html.includes('Hello, User')).toBe(true);
});
test('should nested-routes ssg access /user/1 work correctly with data loading', async () => {
- const htmlPath = path.join(distDir, 'html/main/user/1/index.html');
+ const htmlPath = path.join(distDir, 'html/index/user/1/index.html');
const html = (await fs.readFile(htmlPath)).toString();
expect(html.includes('User 1: John Doe')).toBe(true);
expect(html.includes('User ID: 1')).toBe(true);
diff --git a/tests/integration/ssg/tests/simple.test.ts b/tests/integration/ssg/tests/simple.test.ts
index 9fb721ce38c9..f547fc4e4e42 100644
--- a/tests/integration/ssg/tests/simple.test.ts
+++ b/tests/integration/ssg/tests/simple.test.ts
@@ -11,7 +11,7 @@ describe('ssg', () => {
const appDir = join(fixtureDir, 'simple');
await modernBuild(appDir);
- const htmlPath = path.join(appDir, './dist/html/main/index.html');
+ const htmlPath = path.join(appDir, './dist/html/index/index.html');
const content = fs.readFileSync(htmlPath, 'utf-8');
expect(content).toMatch('Hello, Modern.js');
});
diff --git a/tests/integration/ssg/tests/web-server.test.ts b/tests/integration/ssg/tests/web-server.test.ts
index 965610dc8f83..e3ffddfd0981 100644
--- a/tests/integration/ssg/tests/web-server.test.ts
+++ b/tests/integration/ssg/tests/web-server.test.ts
@@ -11,7 +11,7 @@ describe('ssg', () => {
const appDir = join(fixtureDir, 'web-server');
await modernBuild(appDir);
- const htmlPath = path.join(appDir, './dist/html/main/index.html');
+ const htmlPath = path.join(appDir, './dist/html/index/index.html');
const content = fs.readFileSync(htmlPath, 'utf-8');
expect(content).toMatch('Hello, Modern.js');
expect(content).toMatch('bytedance');
diff --git a/tests/integration/ssr/tests/base-async-entry.test.ts b/tests/integration/ssr/tests/base-async-entry.test.ts
index 3eac06fce0f3..1da8b5449fdb 100644
--- a/tests/integration/ssr/tests/base-async-entry.test.ts
+++ b/tests/integration/ssr/tests/base-async-entry.test.ts
@@ -63,11 +63,11 @@ describe('init with SSR', () => {
const loadableStats = fs.readJSONSync(
path.join(appDir, 'dist/loadable-stats.json'),
);
- const chunks = loadableStats.namedChunkGroups['async-main'].assets;
+ const chunks = loadableStats.namedChunkGroups['async-index'].assets;
const urls: string[] = chunks.map((chunk: { name: string }) => {
return `/${chunk.name}`;
});
- const existAssets = loadableStats.entrypoints.main.assets.map(
+ const existAssets = loadableStats.entrypoints.index.assets.map(
(asset: { name: string }) => `/${asset.name}`,
);
diff --git a/tests/integration/ssr/tests/base.test.ts b/tests/integration/ssr/tests/base.test.ts
index da796eadd951..cc315ed61439 100644
--- a/tests/integration/ssr/tests/base.test.ts
+++ b/tests/integration/ssr/tests/base.test.ts
@@ -56,7 +56,7 @@ async function redirectInLoader(page: Page, appPort: number) {
async function checkIsPassChunkLoadingGlobal() {
const modernJsDir = join(fixtureDir, 'base', 'node_modules', '.modern-js');
- const entryFilePath = join(modernJsDir, 'main', 'index.jsx');
+ const entryFilePath = join(modernJsDir, 'index', 'index.jsx');
const content = await fs.readFile(entryFilePath, 'utf-8');
expect(content).toMatch(/chunkLoadingGlobal/);
}
diff --git a/tests/integration/temp-dir/tests/index.test.ts b/tests/integration/temp-dir/tests/index.test.ts
index 7cebaed4af35..97a503c6f3d5 100644
--- a/tests/integration/temp-dir/tests/index.test.ts
+++ b/tests/integration/temp-dir/tests/index.test.ts
@@ -16,6 +16,6 @@ describe('test temp-dir', () => {
test(`should get right alias build!`, async () => {
expect(buildRes.code === 0).toBe(true);
- expect(existsSync('node_modules/.temp-dir/main')).toBe(true);
+ expect(existsSync('node_modules/.temp-dir/index')).toBe(true);
});
});
diff --git a/tests/integration/write-to-dist/tests/index.test.ts b/tests/integration/write-to-dist/tests/index.test.ts
index 942d734756d6..5c69e0515f36 100644
--- a/tests/integration/write-to-dist/tests/index.test.ts
+++ b/tests/integration/write-to-dist/tests/index.test.ts
@@ -49,6 +49,6 @@ describe('test dev', () => {
test('should not get production in dist', async () => {
expect(existsSync('route.json')).toBeTruthy();
- expect(existsSync('html/main/index.html')).toBeFalsy();
+ expect(existsSync('html/index/index.html')).toBeFalsy();
});
});