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

Replace the header_links plugin with client-side generated anchors. #4165

Merged
merged 2 commits into from
Mar 1, 2017
Merged

Replace the header_links plugin with client-side generated anchors. #4165

merged 2 commits into from
Mar 1, 2017

Conversation

bryanbraun
Copy link
Contributor

Fixes #4124

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

.replace(/\s+/g, '-')
.replace(/[^A-Za-z0-9\-_.]/g, '');

elements[i].setAttribute('id', tidyText);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the anchors actually work, since you're setting the ID after it's rendered? Does the browser correctly scroll down to the anchor when you open a fresh tab and go to a URL with an anchor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The anchors do work. I did some testing across the various desktop browsers where I added anchors at various points in the loading process. I found that they all hop to IDs added after the DOM is fully loaded, though they differ in how much later in the process they will successfully jump to the anchor. In case you're curious, here's where each of the browsers fared on the test (the browser name is listed where they last successfully jumped to the anchor).

  • On DOM Ready (DOMContentLoaded)
    • Safari
    • Chrome
    • Opera
  • On Page Fully Loaded (window.onload)
    • Firefox
    • IE
  • After Arbitrary setTimeout
    • - none -

In short, we're safe in adding the IDs where we have, at least for all the browsers I tested.

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@bryanbraun
Copy link
Contributor Author

OK, this is ready for review again. I also included a CSS adjustment that ensures the Sticky header doesn't obscure the heading being anchored to.

@lacker
Copy link
Contributor

lacker commented Feb 1, 2017

OK so this is fairly old, we redid a lot of the website since then, and there are merge conflicts. @bryanbraun does this PR still make sense and are you still interested in working on it? Or should we just deem it "timed out" and close it.

@gaearon
Copy link
Collaborator

gaearon commented Feb 2, 2017

Btw this is the oldest open PR in React repo :-)

@bryanbraun
Copy link
Contributor Author

@lacker, thanks for following up. I'd like to try rebasing it later this week, and seeing if this kind of change still makes sense with the updated site. I'll let you know what I find by end of day Friday.

@bryanbraun
Copy link
Contributor Author

bryanbraun commented Feb 10, 2017

@lacker, I've rebased the PR so it should apply cleanly now. The code is in the same place as it was in the original PR (before the closing body tag) but it can be moved if needed.

I did a bit of testing in Chrome and IE9 and haven't found any functional or visual issues. I also ran a jekyll build and confirmed that the hash-links aren't showing up in the feed.xml file anymore.

Copy link
Contributor

@lacker lacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small comments. Thanks for fixing this up!

@@ -122,6 +122,7 @@ h1, h2, h3, h4, h5, h6 {
.hash-link {
color: $mediumTextColor;
display: none;
padding-left: 8px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a UI change or is this just to compensate for something that's happening in that Redcarpet library? If it is a UI change, would you mind posting a before and after screen shot to show what you're changing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's compensating... changing how we add space between the title and hash-link. The UI should look the same:

hello_world_-react_and_hello_world-_react

@@ -62,6 +62,36 @@

<div id="fb-root"></div>
<script>
(function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems inconsistent to inline this when things like live_editor.js are included as separate scripts, what do you think about refactoring this out similar to the other stuff?

I suspect people in the future will be digging through old code and trying to figure out what the heck this bit is doing, so would you mind adding just enough overall comments to explain what it is that this section of code is trying to accomplish?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I've made these updates in 1757114.

Also adds a couple comments, for context.
@bryanbraun
Copy link
Contributor Author

Ok, that should be all the changes you requested. 👍

@lacker lacker merged commit 7a878d2 into facebook:master Mar 1, 2017
@lacker
Copy link
Contributor

lacker commented Mar 1, 2017

Thank you! This seems a bit less technical debty, in addition to working better with RSS, since I have a sneaking suspicion that React folks would prefer to write javascript than ruby.

@gaearon
Copy link
Collaborator

gaearon commented Mar 1, 2017

😮

gaearon pushed a commit that referenced this pull request Mar 9, 2017
…4165)

* Replace the header_links plugin with client-side generated anchors.

Fixes #4124

* Move anchor-link code into a separate script

Also adds a couple comments, for context.

(cherry picked from commit 7a878d2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants