Skip to content

feat(v2): persist docs preferred version#3543

Merged
slorber merged 13 commits into
masterfrom
slorber/persist-docs-preferred-version
Oct 12, 2020
Merged

feat(v2): persist docs preferred version#3543
slorber merged 13 commits into
masterfrom
slorber/persist-docs-preferred-version

Conversation

@slorber

@slorber slorber commented Oct 6, 2020

Copy link
Copy Markdown
Collaborator

Motivation

Problem:

The versions dropdown is reset to latest version (currently 2.0.0-alpha.66 (unreleased)).

If the user choose to use a specific version, we can persist in local storage that choice so that the dropdown version does not "jump" from one version to the other.

We shouldn't treat the stored value as "safe" because it can be stale and return outdated versionName that is not part of the site anymore, so it's a best effort only.

Asked by @Simek as a possible enhancement to RN website.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

preview

@slorber slorber requested a review from lex111 as a code owner October 6, 2020 13:02
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 6, 2020
@docusaurus-bot

docusaurus-bot commented Oct 6, 2020

Copy link
Copy Markdown
Contributor

Deploy preview for docusaurus-2 ready!

Built with commit d9c4d9b

https://deploy-preview-3543--docusaurus-2.netlify.app

@slorber slorber marked this pull request as draft October 6, 2020 13:09
@slorber

slorber commented Oct 6, 2020

Copy link
Copy Markdown
Collaborator Author

TODO before merge:

  • use a DocsPreferredVersionProvider at the top of the theme, so that persisted state is shared between all usages (currently each hook usage duplicates that state locally)
  • If we land on a v 1.0 page from google, should we persist 1.0 as the preferred version to browse?
  • behavior of the contextual search regarding which version we search into when we are on unversioned pages (related to Contextual doc version search (Algolia/DocSearch) #3396)

@slorber slorber marked this pull request as ready for review October 9, 2020 16:31
@slorber

slorber commented Oct 9, 2020

Copy link
Copy Markdown
Collaborator Author

@lex111 if you're interested to review, this works locally but just need to figure out why Netlify is not happy 😅

This feature was harder than I thought, but worth investing in it. Will likely use it for knowing which version to search in while browsing the homepage etc, for #3550

import {useDocsData} from '@theme/hooks/useDocs';

// TODO why this import does not work!
// import {DEFAULT_PLUGIN_ID} from '@docusaurus/constants';

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

no idea why, but unable to make this work

@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Oct 12, 2020
@slorber slorber merged commit 4130f1a into master Oct 12, 2020
@slorber slorber deleted the slorber/persist-docs-preferred-version branch August 17, 2021 17:57
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
* persist docs preferred version

* add proper implementation for useDocsPreferredVersion

* add proper implementation for useDocsPreferredVersion

* useDocsPreferredVersion => make localstorage read only after mount

* why @docusaurus/constants can't work?

* fix weird TS issue when not duplicating constants

* add basic @docusaurus/constants doc

* attempt to fix docs-only mode where we should not call useDocs hooks

* attempt to fix docs-only mode where we should not call useDocs hooks

* fix children

* encapsulate hacky isDocsPluginEnabled in docsUtils

* use same priority order for all navbar items: activeVersion ?? preferredVersion ?? latestVersion
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: new feature This PR adds a new API or behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants