facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
56.03k stars 8.41k forks source link

Production build requires refresh to update content #4576

Closed mpmccauley closed 3 years ago

mpmccauley commented 3 years ago

🐛 Bug Report

I am using Gitlab to host the repo for my docusaurus site. Right now we have multiple people committing basic changes to the pages in docs/*. There have been no changes to the other files, just the content within the documentation. Each Friday we pull all changes to a separate node server and build/serve the new content.

The new build and serve does not reflect the changes in the content without a browser refresh. I think it has something to do with the way the browser is caching the information, but I am not sure.

Have you read the [Contributing Guidelines on issues]

Yes

To Reproduce

I'm not sure how to reproduce this bug for everyone. I'm following basic steps to run the website.

  1. git pull
  2. yarn build
  3. yarn serve

Expected behavior

I expect the site to work with all of the new content present.

Actual Behavior

The new content only appears after a browser refresh. If I close the browser and reopen the website the content reverts back to a previous build, requiring another refresh.

The information is all there and working as long as the browser is refreshed. I can't expect that users will do this intuitively.

Your Environment

Reproducible Demo

I don't know how to make this reproducible because it just started happening after months of using docusaurus.

slorber commented 3 years ago

Hi,

Unfortunately I can't help you with so few informations and no site to inspect. You probably do something wrong as it works for others but I can't tell you what.

If you want me to inspect your problem, please create a repro scenario using a public repo, and make it easy for me to understand how to reproduce the problem (including all the exact steps). We'll re-open if all this is provided, otherwise there's nothing I can do.

Maybe you are using the PWA plugin? That could be related.

kuhlaid commented 2 weeks ago

I am seeing the same problem in version 3.5.2 and I believe it may have to do with what is being updated on the site. In my case I was simply updating the _category_json file within one of the docs sub-directories. For my testing I was interested in the following lines of the HTML source of the site. I assumed that if these file names changed then my site content would load the latest content. This is what I was starting with:

<script src="/assets/js/runtime~main.ccf9a1b2.js" defer="defer"></script>
<script src="/assets/js/main.53f392a6.js" defer="defer"></script>

I moved the _category_json file out of the docs subdirectory and into the root (where it would be ignored) and ran yarn run clear then yarn run build and the output was.

<script src="/assets/js/runtime~main.c5fb4d89.js" defer="defer"></script>
<script src="/assets/js/main.e0c3a592.js" defer="defer"></script>

So far, so good.

When I moved the _category_json file back to the docs subdirectory and ran yarn run clear then yarn run build and the output was (notice the main.e0c3a592 file name did not change):

<script src="/assets/js/runtime~main.b3d33da5.js" defer="defer"></script>
<script src="/assets/js/main.e0c3a592.js" defer="defer"></script>

This was no good because the main.e0c3a592.js file name did not change and thus the content of the site is not showing the latest.

After a 'Shift'+Refresh of the browser tab, the site source HTML changed to (note the main.53f392a6.js file name changed):

<script src="/assets/js/runtime~main.ccf9a1b2.js" defer="defer"></script>
<script src="/assets/js/main.53f392a6.js" defer="defer"></script>

Anyway, this is my use-case where Docusaurus serves up stale content.

slorber commented 2 weeks ago

Can you please create a repro with 2 branches and commit the build output so that we can compare the input and the output and troubleshoot this kind of problem? It's hard to help if I can't run the code that causes you troubles

kuhlaid commented 2 weeks ago

Hi @slorber, thank you for the reply. I ran some additional tests on a new Docusaurus site and was not able to reproduce the problem. I then returned to the site that was having the issue and reran the tests and again was not able to reproduce the problem. So, I'm glad I was not able to reproduce, but my apologies for not being able to reproduce. If the issue somehow resurfaces and I am able to reproduce the issue, I will circle back.

If I had to guess maybe I missed the yard run clear step and Docusaurus ran an incremental build instead of a cold build and thus tried to re-use prior build components. At least I now know Docusaurus has both cold and incremental builds.