slate-react 0.72.6 → 0.72.7-20220221103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # slate-react
2
2
 
3
+ ## 0.72.7-20220221103
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4798](https://github.com/ianstormtaylor/slate/pull/4798) [`3796c514`](https://github.com/ianstormtaylor/slate/commit/3796c514d6da0db8656486151147d92e73a2350a) Thanks [@hueyhe](https://github.com/hueyhe)! - Fix text not rendered on ssr
8
+
3
9
  ## 0.72.6
4
10
 
5
11
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/components/string.tsx"],"names":[],"mappings":";AACA,OAAO,EAAU,IAAI,EAAQ,OAAO,EAAQ,MAAM,OAAO,CAAA;AAKzD;;GAEG;AAEH,QAAA,MAAM,MAAM,UAAW;IACrB,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,IAAI,CAAA;CACX,gBAsCA,CAAA;AAoDD,eAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/components/string.tsx"],"names":[],"mappings":";AACA,OAAO,EAAU,IAAI,EAAQ,OAAO,EAAQ,MAAM,OAAO,CAAA;AAKzD;;GAEG;AAEH,QAAA,MAAM,MAAM,UAAW;IACrB,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,IAAI,CAAA;CACX,gBAsCA,CAAA;AAkED,eAAe,MAAM,CAAA"}
package/dist/index.es.js CHANGED
@@ -151,7 +151,11 @@ var TextString = props => {
151
151
  text,
152
152
  isTrailing = false
153
153
  } = props;
154
- var ref = useRef(null); // This is the actual text rendering boundary where we interface with the DOM
154
+ var ref = useRef(null);
155
+
156
+ var getTextContent = () => {
157
+ return "".concat(text !== null && text !== void 0 ? text : '').concat(isTrailing ? '\n' : '');
158
+ }; // This is the actual text rendering boundary where we interface with the DOM
155
159
  // The text is not rendered as part of the virtual DOM, as since we handle basic character insertions natively,
156
160
  // updating the DOM is not a one way dataflow anymore. What we need here is not reconciliation and diffing
157
161
  // with previous version of the virtual DOM, but rather diffing with the actual DOM element, and replace the DOM <span> content
@@ -160,16 +164,26 @@ var TextString = props => {
160
164
  // eg makes native spellcheck opt out from checking the text node.
161
165
  // useLayoutEffect: updating our span before browser paint
162
166
 
167
+
163
168
  useIsomorphicLayoutEffect(() => {
164
169
  // null coalescing text to make sure we're not outputing "null" as a string in the extreme case it is nullish at runtime
165
- var textWithTrailing = "".concat(text !== null && text !== void 0 ? text : '').concat(isTrailing ? '\n' : '');
170
+ var textWithTrailing = getTextContent();
166
171
 
167
172
  if (ref.current && ref.current.textContent !== textWithTrailing) {
168
173
  ref.current.textContent = textWithTrailing;
169
174
  } // intentionally not specifying dependencies, so that this effect runs on every render
170
175
  // as this effectively replaces "specifying the text in the virtual DOM under the <span> below" on each render
171
176
 
172
- }); // the span is intentionally same on every render in virtual DOM, actual rendering happens in the layout effect above
177
+ }); // Render text content immediately if it's the first-time render
178
+ // Ensure that text content is rendered on server-side rendering
179
+
180
+ if (!ref.current) {
181
+ return /*#__PURE__*/React.createElement("span", {
182
+ "data-slate-string": true,
183
+ ref: ref
184
+ }, getTextContent());
185
+ } // the span is intentionally same on every render in virtual DOM, actual rendering happens in the layout effect above
186
+
173
187
 
174
188
  return /*#__PURE__*/React.createElement("span", {
175
189
  "data-slate-string": true,