Intra-post anchor links don't work in Safari / Firefox

AI-generated summary

Intra-post anchor links not working in Safari / Firefox

plkap74 reported an issue with intra-post anchor links not working in Safari and Firefox, but working in Chrome. The error message in Safari is cryptic and does not provide a useful trace.

After investigation, plkap74 found that the issue only occurs in production mode, not in development mode. sam suggested that it might be related to a minifier bug.

The issue was eventually tracked down to a missing bracket in javascripts/discourse/lib/url.js plkap74. A pull request was submitted to fix the issue PR #3503.

I’ve been experimenting with anchor links inside of posts (links to content inside of a long post). I have read that you can’t use the ids because they get stripped. I used the name property instead and it works for Chrome but throws a very cryptic error in Safari.

Error: Syntax error, unrecognized expression: [name=anchor-name

It doesn’t give a useful trace so I can’t even tell where it is coming from. Is the anchor routing dealt with by Ember? Is there custom logic for that somewhere?


Example 1 (Live bug)

Try going to this link in Chrome (it works) but in Safari it throws an error and doesn’t work:


Example 2 (Reproduced bug)

works in Chrome, throws errors in safari

Table of contents

Topic 1

The markup for this heading is:

#### <a name="topic-1">Topic 1</a>

Topic 2

The markup for this heading is:

#### <a name="topic-2">Topic 2</a>

TOC Markup

The markup for the table of contents is

### Table of contents
- <a href="#topic-1">Topic 1</a>
- <a href="#topic-2">Topic 2</a>
- <a href="#toc-markup">TOC markup</a>
7개의 좋아요

I can repro this on Firefox v38

2개의 좋아요

Plot like gravy thickens. It appears to not throw any errors in development mode, only in production…

1개의 좋아요

Can be minifier related , seen a minifier bug once before

Can you point me to where in the JS this is being handled?

It is here

1개의 좋아요

I’m sorry I should have been more specific, I meant where was the name anchor code happening. I dove in and found it in javascripts/discourse/lib/url.js. It looks like there is a missing bracket.

Not sure why that would break only production though…

I’ll submit a PR.

3개의 좋아요

PR submitted

https://github.com/discourse/discourse/pull/3503

4개의 좋아요