Repository navigation
Conversation
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.
Member
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 这个 PR 的性质是?
🔗 相关 Issue
None — self-found by enumerating every
jumpLocation()call site and running the literal arguments through the shipped implementation.💡 需求背景和解决方案
What's broken
jumpLocation()inpackages/site-components/src/utils/locale.tsreturns`${url}-en`for an English page, appending the locale marker to the end of the whole URL. The site's English-route convention puts-enas a suffix of the last path segment —/icons-enand/source-enare 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:13passes'https://tdesign.tencent.com/starter/', so the "TDesign Starter" entry in the footer of every English page currently points at— a path segment named
-enunder/starter/, which is not a route. The same line also corrupts queries (/search?keyword=button→/search?keyword=button-en, which breaks the parameter and — sincegetLang()decides language from a/-en$/test onlocation.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 inconfig/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-enis 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 thejumpLocation()wrapper on that footer line — the call site was left alone so the maintainer can pick.Validation
src/__tests__/locale.spec.ts(6 cases;utils/locale.tshad 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 ata625b56= 10 across 5 files, nothing regressed);pnpm run lintexit 0;npx tsc --noEmitexit 0;npx prettier --checkon both files clean.📝 更新日志
-enlocale marker is now appended to the last path segment, fixing the Starter footer link on English pages☑️ 请求合并前的自查清单