GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Treat empty string as null by salazarm · Pull Request #22807 · react/react

Conversation

@salazarm

@salazarm salazarm commented Nov 22, 2021

Copy link
Copy Markdown
Contributor

Summary

When we server render an empty string from the server the browser does not create a text node for the empty string. This leads to a hydration mismatch. Since #22629 we now throw on mismatches and fallback to client render. This causes empty strings to always lead to client rendering #22784. To fix this we're making the client treat empty strings as null so that there is no mismatch.

How did you test this change?

Jest

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

karlhorky reacted with thumbs up emoji wongmjane and karlhorky reacted with heart emoji
All reactions
  • 👍 1 reaction
  • ❤️ 2 reactions
Marco Salazar
treat empty string as null
9cabd85
@facebook-github-bot facebook-github-bot added the CLA Signed label Nov 22, 2021
@salazarm
salazarm requested review from acdlite and sebmarkbage November 22, 2021 20:59
@facebook-github-bot facebook-github-bot added the React Core Team Opened by a member of the React Core Team label Nov 22, 2021
@salazarm
salazarm requested a review from gaearon November 22, 2021 20:59
@sizebot

sizebot commented Nov 22, 2021

Copy link
Copy Markdown

Comparing: 149b420...9cabd85

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js +0.02% 129.98 kB 130.01 kB = 41.56 kB 41.57 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.02% 134.74 kB 134.77 kB +0.01% 42.96 kB 42.96 kB
facebook-www/ReactDOM-prod.classic.js +0.03% 424.49 kB 424.63 kB +0.01% 78.24 kB 78.24 kB
facebook-www/ReactDOM-prod.modern.js +0.03% 413.04 kB 413.19 kB = 76.50 kB 76.51 kB
facebook-www/ReactDOMForked-prod.classic.js +0.03% 424.49 kB 424.63 kB +0.01% 78.24 kB 78.25 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 9cabd85

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sebmarkbage
sebmarkbage approved these changes Nov 23, 2021
View reviewed changes
@eps1lon

eps1lon commented Nov 23, 2021

Copy link
Copy Markdown
Collaborator

Fixes #22784: https://codesandbox.io/s/react-18-fixed-emptry-string-hydration-mismatch-forked-wvvm9?file=/package.json

SergChr reacted with thumbs down emoji
All reactions
  • 👎 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@salazarm
salazarm merged commit c1220eb into react:main Nov 23, 2021
@eps1lon eps1lon mentioned this pull request Nov 23, 2021
React 18 Bug: Hydration mismatch if empty string is rendered #22784
Closed
facebook-github-bot pushed a commit to react/react-native that referenced this pull request Nov 29, 2021
Andrei Shikov @facebook-github-bot
React Native sync for revisions c0c71a8...c1220eb
a596e98
Summary:
This sync includes the following changes:
- **[c1220eb](react/react@c1220ebdd )**: treat empty string as null ([#22807](react/react#22807)) //<salazarm>//
- **[09d9b17](react/react@09d9b1775 )**: Update deprecated features in ESLint configuration files. ([#22767](react/react#22767)) //<Esteban>//
- **[bddbfb8](react/react@bddbfb86d )**: Revert "Fix Node package.json ./ exports deprecation warning ([#22783](react/react#22783))" ([#22792](react/react#22792)) //<Sebastian Silbermann>//
- **[b831aec](react/react@b831aec48 )**: chore(fast-refresh): double check wasMounted ([#22740](react/react#22740)) //<anc95>//
- **[8edeb78](react/react@8edeb787b )**: Fix Node package.json ./ exports deprecation warning ([#22783](react/react#22783)) //<Rin Arakaki>//
- **[fdc1d61](react/react@fdc1d617a )**: Flag for client render fallback behavior on hydration mismatch ([#22787](react/react#22787)) //<salazarm>//
- **[aa19d56](react/react@aa19d569b )**: Add test selectors to experimental build ([#22760](react/react#22760)) //<Brian Vaughn>//
- **[520ffc7](react/react@520ffc77a )**: Use globalThis if possible for native fetch in browser build ([#22777](react/react#22777)) //<Jiachi Liu>//
- **[afbc2d0](react/react@afbc2d08f )**: Remove unused react-internal/invariant-args ESLint rule. ([#22778](react/react#22778)) //<Esteban>//
- **[ca94e26](react/react@ca94e2680 )**: Remove 'packages/shared/invariant.js' ([#22779](react/react#22779)) //<Esteban>//
- **[8356471](react/react@83564712b )**: Move SuspenseList to experimental channel ([#22765](react/react#22765)) //<Andrew Clark>//
- **[d4144e6](react/react@d4144e6e5 )**: fix : grammatical typo for test description ([#22764](react/react#22764)) //<Brijesh Prasad>//
- **[0b32951](react/react@0b329511b )**: chore: fix comment typo ([#22657](react/react#22657)) //<Han Han>//
- **[e6f60d2](react/react@e6f60d2ad )**: fix typos ([#22715](react/react#22715)) //<180909>//

Changelog:
[General][Changed] - React Native sync for revisions c0c71a8...c1220eb

jest_e2e[run_all_tests]

Reviewed By: yungsters

Differential Revision: D32646433

fbshipit-source-id: c534ee7a17141634700c90fc2c7b34bfbe17887a
@salazarm
salazarm deleted the reactIgnoreEmptyString branch February 10, 2022 14:27
zhengjitf pushed a commit to zhengjitf/react that referenced this pull request Apr 15, 2022
@salazarm @zhengjitf
treat empty string as null (react#22807)
f25930c
@ngunna ngunna mentioned this pull request Aug 30, 2022
chore: Support React v18 ubilabs/react-geosuggest#495
Merged
4 tasks done
@rickhanlonii rickhanlonii mentioned this pull request Oct 18, 2022
Empty string without <Text> component does not cause error / crash react/react-native#35002
Closed
@li-jia-nan li-jia-nan mentioned this pull request Dec 6, 2022
antd 测试库迁移的那些事儿 li-jia-nan/my-blog#22
Open
@sebmarkbage sebmarkbage mentioned this pull request Mar 1, 2024
Clean up empty string special cases #28475
Merged
rickhanlonii pushed a commit that referenced this pull request Mar 1, 2024
@sebmarkbage
Clean up empty string special cases (#28475)
bb4b147
This was fixed in #22807 so we
don't need these special cases anymore.
github-actions Bot pushed a commit that referenced this pull request Mar 1, 2024
@rickhanlonii
Clean up empty string special cases (#28475)
df4b99c
This was fixed in #22807 so we
don't need these special cases anymore.

DiffTrain build for [bb4b147](bb4b147)
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
@sebmarkbage @AndyPengc12
Clean up empty string special cases (react#28475)
78ee302
This was fixed in react#22807 so we
don't need these special cases anymore.
Akshato07 pushed a commit to Akshato07/-Luffy that referenced this pull request Feb 20, 2025
@rickhanlonii
Clean up empty string special cases (#28475)
dbab28d
This was fixed in react/react#22807 so we
don't need these special cases anymore.

DiffTrain build for commit react/react@bb4b147.
This was referenced Jan 3, 2026
feat: add jsx-no-leaked-render rule jokull/tsgolint#1
Open
feat: add jsx-no-leaked-render rule oxc-project/tsgolint#556
Closed
mrizwanashiq pushed a commit to mrizwanashiq/react that referenced this pull request Jun 25, 2026
@salazarm
treat empty string as null (react#22807)
399370c
hanzo-dev pushed a commit to hanzoai/react that referenced this pull request Sep 9, 2026
@salazarm
treat empty string as null (react#22807)
6ceaf02
hanzo-dev pushed a commit to hanzoai/react that referenced this pull request Sep 9, 2026
@sebmarkbage
Clean up empty string special cases (react#28475)
9e689c1
This was fixed in react#22807 so we
don't need these special cases anymore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@acdlite acdlite Awaiting requested review from acdlite
@gaearon gaearon Awaiting requested review from gaearon
1 more reviewer
@sebmarkbage sebmarkbage sebmarkbage approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@salazarm @sizebot @eps1lon @sebmarkbage @facebook-github-bot
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.