Skip to content

[V2] Versioning Suggestions #2302

Closed
Closed

Description

@bgub

💥 Proposal

Hi! As I work on developing my Docusaurus site (https://squirrelly.js.org), I've noticed a few problems with the current versioning system.

  1. Pages aren't versioned. This is a problem for me because on one page I host a live playground, and the syntax changes completely between the new and old libraries.
  2. docusaurus.config.js isn't versioned. In my top bar, I link to different docs files. However, no matter what version I'm viewing, they always link to the latest docs (ex. /docs/ instead of docs/some-version/).
  3. There's no way to get the current version in your React Components, so, for example, on the Docusaurus site, the link next to Docusaurus always reads alpha.43, no matter what version you're currently viewing.

With these problems in mind, I'd suggest having a public version variable. This could be provided to MDX files, similarly to withBaseUrl. It would also be nice if you could, in docusaurus.config.js, export a function that accepted a version string as the parameter.

Have you read the Contributing Guidelines on issues?

Yes

Activity

  1. added
    status: needs triage
    proposal
    on Feb 20, 2020
  2. daldridge-cs commented on Feb 21, 2020

    @daldridge-cs

    For item 3 above, I would like to see a hook that provides current version and a list of all versions:

    import useVersion from `@docusaurs/core`; // ? or whatever module...
    
    function myComponent() {
      const ( version, versions } = useVersion();
      return (... whatever ...);
    }
    

    I wrote something workable in my Lunr search plugin by using the useLocation hook from react-router and inspecting the path. Would be much nicer to have Docusaurus provide a mechanism.

  3. bgub commented on Feb 21, 2020

    @bgub
    ContributorAuthor

    @BoMiddleton yes, I have all of that set up and working.

    The problem is that the links in the top navbar only point to the most recent version, rather than whatever version the user is currently looking at.

    Additionally, I can't display different pages depending on the version (unless I parse the URL, which is rather complicated)

  4. amimas commented on Feb 26, 2020

    @amimas

    I don't think "pages" should be versioned. I think the idea of "pages" is different from "docs", which has a completely different requirement.

    If "pages" are versioned, then the following pages become very confusing:

    - index.html
    - help.html
    - contact.html
    

    You'll have to maintain a separate list of pages that should be versioned and should not be versioned. Pretty soon this is going to get out of control...

    Since this thread is about versioning in V2, then I think in your case you can write a custom react component and add that into a doc as part of normal mdx syntax.

  5. amimas commented on Feb 26, 2020

    @amimas

    docusaurus.config.js also should not be versioned. That's a repo-wide/site-wide configuration.

    In my top bar, I link to different docs files. However, no matter what version I'm viewing, they always link to the latest docs

    That sounds like a bug. That doesn't happen in V1

  6. bgub commented on Feb 26, 2020

    @bgub
    ContributorAuthor

    @Animas I agree we shouldn't have versioned pages, but I would love for there to be a way to fetch the current version inside a page, using something like useVersion()

  7. amimas commented on Feb 26, 2020

    @amimas

    I would love for there to be a way to fetch the current version inside a page, using something like useVersion()

    I agree with this too. Just to be clear, I think you meant fetching the current version inside a "doc", not a page since... we're saying pages shouldn't be versioned and in that case, a page doesn't really have a context of what version you're looking at right now.

  8. lex111 commented on Feb 26, 2020

    @lex111
    Contributor

    We will add the useVersion hook, the more we need it to show the version of docs in navbar.

  9. bgub commented on Feb 26, 2020

    @bgub
    ContributorAuthor

    @lex111 let me know if there's anything I can do to help

  10. lex111 commented on Feb 27, 2020

    @lex111
    Contributor

    @nebrelbug well, if you want to implement a similar hook and create the corresponding PR - it would be very very cool 😃

  11. bgub commented on Feb 27, 2020

    @bgub
    ContributorAuthor

    I'll take a look, but I wouldn't be able to do any work until Friday 😄. I would enjoy contributing though -- though I've found several bugs and given feedback, I have yet to earn the Contributor badge by my name :)

  12. yangshun commented on Feb 27, 2020

    @yangshun
    Contributor

    @nebrelbug These are hard problems you've mentioned.

    Pages aren't versioned

    We don't intend to add support for this. Versioning shall be a docs-only feature. Notice that the current versioned docs path is docs/<version>/some-markdown. This is intentional and by design. We want to support the use case of having multiple sets of docs, each with its own version. For example, you're building a mobile SDK for both iOS and Android and want them to have different versions.

    The current docs design is a little flawed. We allow for multiple doc plugins but the versioning approach and commands assume only one docs plugin. In future we should have a namespace for each set of docs, which you define as options passed into the docs plugin. So useVersion() would have to take in a parameter for the namespace, e.g. useVersion('iOS'), useVersion('Android').

  13. slorber commented on May 20, 2020

    @slorber
    Collaborator

    Some things worth mentioning:

    one deployment per version

    If your docusaurus site changes too much across versions and having only docs versioned is a problme, you could also handle the versioning outside of docusaurus, with separate immutable deployments.

    This is the strategy of the ReactJS website.
    This url redirects to a separate Netlify deployment: https://fr.reactjs.org/version/16.3
    The main site only handle the current version: https://fr.reactjs.org/versions/

    This strategy gives the opportunity to affect current version without the risk of breaking something that worked on an older version.

    useVersion() can only work in docs/sidebar comps

    There's currently no concept of "global current version", only docs/sidebar version.
    Such a hook would only work when the user is browsing a docs page.

    On global pages like /live-editor or /contact, there's no version in the url, so we don't know what is the version. At most, we could store the last version browsed by the user in some kind of storage, but that seems hacky (probably possible in userland).

    global site dependencies

    If you have a live editor like react-live somewhere in the app, in 5 different versions, it's unlikely you'll be able to provide your lib's code in the editor scope for the 5 different lib versions (it might be possible with yarn resolution to load a lib in 2 different versions).

    It might be better to publish the live playground as a separate app, and integrate it in your doc.

    For example you could use a unique page, with tabs to select the playground version, and load an iframe or something.

    If this tab system is annoying, you can also create a versioned doc on which you embed the playground iframe thanks to MDX.

  14. 1 remaining item

  15. added and removed
    status: needs triage
    on Jun 5, 2020
  16. krillboi commented on Jun 10, 2020

    @krillboi

    I'd personally also love a version hook, so bump to this!

    Also, are there any plans to implement versioning of assets like images, as mentioned here in #1257?

  17. bravo-kernel commented on Jun 10, 2020

    @bravo-kernel
    Contributor

    Bumping this because we desperately need simple versioning ❤️

  18. slorber commented on Jun 10, 2020

    @slorber
    Collaborator

    @krillboi that's something I'd like to add. Will see how we could add a provider on top of a whole version.

    @bravo-kernel what is simple versioning to you? What's missing that you need in D2?

  19. bravo-kernel commented on Jun 11, 2020

    @bravo-kernel
    Contributor

    Awesome @slorber. I have tried to explain this on multiple occasions and always failed to get it across. Perhaps this real world example will work:

    First the situation:

    • we have a separate repository that holds the code (Powershell Pester)
    • we have a separate repository for our D2 documentation (Powershell Pester Docs)
    • we once created the D2 website with some pages auto-generated by parsing the source code repo, at that time v4
    • time has passed
    • now the source repository is v5 (and will stay v5 for a long time)

    What we would like:

    • create a copy/cut of our current D2 website
    • name that copy v4
    • update D2 master to represent v5
    • use D2 master as current (just as would be the case if we only had one version)

    What we do not want

    • follow the workflow derived from existing next (because for us, v5 is not next version, it's the actual and current one, will not significantly change)

    Hope that makes sense. If you have any additional questions please let me know

  20. slorber commented on Jun 11, 2020

    @slorber
    Collaborator

    @bravo-kernel

    Do you still update v4 docs? If not, you could simply create a docs-v4 branch, deploy it to netlify as a non-versioned D2 deployment, like v4.pester.dev, and have v5 be the master branch (still without D2 versioning).

    If you want v4 and v5 as the same unified SPA under same domain: as far as I understand, what you would like is to have /docs instead of /docs/next ? ie v5 is the current "work in progress version", and you want to edit files in ./docs directly?

    IE somehow it's a workflow where you have already released v5 + v5 initial doc, but you still do a lot of documentation work, so that you don't yet want to copy these files to the versioned folder?

    This feature makes sense to me, we could allow to configure currentVersion: 'next'

  21. bravo-kernel commented on Jun 11, 2020

    @bravo-kernel
    Contributor

    Exactly, this:

    If you want v4 and v5 as the same unified SPA under same domain: as far as I understand, what you would like is to have /docs instead of /docs/next ? ie v5 is the current "work in progress version", and you want to edit files in ./docs directly?

  22. bravo-kernel commented on Jun 11, 2020

    @bravo-kernel
    Contributor

    And updates to the v4 would then have to be done in /docs/v4 but that makes sense from an end-user perspective. Seems to be the location where one expects them to be.

  23. amimas commented on Jun 11, 2020

    @amimas

    This feature makes sense to me, we could allow to configure currentVersion: 'next'

    ☝️ This doesn't quite make sense to me, to be honest. I find it a bit confusing when I read that config.

    From the example that @bravo-kernel mentioned, my understanding is "v5" is their "next version" if it's not fully completed yet or there isn't a "next version" after v5 (as of right now). So, the existing setup/process/workflow of Docusaurus still make sense to me.

    Maybe it's just a matter of being able to "label" the next release. That way, in the versioning page/list, "next release" is named "v5" instead of hard coded to "master/unreleased". So, technically you're not creating the "v5" version in Docusaurus, because it's still "in-progress".

    Not sure if that helps but thought I'd put it out there. I like simplicity and hopefully Docusaurus V2 features does not become over-complicated due to multitude of options that becomes hard to maintain down the road.

  24. krillboi commented on Jun 12, 2020

    @krillboi

    I have a little caveat to add. Let's say I have 3 versions: 1.0, 2.0 and 3.0. This would produce links following this structure:

    /docs/1.0/introduction.mdx
    /docs/2.0/introduction.mdx

    The problem now arises with 3.0. Since this is current stable version, you will access the introduction doc with simply /docs/introduction.mdx but as far as I can tell the link /docs/3.0/introduction.mdx is not created. This is a problem if you release your application/product with direct links to the introduction article with the correct version, i.e. I release 1.0 of my product which contains a link to /docs/1.0/introduction.mdx, then I release 2.0 with /docs/2.0/introduction.mdx.

    Now I release 3.0 where /docs/3.0/introduction.mdx won't work. If I link with /docs/introduction.mdx it always links to current version which means when 4.0 is released, links inside the 3.0 product will link to a wrong version.

    Not sure if that was clear enough but TLDR: all versions should have a corresponding link to its version, also if it happens to be current version.

  25. bravo-kernel commented on Jun 20, 2020

    @bravo-kernel
    Contributor

    As much as I understand that most examples and caveats can be valid, they also show the complexity that we (as requesters of simple versioning) are trying to avoid.

  26. slorber commented on Aug 14, 2020

    @slorber
    Collaborator

    Hey everyone.

    I believe we already addressed some things of this issue.

    • The pages and site config are not going to be versioned.

    • The docs plugin can be "multi instance": Support versioning of individual sections #2528 (comment)

    • The new navbar items "versionDropdown" and "docsVersion" should cover your need. A useVersion hook is likely to not be straightforward to use because it would require passing the docs plugin instance id, + it would always return undefined on pages for examples. If you think it's not enough, please discuss with me your specific usecases in depth. We have hooks in the docs plugin but we consider them "internal" for now. If you decide to use them, please show me how.

    There is an RFC here that should cover the issues related to /docs/next, /docs etc... let's move the conversation here but please let me know if you think something is not resolved.

    #3285

  27. slorber commented on Aug 14, 2020

    @slorber
    Collaborator

    In case you are interested to check these "internal" hooks, see the DocsVersionNavbarItem.tsx component, which permit to display in the navbar the current version, with a fallback to the "latest version".

    As you see, it's not so straightforward to use as useActiveVersion will not necessarily return a result if you are on a page (like the homepage), on the 404/search page etc... We need a fallback to always display something useful.

    import React from 'react';
    import DefaultNavbarItem from './DefaultNavbarItem';
    import {useActiveVersion, useLatestVersion} from '@theme/hooks/useDocs';
    
    const getVersionMainDoc = (version) =>
      version.docs.find((doc) => doc.id === version.mainDocId);
    
    export default function DocsVersionNavbarItem({
      label: staticLabel,
      to: staticTo,
      docsPluginId,
      ...props
    }) {
      const activeVersion = useActiveVersion(docsPluginId);
      const latestVersion = useLatestVersion(docsPluginId);
      const version = activeVersion ?? latestVersion;
      const label = staticLabel ?? version.label;
      const path = staticTo ?? getVersionMainDoc(version).path;
      return <DefaultNavbarItem {...props} label={label} to={path} />;
    }

    Unless you use docs multi instance, docsPluginId="default" (undefined should work too)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions