Skip to content

fix(site-components): put the -en locale marker on the last path segment - #948

Open
NUAAwqy wants to merge 1 commit into
Tencent:mainfrom
NUAAwqy:fix/jump-location-path-suffix
Open

NUAAwqy wants to merge 1 commit into
Tencent:mainfrom
NUAAwqy:fix/jump-location-path-suffix

Conversation

@NUAAwqy

@NUAAwqy NUAAwqy commented Oct 25, 2026

Copy link
Copy Markdown

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 测试用例

🔗 相关 Issue

None — self-found by enumerating every jumpLocation() call site and running the literal arguments through the shipped implementation.

💡 需求背景和解决方案

What's broken

jumpLocation() in packages/site-components/src/utils/locale.ts returns `${url}-en` for an English page, appending the locale marker to the end of the whole URL. The site's English-route convention puts -en as a suffix of the last path segment — /icons-en and /source-en are hardcoded that way — so plain concatenation is only equivalent when the argument has no trailing slash, query, or fragment.

One live call site does have a trailing slash: config/footer.ts:13 passes 'https://tdesign.tencent.com/starter/', so the "TDesign Starter" entry in the footer of every English page currently points at

https://tdesign.tencent.com/starter/-en

— a path segment named -en under /starter/, which is not a route. The same line also corrupts queries (/search?keyword=button → /search?keyword=button-en, which breaks the parameter and — since getLang() decides language from a /-en$/ test on location.pathname — would not even serve English) and turns / into /-en.

The fix

Split at the first ?/#, strip trailing slashes, append the marker to the remaining path, re-attach query and fragment, and return the address unchanged when no segment is left to carry it. The Chinese branch returns its argument verbatim, exactly as before.

Blast radius, measured rather than assumed: all 24 call sites (4 in config/footer.ts, 20 in config/header.ts) were run through the old and new implementations — exactly one output changes (the starter link above); the other 23 are byte-identical.

Scope note: whether the English starter page is served at /starter-en is a routing fact outside this repository, so the fix restores the repo's own naming convention rather than asserting the page exists. If the starter guide has no English version at all, the right change would be to drop the jumpLocation() wrapper on that footer line — the call site was left alone so the maintainer can pick.

Validation

  • New src/__tests__/locale.spec.ts (6 cases; utils/locale.ts had no coverage at all): 3 of the 6 fail against the shipped implementation with the strings quoted above; all 6 pass with the fix.
  • npx vitest run → 16 passed across 6 files (baseline at a625b56 = 10 across 5 files, nothing regressed); pnpm run lint exit 0; npx tsc --noEmit exit 0; npx prettier --check on both files clean.

📝 更新日志

  • fix(site-components): the -en locale marker is now appended to the last path segment, fixing the Starter footer link on English pages

☑️ 请求合并前的自查清单

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

jumpLocation() built the English address by concatenating "-en" onto the end of
whatever string it was given, which is only correct when the argument is a bare
in-site path with no trailing slash, query or hash. The one argument that does
have a trailing slash is a live footer link, and it is broken today:

  config/footer.ts:13  jumpLocation('https://tdesign.tencent.com/starter/')
  English page -> https://tdesign.tencent.com/starter/-en

That URL asks for a path segment named "-en" *under* /starter/, while every
English route on this site carries the marker as a suffix of the last segment
(/icons-en and /source-en are hardcoded that way in
site/src/pages/design/icon.vue:77 and in the same footer config), so the
"TDesign Starter" entry in the footer of every English page points at something
that is not a route. Measured against the shipped implementation the returned
string is exactly `https://tdesign.tencent.com/starter/-en`.

The same concatenation corrupts any address that carries a query or a fragment:
`/search?keyword=button` becomes `/search?keyword=button-en`, which both breaks
the parameter and — because getLang() decides the language from a `/-en$/` test
on the pathname — would not even be served as the English page. And `'/'`
becomes `/-en`, inventing a segment out of nothing.

Fix: split the address at the first `?` or `#`, strip trailing slashes from the
path part, append the marker to what is left, then re-attach the query and
fragment. If the path part is empty there is no segment to attach the marker to,
so the address is returned unchanged rather than being given a synthetic one.
The Chinese branch is untouched: a non-English page still returns its argument
verbatim.

Effect on the repository's 24 call sites was enumerated rather than assumed:
every literal argument in config/footer.ts and config/header.ts was parsed and
run through the old and new implementations, and exactly one output changes
(the starter link above). The other 23 — /source, /design, /icons,
/about/introduce, /about/contact and the eight framework /overview paths — are
byte-identical, because a path with no trailing slash falls through to the same
concatenation.

Validation:
- New src/__tests__/locale.spec.ts (the file previously had no coverage of
  utils/locale.ts at all) pins the unchanged Chinese and plain-path behaviour,
  the trailing-slash case, query-only, hash-only and query+hash addresses, and
  the empty-path guard. Against the shipped implementation 3 of the 6 cases
  fail with the observed strings quoted above; after the change all 6 pass.
- packages/site-components: `npx vitest run` -> 16 passed across 6 files
  (baseline at this commit is 10 across 5 files, so nothing regressed),
  `pnpm run lint` (eslint src config script --ext .ts) exit 0,
  `npx tsc --noEmit` exit 0, `npx prettier --check` on both files clean.
- Not run: `pnpm run site:preview` and the root `pnpm -r run lint`, which need
  the other workspace packages; the site is a browser app and cannot be
  exercised here.

Scope I am not claiming: whether the English starter page is served at
/starter-en is a routing fact outside this repository, so the fix restores the
repo's own naming convention rather than asserting that the page exists. If the
starter guide has no English version at all, the right change is to drop the
jumpLocation() wrapper on that footer line instead, and I have left the call
site alone so the maintainer can pick.
@tencent-adm

tencent-adm commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants