fix(core): fix duplicate app render when url accessed through .html extension#10059
Draft
fix(core): fix duplicate app render when url accessed through .html extension#10059
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site configuration. |
7 tasks
⚡️ Lighthouse report for the deploy preview of this PR
|
|
Size Change: +143 B (0%) Total Size: 1.59 MB
ℹ️ View Unchanged
|
This was referenced Apr 19, 2024
2 tasks
12 tasks
|
Having similar issue, anyway to solve before the 4.0 release ? |
Collaborator
Author
|
I haven't found any other way to solve this problem, unfortunately. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
When a Docusaurus page is accessed through its non-canonical variant ending with
.html, we get a weird duplicate renderIt looks like React is not able to hydrate and fully recreate an app alongside the existing static markup, leading to duplicated HTML markup
This can be seen in production: https://docusaurus.io/tests.html
Note: technically it's not really a bug because URLs should be accessed through their canonical URLs, that work fine. Users should configure their host properly so that this is always the URL used: https://docusaurus.io/tests
However, not all hosts have access to a "pretty URL" setting that do the redirect to the canonical URL (and apparently Netlify's pretty URL setting does not even work for us...)
I tried investigating the problem and it's very unclear what's causing this issue. It might be React Router v5, or our integration of it through the
<PendingNavigation/>component. It looks like a core problem, not a theme-classic nor layout issue because I can reproduce with an empty theme layout too. We have anormalizeLocationfunction in core (removing the HTML suffix before matching with React Router) but it does not look to be the problem, and using an hardcoded location lead to the same result.It looks like just adding a wrapper div around the
<App>fixes the problem (cf this PR). I suspect this is a bug in React that fails to hydrate when the<App>renders a fragment of multiple elements. I don't mind adding this extra wapper div, it probably wouldn't harm, but let's delay this to v4 considering it might break some user selectors (breaking change? 🤔 ). Also, it's possible that simply upgrading to React Router v6 and React 19 fixes the problem 🤷♂️ . But that does not look like a bad idea to add this wrapper for v4 anyway.Note: to reproduce locally with
docusaurus serve, it requires explicitly disabling clean URLs inserve.ts:Test Plan
Netlify preview should fine for: