fix(vue-table): return null for empty string in FlexRender to prevent hydration mismatch#6186
Conversation
… hydration mismatch When a column value is an empty string, Vue's SSR would render no content while the client would render an empty text node, causing a hydration mismatch error. This adds a check in FlexRender to return null instead of empty or nullish values, ensuring consistent rendering between server and client. Closes TanStack#6077
🦋 Changeset detectedLatest commit: 87d8da9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
When using
@tanstack/vue-tablewith SSR (e.g., Nuxt), a hydration error occurs inside<td>elements when a column value is an empty string"".As reported in #6077, Vue's server-side renderer produces no content for an empty string, while the client-side renderer creates an empty text node, causing a hydration mismatch.
Root Cause
In the
FlexRendercomponent, whenprops.renderis an empty string:h()branch is skippedreturn props.renderwhich returns""Fix
Added an explicit check for nullish and empty string values before the fallthrough return, returning
nullinstead. This ensures consistent rendering between server and client:Reproduction
See the StackBlitz reproduction from the original issue.
Closes #6077