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

fix(core): ensure stable webpack theme aliases sorting #6878

Merged
merged 1 commit into from
Mar 9, 2022
Merged

fix(core): ensure stable webpack theme aliases sorting #6878

merged 1 commit into from
Mar 9, 2022

Conversation

jrvidal
Copy link
Contributor

@jrvidal jrvidal commented Mar 8, 2022

Motivation

The comparison function provided for themes is not consistent. The resulting array order is implementation-dependent, which means it could break between Node releases (unlikely, though) or if somebody tried to run this code in a browser somehow 😬

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

The only way to test this is by not using V8:

Before:

[
  '@theme/Navbar',
  '@theme/NavbarItem',
  '@theme/NavbarItem/DefaultNavbarItem',
].sort((a, b) => a.includes(`${b}/`) ? -1 : 0)

Chrome: ['@theme/Navbar', '@theme/NavbarItem/DefaultNavbarItem', '@theme/NavbarItem']
Firefox: [ "@theme/Navbar", "@theme/NavbarItem", "@theme/NavbarItem/DefaultNavbarItem"]

After:

[
  '@theme/Navbar',
  '@theme/NavbarItem',
  '@theme/NavbarItem/DefaultNavbarItem',
].sort((a, b) => a.includes(`${b}/`) ? -1 : (b.includes(`${a}/`) ? 1 : 0))

Chrome: ['@theme/Navbar', '@theme/NavbarItem/DefaultNavbarItem', '@theme/NavbarItem']
Firefox: [ "@theme/Navbar", "@theme/NavbarItem/DefaultNavbarItem", "@theme/NavbarItem" ]

Related PRs

Current implementation introduced here: #5383

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 8, 2022
@netlify
Copy link

netlify bot commented Mar 8, 2022

✔️ [V2]
Built without sensitive environment variables

🔨 Explore the source changes: 8ae30b0

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/6227dcc5dc718e0007aeb1f1

😎 Browse the preview: https://deploy-preview-6878--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Mar 8, 2022

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 48
🟢 Accessibility 100
🟠 Best practices 83
🟢 SEO 100
🟢 PWA 90

Lighthouse ran on https://deploy-preview-6878--docusaurus-2.netlify.app/

Copy link
Collaborator

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

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

Oh, I didn't realize we are using 0! What if we just change 0 to 1? Could that ensure stable sorting?

@Josh-Cena Josh-Cena changed the title fix: webpack aliases sorting fix: ensure stable webpack aliases sorting Mar 9, 2022
@Josh-Cena Josh-Cena added the pr: polish This PR adds a very minor behavior improvement that users will enjoy. label Mar 9, 2022
@Josh-Cena Josh-Cena changed the title fix: ensure stable webpack aliases sorting fix(core): ensure stable webpack theme aliases sorting Mar 9, 2022
Copy link
Collaborator

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

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

I just re-parsed and understood where you are coming from 🤦‍♂️ Thanks a lot for catching that!

@Josh-Cena Josh-Cena merged commit 73df485 into facebook:main Mar 9, 2022
@jrvidal jrvidal deleted the sort-fix branch March 9, 2022 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: polish This PR adds a very minor behavior improvement that users will enjoy.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants