diff --git a/.changeset/tender-insects-rest.md b/.changeset/tender-insects-rest.md new file mode 100644 index 000000000..a6f73b7b6 --- /dev/null +++ b/.changeset/tender-insects-rest.md @@ -0,0 +1,5 @@ +--- +"victory-core": patch +--- + +Fix text label measurements after SSR hydration mismatch diff --git a/packages/victory-core/src/victory-util/textsize.ts b/packages/victory-core/src/victory-util/textsize.ts index b41b0b153..3d15347bc 100644 --- a/packages/victory-core/src/victory-util/textsize.ts +++ b/packages/victory-core/src/victory-util/textsize.ts @@ -296,7 +296,11 @@ const styleToKeyComponent = (style) => { const _measureDimensionsInternal = memoize( (text: string | string[], style?: TextSizeStyleInterface) => { - const containerElement = _getMeasurementContainer(); + let containerElement = _getMeasurementContainer(); + if (!containerElement.isConnected) { + _getMeasurementContainer.cache.clear?.(); + containerElement = _getMeasurementContainer(); + } const lines = _splitToLines(text); let heightAcc = 0;