-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
fix(core): fix duplicate app render when url accessed through .html extension #10059
Draft
slorber
wants to merge
2
commits into
main
Choose a base branch
from
slorber/attempt-fix-duplicate-render
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+92
−84
Conversation
This file contains 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
✅ [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
|
slorber
added
the
pr: breaking change
Existing sites may not build successfully in the new version. Description contains more details.
label
Apr 19, 2024
Size Change: +143 B (0%) Total Size: 1.59 MB
ℹ️ View Unchanged
|
This was referenced Apr 19, 2024
2 tasks
12 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
CLA Signed
Signed Facebook CLA
pr: breaking change
Existing sites may not build successfully in the new version. Description contains more details.
pr: bug fix
This PR fixes a bug in a past release.
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 anormalizeLocation
function 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: