-
-
Notifications
You must be signed in to change notification settings - Fork 731
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
chore: fix broken docs build / remove unused tag files #2402
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
c7c2252
to
6e3dfb2
Compare
With the new version of docusaurus OpenAPI plugin, sidebar_labels and titles are now quoted correctly, removing the need for this extra bit of code.
6e3dfb2
to
39dbaed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're a ninja for finding this, nice one
"docusaurus-plugin-openapi-docs": "0.0.0-507", | ||
"docusaurus-theme-openapi-docs": "0.0.0-507", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving from a released version (1.4.1) to 0.0.0-<> ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Canary release that includes fixes for 2.2.0. Should be in the next release, but this fixes the issue for now. We may be able to roll back to 1.4.3 with docusaurus 2.1.0, however. I can look into it on monday unless we just want to wait it out.
Issue
So, we've got an issue with our docs build not working. When building for production, we get an error that looks a little bit like this:
Which isn't very helpful at all. If you go into
/node_modules/@docusaurus/core/lib/client/serverEntry.js
and modify therender
function to log the actual error and remove anything chalk-related, you get this instead:That's better, but it's still not very clear.
Getting more info
We've had problems with a similar error message before. Last time it was caused by an empty file that docusaurus couldn't process.
A similar issue has also been described in this docusaurus GitHub issue . That's also what gave me the idea of changing the logging in the dependency.
I'm currently unsure whether this is caused by the openapi docs or something else. I've been in touch with the openapi plugin maintainer and he has been able to see the same error when building for prod locally, but it was due to some old generated files.
Worth noting: this only seems to affect the prod build. Building for dev (
yarn docusaurus start
) works just fine. It also fails locally and in CI, so it is an issue.Updating the logging
To get better logging, you can go into the
/node_modules/@docusaurus/core/lib/client/serverEntry.js
file and update therender
function fromto
That'll yield the errors about the current sidebar in context.
Root cause
Found the issue! 🙋🏼 It's explained in this comment on the openapi docs integration for now, but in short: we have tags defined that we don't use. They're being picked up by docusaurus, but don't have the proper context. That's causing this.
The previously mentioned comment is included here for easy finding in the future:
Root cause explanation
The OpenAPI spec we use to generate the docs has a number of tags listed at the root level. This is necessary for this plugin to pick up tag categories and is, as far as I can tell, also how it should be done.
However, not all of those tags are in use. Specifically, there's 2 tags that are not.
When the plugin generates docs from the spec, it generates pages for all endpoints and all tags and groups them by tag. However, it seems likely that if a tag doesn't have any associated endpoints, then it won't get added to the sidebar because there's no endpoint that references it.
But the doc files for these tags do end up lying around in the directory regardless, and when docusaurus tries to pick up the files in the generated directory, it also tries to pick up the unused tag files. But because they're not part of a sidebar, they end up throwing errors because they can't find the sidebar context.
How I found it
The fact that I got more instances of the error message without the sidebar ref than with it made me pay more attention to the number of errors. I decided to check how many files were in the generated directory and how many files were referenced from the generated sidebar. Turns out the difference there was 2: there were two generated files in the directory that the sidebar didn't reference.
At this point, it was easy enough to try and delete those files before rebuilding, and wouldn't you know: it worked!
Our use case
Now, why do we have tags that are unused in the root spec? Can't we just remove them?
That's a good question with a bit of a complicated answer. Unleash uses an open core model and the OpenAPI integration is part of that open core. The closed-source parts of Unleash are located in another repo and extend the open-source distribution.
Because the OpenAPI spec is configured in the open-source part, enterprise-only tags etc also need to be configured there. Then, when the changes are absorbed into enterprise, we can use the tags there.
It gets more complicated because we use an enterprise instance to generate the docs (because we want enterprise-endpoints to be listed too). The instance uses the latest released instance of Unleash to have the docs most accurately reflect the current state of things.
So, in this case, the tags have been added, but not yet used by any endpoints, which suddenly causes this build failure. We can add the tags to the enterprise-version, but the spec wouldn't be updated before the next release regardless, which will probably be in a week or so.
This isn't an ideal setup, but .. it is what it is.
Solutions and workarounds
As mentioned in the previous section, the reason the build was failing was that there were unused tag files that docusaurus tried to include in the build. Because they don't belong to a sidebar, the compilation failed.
I've reported the issue to the openapi plugin maintainers and am waiting for a response.
However, it seems that having unused root tags declared is invalid according to the spec, so it's something we should look into fixing in the future.
Current workaround: cleaning script
The current workaround is to extend the api cleaning script to manually remove the unused tag files.
Ideal solution: filter root-level tags
Ideally, we shouldn't list unused OpenAPI tags on the root level at all. However, because of the way we add root-level tags (as a predefined, static lists, refer to
src/lib/openapi/index.ts
) and endpoints (dynamically added at runtime) today, we don't really have a clear way to filter the list of tags. This gets even more complicated when taking the enterprise functionality and the potential extra tags they must have.This is, however, something that should definitely be looked into. Working with OpenAPI across multipile repos is already troublesome, so this is just yet another thing to look into.