-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
80 additions
and
130 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
10 | ||
11 |
39 changes: 39 additions & 0 deletions
39
docs/adr/0011-suppressing-hydration-warnings-on-scripts.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 11. Suppressing Hydration Warnings on Scripts | ||
|
||
Date: 2023-03-10 | ||
|
||
## Status | ||
|
||
Accepted | ||
|
||
## Context | ||
|
||
![Hydration Warning](../images/hydration.png) | ||
|
||
When using the app in development mode, the console is filled with hydration warnings. | ||
This usually is because the server and client render different content. | ||
This is not a problem in production, but it is annoying in development. | ||
|
||
In this case however the error stems from a change in the [DOM specification](https://github.com/whatwg/html/pull/2373) | ||
which aims to reduce attack vectors by removing the nonce attribute from elements. | ||
|
||
This inadvertently breaks causes differences between the server and the client side and React freaks out. | ||
|
||
There is an [outstanding issue](https://github.com/facebook/react/issues/26028) to look into the problem. | ||
|
||
We had | ||
a [solution](https://github.com/meza/trance-stack/blob/12907646f56f58c604a1eaeae68f1549d9b570ec/src/components/StaticContent/StaticContent.tsx) | ||
for this that was taken from a [stackoverflow post](https://stackoverflow.com/a/60365819). | ||
|
||
This solution worked, but it seemed to be introducing a lot of "magic" to mask the problem. | ||
|
||
## Decision | ||
|
||
After some discussion, we decided to do the same | ||
thing [Remix does](https://github.com/remix-run/remix/blob/8a07860f3eea1cbfc2c67d0018cb9ac76c6df9d1/packages/remix-react/scroll-restoration.tsx#L70) | ||
and suppress the warnings at the script level without any additional magic. | ||
|
||
## Consequences | ||
|
||
- We will no longer see hydration warnings in development mode. | ||
- We have to keep an eye on the React issue to see if they come up with a better solution. |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
4 changes: 2 additions & 2 deletions
4
src/components/ExposeAppConfig/__snapshots__/ExposeAppConfig.test.tsx.snap
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`ExposeAppConfig > can expose the app config correctly 1`] = ` | ||
<StaticContent | ||
<script | ||
dangerouslySetInnerHTML={ | ||
{ | ||
"__html": "window.appConfig = {\\"hotjarId\\":\\"a-hotjar-id\\",\\"googleAnalyticsId\\":\\"ga-id\\",\\"mixpanelToken\\":\\"a-mixpanel-token\\",\\"visitorId\\":\\"a-visitor-id\\",\\"isProduction\\":true,\\"mixpanelApi\\":\\"a-mixpanel-api\\",\\"splitToken\\":\\"a-split-token\\",\\"cookieYesToken\\":\\"a-cookieyes-token\\",\\"version\\":\\"0.0.0-dev\\",\\"sentryDsn\\":\\"a-sentry-dsn\\"}", | ||
} | ||
} | ||
element="script" | ||
id="app-config" | ||
suppressHydrationWarning={true} | ||
/> | ||
`; |
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
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/components/StaticContent/__snapshots__/StaticContent.test.tsx.snap
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.