Skip to content

Last picture overriden on reload #9036

Closed as not planned
Closed as not planned

Description

@pgrange

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

In some blog entries with several pictures, the last picture is overridden by the previous picture when reloading the page.

I've setup the smallest blog entry that I've been able to create that will reproduce the issue in this project: https://github.com/pgrange/docusaurus-final-picture

I'm sorry I did not see https://new.docusaurus.io/ before trying to qualify the issue, I hope you can work with that.

The project has been created with:

npx create-docusaurus@latest docusaurus-final-picture classic

Then the following commit creates a blog entry which exhibits the issue.

The issue can be seen on the following page (when running locally): http://localhost:3000/blog/2023-05

Reproducible demo

http://localhost:3000/blog/2023-05 (sorry)

Steps to reproduce

git clone https://github.com/pgrange/docusaurus-final-picture.git
cd docusaurus-final-picture
yarn
yarn build
yarn serve

Then go to the following page: http://localhost:3000/blog/2023-05

You should see three images, a 1, a 2 and a 3.

Click reload.

Expected behavior

You should still see three images, a 1, a 2 and a 3 after reloading the page.

Actual behavior

You see a 1, a 2 and a 2 again. The 3 has been replaced by the 2.

Your environment

Self-service

  • I'd be willing to fix this bug myself.

Activity

  1. added
    bug
    status: needs triage
    on Jun 5, 2023
  2. Josh-Cena commented on Jun 7, 2023

    @Josh-Cena
    Collaborator

    Thank you for the great repro! Very easy to follow. I'll try to investigate.

  3. Josh-Cena commented on Jun 7, 2023

    @Josh-Cena
    Collaborator

    Unfortunately I can't reproduce this... I'm using localhost, Safari 16.5, macOS 13.4. Would be great if you can make a shareable repro.

  4. added
    status: needs more information
    and removed
    status: needs triage
    on Jun 7, 2023
  5. pgrange commented on Jun 7, 2023

    @pgrange
    Author

    I'm so sorry to read that you can't reproduce. It's quite deterministic on my side and we've observed it on our website that was built by GitHub action running on Ubuntu.

    Just to confirm, if I open http://localhost:3000/blog then the first time, picture 3 html source code is:

    <img loading="lazy" alt="Third picture" src="/assets/images/3-802964b3f2763fcb7b9245721bd8c9ca.jpg" width="1868" height="2140" class="img_ev3q">
    

    If I hit reload now, picture 3 html source code becomes:

    <img loading="lazy" alt="Second picture" src="/assets/images/2-98f85917bd3f9e6fa6724066c22455d8.jpg" width="1868" height="2140" class="img_ev3q">
    

    Also, if I prevent javascript from running (I tried by putting a breakpoint in the source of the page) then there is no problem. So it's really like the html is good but is immediately tempered with by javascript.

    It's important to note that I have to reload the page to see the problem.

  6. pgrange commented on Jun 7, 2023

    @pgrange
    Author

    FYI, I asked some colleagues here to see if they can reproduce the bug and I haven't found anyone not having the issue yet.

  7. slorber commented on Jun 8, 2023

    @slorber
    Collaborator

    I am not able to reproduce either on your repro:

    CleanShot 2023-06-08 at 10 28 16@2x

    Are you sure your repro is correct and you and your colleagues can reproduce deterministically the issue on your repro? Can you host your repro somewhere and then record us a video or screenshot showing the URL as a proof?

    Maybe this problem only happens in your real app? In this case please share the URL and/or record a video too.


    That is probably because of a React hydration issue. In some cases, the static HTML produced at build time is slightly different from the HTML rendered by React on the client, and the mismatch can create weird issues like this. It already happened in the past.

    Docusaurus itself has some little mismatches that are now reported in the console with React 18, and I'm in the process of fixing them as part of the React 18 upgrade here: #8961

    It's possible that it's the fault of Docusaurus hydration mismatches, we already saw that happen in the past (#5617). Apart from waiting for the React 18 upgrade, you can try to add extra JSX tags (divs, spans, sections whatever) around your content, and this may help React avoid this issue.

  8. slorber commented on Jun 8, 2023

    @slorber
    Collaborator

    Edit: indeed I can see the problem on prod build on your repro (not with the dev server) and it looks like an hydration issue due to a mismatch somewhere else in the Docusaurus layout (should be fixed with React 18).

    In the meantime this is a workaround that seems to work:

    <div>
    
    ![Third picture](./img/3.jpg) <small><center>Do you see a 3?</center></small>
    
    </div>
  9. removed
    status: needs more information
    on Jun 8, 2023
  10. Josh-Cena commented on Jun 8, 2023

    @Josh-Cena
    Collaborator

    Ah yes... I forgot I need to run a build to see hydration problems😅

    Wondering why this would be though. My guess is that there's invalid markup "fixed" by Terser.

  11. slorber commented on Jun 8, 2023

    @slorber
    Collaborator

    Wondering why this would be though. My guess is that there's invalid markup "fixed" by Terser.

    That's a possibility, but the React 18 PR also reported a few issues that I fixed, so we'll see if we can still reproduce once we upgrade

  12. Josh-Cena commented on Jun 8, 2023

    @Josh-Cena
    Collaborator

    there's invalid markup

    Just tested, Terser didn't change anything in the generated HTML. The JS chunk also looks okay-ish. This seems weird.

  13. vixducis commented on Jun 15, 2023

    @vixducis

    I have a closely related issue on one of my projects. It can be seen on the following page:
    https://handleiding.tbvs.be/leerlingenrekeningen/Schooljaar/

    Clicking on the sidebar loads the last image correctly, reloading the page or accessing it directly by the URL causes the last image to be replaced it with the previous one. That page leads to this markdown file: https://github.com/toolbox-kobavzw/toolbox-handleiding/blob/master/docs/leerlingenrekeningen/3.%20Schooljaar/index.mdx?plain=1

    My repository is open, so feel free to use it to debug the issue.

  14. slorber commented on Jun 15, 2023

    @slorber
    Collaborator

    This is likely to be fixed in Docusaurus v3 with React 18, I'm going to release the first alphas very soon but in the meantime you can use a canary release.

    Please try to upgrade to a canary/alpha/beta/rc (or v3 once released) and if it's not fixed we'll debug it. It is not worth spending time debugging existing sites considering the issue might already be fixed

  15. slorber commented on Sep 25, 2023

    @slorber
    Collaborator

    Looks fixed in Docusaurus v3 beta 0

    CleanShot 2023-09-25 at 18 02 04@2x
  16. added
    closed: can't repro
    closed: wontfix
    and removed
    closed: can't repro
    on Sep 25, 2023
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

    bugclosed: wontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions