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

Hook useDoc is called outside the <DocProvider>. #580

Closed
tripheo0412 opened this issue May 19, 2023 · 16 comments
Closed

Hook useDoc is called outside the <DocProvider>. #580

tripheo0412 opened this issue May 19, 2023 · 16 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@tripheo0412
Copy link

Describe the bug

git clone https://github.com/PaloAltoNetworks/docusaurus-openapi-docs.git
git checkout v2.0.0

And using demo folder from the repo.
With 2.0.0-beta.3 Whenever render any page with API docs using @theme/ApiItem I got Hook useDoc is called outside the <DocProvider>.

Expected behavior

Docusaurus render without issue.

Current behavior

Got error when render API docs page

ERROR
Hook useDoc is called outside the <DocProvider>. 
ReactContextError
    at useDoc (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/contexts/doc.js:28:112)
    at DocItemMetadata (webpack-internal:///./node_modules/@docusaurus/theme-classic/lib/theme/DocItem/Metadata/index.js:13:139)
    at renderWithHooks (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:14986:18)
    at mountIndeterminateComponent (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:17812:13)
    at beginWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:19050:16)
    at HTMLUnknownElement.callCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:3946:14)
    at Object.invokeGuardedCallbackDev (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:3995:16)
    at invokeGuardedCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:4057:31)
    at beginWork$1 (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:23960:7)
    at performUnitOfWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:22772:12)

Steps to reproduce

  1. git clone https://github.com/PaloAltoNetworks/docusaurus-openapi-docs.git
  2. git checkout v2.0.0
  3. Add to package.json
"resolutions": {
    "react-live": ">=3.1.1 <4.1.0"
  },
  1. yarn install
  2. yarn start
  3. Got error

Screenshots

image

Your Environment

  • Version used: Docusaurus 2.4.0, plugin-openapi-docs and theme 2.0.0-beta.3, yarn 1.22.19
  • Environment name and version: Node 18.16.0
  • Operating System and version (desktop or mobile): Windows 11, MacOS 13
@tripheo0412 tripheo0412 added the bug Something isn't working label May 19, 2023
@welcome-to-palo-alto-networks

🎉 Thanks for opening your first issue here! Welcome to the community!

@sserrata
Copy link
Member

Hi @tripheo0412, it's difficult to debug without seeing your lock and package.json files, but this error is caused by a mismatch in plugin and Docusaurus versions. Please see the compatibility matrix in the README for more info.

@tripheo0412
Copy link
Author

@sserrata hi! We use the exact package.json in the demo folder on branch v2.0.0

@sserrata
Copy link
Member

Hi @tripheo0412, that may be the case but it's not deterministic on its own - the packages that ultimately get installed are also dependent on the lock file and the ranges allowed in package.json. My advice is to scrub your lock file to ensure consistent versioning for Docusaurus and the plugin. Also, instead of starting from the demo, begin with a base docusaurus project.

Note: the demo project gets deployed continuously for both v1 and v2

@tripheo0412
Copy link
Author

@sserrata we did delete node_modules and lock file in between try combinations of docusaurus version 2.3.1/2.4.0/2.4.1 with the plugins + theme version v2.0.0-beta.3

Docusaurus v2.2.0 works perfectly with plugins + theme v1.7.3

It just I'm excited with the beta and want to try it out :) Thank you for your work 🙏

@Vardominator
Copy link

@sserrata Do you plan on supporting this for the latest version of Docusaurus anytime soon?

@xenobytezero
Copy link

I'm continuing to get this issue, and have rolled back everything progressively (all the way back to Docusaurus 2.2.0 / Plugin 1.4.4, which was said to work in this comment ) with no success, I assume its something else going on in my config. was there any progress on getting to the root of this?

@justinrossack
Copy link

Any fix? I have the same issue.

@clarkmcc
Copy link

Same issue here. When I remove these lines from the config it goes away

docLayoutComponent: "@theme/DocPage",
docItemComponent: "@theme/ApiItem",

@johnrengelman
Copy link

johnrengelman commented Mar 29, 2024

I'm getting this same error with these versions:
@docusaurus/core: 3.1.1
docusaurus-plugin-openapi-docs: 3.0.0-beta.10
docusaurus-theme-openapi-docs: 3.0.0-beta.10

Error:

Hook useDoc is called outside the <DocProvider>. 
ReactContextError
    at useDoc (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/contexts/doc.js:30:112)
    at DocItemMetadata (webpack-internal:///./node_modules/@docusaurus/theme-classic/lib/theme/DocItem/Metadata/index.js:15:139)
    at renderWithHooks (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:16306:18)
    at mountIndeterminateComponent (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:20070:13)
    at beginWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:21583:16)
    at HTMLUnknownElement.callCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:4165:14)
    at Object.invokeGuardedCallbackDev (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:4214:16)
    at invokeGuardedCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:4278:31)
    at beginWork$1 (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:27447:7)
    at performUnitOfWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:26556:12)

One things, I'm doing is using this plugin with a 2nd installation of the docs plugin:

plugins: [
    require.resolve("docusaurus-lunr-search"),
    [
      "docusaurus-plugin-openapi-docs",
      {
        id: "apiDocs",
        docsPluginId: "apis",
        config: {...}
      }
    ],
    [
      "@docusaurus/plugin-content-docs",
      {
        id: "apis",
        sidebarPath: require.resolve('./sidebars/apis.ts'),
        path: "gen/apis",
        routeBasePath: "/apis",
        editUrl: ({versionDocsDirPath, docPath}) =>
        `https://<made up repo>/edit/main/${versionDocsDirPath}/${docPath}`,
        docItemComponent: "@theme/ApiItem"
      } satisfies DocsPlugin.Options,
    ]

related to #726

@blindaa121 blindaa121 added the reviewing 👀 Undergoing manual audit to determine if issue should still be active label Apr 1, 2024
@blindaa121 blindaa121 self-assigned this Apr 1, 2024
@sangaline
Copy link

I'm getting the same error with both docusaurus v3.0.1 and v3.1.1 against v3.0.0-beta.10, but I'm not using a second installation of the docs plugin. There was some discussion of this in #654 and the recommendation was to set docRootComponent: '@theme/DocRoot' in the config. I get the error with or without this setting.

        docs: {
          sidebarPath: require.resolve('./sidebars.js'),
          docItemComponent: '@theme/ApiItem',
          docRootComponent: '@theme/DocRoot',
        },

I've tried many different version pairings between docusaurus and the plugin, and I get the same error each time.

@johnrengelman Do you still get the same error if you remove your second docs installation?

@sserrata
Copy link
Member

sserrata commented Apr 4, 2024

FWIW, the docRootComponent option is not required for the plugin theme to work with v3. If you continue to encounter issues, I recommend starting from a fresh docusaurus site, using the latest release, to help avoid dependency conflicts. I did this a week ago and have successfully tested 3.1.1 and 3.2.0 with no issues. Every time I have encountered this issue there has, without fail, been a dependency conflict observable in my lock file. As I mentioned before, thoroughly scrub your lock file to sniff out any potential conflicts and pin dependencies if necessary/appropriate.

@sangaline
Copy link

Yes, there must have been a dependency conflict in my case. I had already been deleting yarn.lock and node_modules before trying different versions when I was getting the error. After removing all of the dependencies from package.json and incrementally adding them back from most core to least core (i.e. starting with docusaurus core packages, then the openapi plugin, and finally other third party plugins), I was able to get things working. I'm not sure exactly which dependency conflict was causing the issue, but v3.0.0-beta.10 is now working with v3.2.0 after following that approach.

@ChrisSargent
Copy link

ChrisSargent commented Apr 15, 2024

running a yarn dedupe solved this for us, slighty less scary that trying to rebuild yarn.lock

@trajan0x
Copy link

trajan0x commented May 9, 2024

Update:

I've managed to get this to work! The issue as indeed conflicting versions of docusaurus, in addition to facebook/docusaurus#8091

Issue

I'm seeing a similiar issue to @sangaline (and also with or without docRoot in synapsecns/sanguine#2603

My repo is open source so this is pretty easy to replicate:

  1. git clone https://github.com/synapsecns/sanguine
  2. git checkout 066baa6627026dd3a56cc23fcedef4edbe5e82aa (this commit: synapsecns/sanguine@066baa6 )
  3. nvm use
  4. yarn (this is a yarn workspaces monorepo so this gets run from root of the repo)
  5. cd packages/docs/bridge
  6. yarn build

Error output looks like this:

image
    at serverEntry_render (main:56441:358)
    at runNextTicks (node:internal/process/task_queues:60:5)
    at process.processImmediate (node:internal/timers:447:9)
    at async /Users/trajan0x/sanguine/node_modules/p-map/index.js:57:22 {
  [cause]: ReactContextError
      at useDoc (main:56695:112)
      at DocItemMetadata (main:14235:148)
      at Uc (main:59953:44)
      at Xc (main:59955:253)
      at Z (main:59961:89)
      at Yc (main:59964:98)
      at $c (main:59963:140)
      at Z (main:59961:345)
      at Yc (main:59964:98)
      at $c (main:59963:140) {
    message: 'Hook useDoc is called outside the <DocProvider>. '
  }
}

Interestingly enough it works here: synapsecns/sanguine@a6cedda when yarn workspaces not in use. I've tried everything (nohoist, etc).

Anyone have any ideas? Would like to solve the root issue but not sure what it is

So far, I've tried:

interestingly enough though, the yarn why after running this indicates only one version after running this (see here )

I mostly wanna figure out the root issue so I can try to see where it's coming from.

After running yarn why, it seems like I have two different versions of docusaurus/core?

=> Found "@docusaurus/core@3.1.1"
info Has been hoisted to "@docusaurus/core"
info Reasons this module exists
   - "workspace-aggregator-ef9502fc-9caa-4bd5-bcd0-2499816b312b" depends on it
   - Hoisted from "_project_#@docusaurus#plugin-content-blog#@docusaurus#core"
   - Hoisted from "_project_#@docusaurus#plugin-content-docs#@docusaurus#core"
   - Hoisted from "_project_#@docusaurus#plugin-content-pages#@docusaurus#core"
   - Hoisted from "_project_#bridge#@docusaurus#core"
   - Hoisted from "_project_#bridge#@docusaurus#preset-classic#@docusaurus#core"
   - Hoisted from "_project_#bridge#@docusaurus#preset-classic#@docusaurus#plugin-debug#@docusaurus#core"
   - Hoisted from "_project_#bridge#@docusaurus#preset-classic#@docusaurus#plugin-google-analytics#@docusaurus#core"
   - Hoisted from "_project_#bridge#@docusaurus#preset-classic#@docusaurus#plugin-google-gtag#@docusaurus#core"
   - Hoisted from "_project_#bridge#@docusaurus#preset-classic#@docusaurus#plugin-google-tag-manager#@docusaurus#core"
   - Hoisted from "_project_#bridge#@docusaurus#preset-classic#@docusaurus#plugin-sitemap#@docusaurus#core"
   - Hoisted from "_project_#bridge#@docusaurus#preset-classic#@docusaurus#theme-classic#@docusaurus#core"
   - Hoisted from "_project_#bridge#@docusaurus#preset-classic#@docusaurus#theme-search-algolia#@docusaurus#core"
info Disk size without dependencies: "44.8MB"
info Disk size with unique dependencies: "44.8MB"
info Disk size with transitive dependencies: "44.8MB"
info Number of shared dependencies: 716
=> Found "docusaurus-plugin-openapi-docs#@docusaurus/core@3.3.2"
info Reasons this module exists
   - "_project_#bridge#docusaurus-plugin-openapi-docs#@docusaurus#plugin-content-docs" depends on it
   - Hoisted from "_project_#bridge#docusaurus-plugin-openapi-docs#@docusaurus#plugin-content-docs#@docusaurus#core"
=> Found "docusaurus-theme-openapi-docs#@docusaurus/core@3.3.2"
info Reasons this module exists
   - "_project_#bridge#docusaurus-theme-openapi-docs#@docusaurus#theme-common#@docusaurus#plugin-content-blog" depends on it
   - Hoisted from "_project_#bridge#docusaurus-theme-openapi-docs#@docusaurus#theme-common#@docusaurus#plugin-content-blog#@docusaurus#core"
   - Hoisted from "_project_#bridge#docusaurus-theme-openapi-docs#@docusaurus#theme-common#@docusaurus#plugin-content-docs#@docusaurus#core"
   - Hoisted from "_project_#bridge#docusaurus-theme-openapi-docs#@docusaurus#theme-common#@docusaurus#plugin-content-pages#@docusaurus#core"
✨  Done in 1.78s.

@sserrata sserrata added documentation Improvements or additions to documentation and removed bug Something isn't working reviewing 👀 Undergoing manual audit to determine if issue should still be active labels Jun 28, 2024
@sserrata
Copy link
Member

As stated before, this error is associated with mismatches between docusaurus deps and the plugin.

@sserrata sserrata closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests