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

Anchor name conflicts when type names differ only by capitalization #1585

Closed
cspotcode opened this issue May 16, 2021 · 3 comments
Closed

Anchor name conflicts when type names differ only by capitalization #1585

cspotcode opened this issue May 16, 2021 · 3 comments
Labels
bug Functionality does not match expectation

Comments

@cspotcode
Copy link
Contributor

cspotcode commented May 16, 2021

Search terms

header id conflicts
anchor conflict

Expected Behavior

On a page with two types Foo and foo, header links correctly link to both.

Actual Behavior

Typedoc generates anchors by converting both to lowercase, so links to foo will erroneously show Foo.

Both anchors use lowercase:

<a name="foo" class="tsd-anchor"></a>

Steps to reproduce the bug

The behavior occurs here for the Register and register types. Links that should go to register go instead to Register.
https://typestrong.org/ts-node/api/index.html

This was mentioned by Gerrit0 here: #1135 (comment)
Since it is already a known issue, I assume a smaller reproduction is not needed, but I can create one.

Environment

  • Typedoc version: 0.20.28
  • TypeScript version: 4.2.2
  • Node.js version: 14.16.0
  • OS: Linux
@cspotcode cspotcode added the bug Functionality does not match expectation label May 16, 2021
@cspotcode
Copy link
Contributor Author

Is there a good place I should get started looking to fix this? Or is a big, overhaul-type task that requires creating an entirely new subsystem to generate anchor names? Or somewhere in-between?

Not having looked at the code, I imagine that typedoc should generate a mapping from symbol to anchor name, generating them on-demand, and handling duplicates. It will need to understand that duplicates can only happen if the 2 anchors are on the same page.

Alternatively, when I modify one of the anchors to be capitalized, my browser handles them correctly. If this is standard browser behavior, perhaps we can simply remove the toLowercase() and allow capitalized anchors?

@cspotcode
Copy link
Contributor Author

I was able to fix the issue using this patch: https://github.com/cspotcode/typedoc/compare/master..patch-2

I'm using it to build the ts-node website here: https://github.com/TypeStrong/ts-node/blob/50e2ce0e0dfd530744415bebe500dcf04ec43fd8/.github/workflows/website.yml#L19-L21

So far it appears to be working. html filenames and URLs are capitalized to match the types. I don't know if I have accidentally broken something in the process.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jun 1, 2021

If this is standard browser behavior

Yep, unless you care about IE. Which... I don't.

This is.. probably somewhere in between.

In HTML 4 and earlier, two anchors that differed only in case were invalid (https://www.w3.org/TR/html401/struct/links.html#h-12.2.3)... so apparently whoever wrote this piece of code decided to avoid that by making them all lowercase?

Your patch shouldn't break anything, but is only half of the fix... it will still break if someone does this:

export function foo() {}
export type foo = 123

Properly fixing this is a bigger issue. I'd be happy to merge your fix since it's an improvement on what is there currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation
Projects
None yet
Development

No branches or pull requests

2 participants