Skip to content

Commit

Permalink
[fix] Image SSR hydration warnings
Browse files Browse the repository at this point in the history
React doesn't currently provide an API for defining SSR-safe IDs, so we have to
suppress the hydration warnings that occur.

The 'useOpaqueIdentifier' hook is intended to support this use case but is not
currently a public API and development has been paused.
facebook/react#17322.

Close #1375
  • Loading branch information
necolas committed Sep 9, 2020
1 parent e9d81af commit 1e12365
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/react-native-web/src/exports/Image/index.js
Expand Up @@ -35,7 +35,7 @@ function createTintColorSVG(tintColor, id) {
return tintColor && id != null ? (
<svg style={{ position: 'absolute', height: 0, visibility: 'hidden', width: 0 }}>
<defs>
<filter id={`tint-${id}`}>
<filter id={`tint-${id}`} suppressHydrationWarning={true}>
<feFlood floodColor={`${tintColor}`} key={tintColor} />
<feComposite in2="SourceAlpha" operator="atop" />
</filter>
Expand All @@ -46,7 +46,6 @@ function createTintColorSVG(tintColor, id) {

function getFlatStyle(style, blurRadius, filterId) {
const flatStyle = { ...StyleSheet.flatten(style) };

const { filter, resizeMode, shadowOffset, tintColor } = flatStyle;

// Add CSS filters
Expand Down Expand Up @@ -284,6 +283,7 @@ const Image = forwardRef<ImageProps, *>((props, ref) => {
{ backgroundImage, filter },
backgroundSize != null && { backgroundSize }
]}
suppressHydrationWarning={true}
/>
{hiddenImage}
{createTintColorSVG(tintColor, filterRef.current)}
Expand Down

0 comments on commit 1e12365

Please sign in to comment.