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/dist/index.js CHANGED
@@ -293,7 +293,11 @@ var TextString = function TextString(props) {
293
293
  var text = props.text,
294
294
  _props$isTrailing = props.isTrailing,
295
295
  isTrailing = _props$isTrailing === void 0 ? false : _props$isTrailing;
296
- var ref = React.useRef(null); // This is the actual text rendering boundary where we interface with the DOM
296
+ var ref = React.useRef(null);
297
+
298
+ var getTextContent = function getTextContent() {
299
+ return "".concat(text !== null && text !== void 0 ? text : '').concat(isTrailing ? '\n' : '');
300
+ }; // This is the actual text rendering boundary where we interface with the DOM
297
301
  // The text is not rendered as part of the virtual DOM, as since we handle basic character insertions natively,
298
302
  // updating the DOM is not a one way dataflow anymore. What we need here is not reconciliation and diffing
299
303
  // with previous version of the virtual DOM, but rather diffing with the actual DOM element, and replace the DOM <span> content
@@ -302,16 +306,26 @@ var TextString = function TextString(props) {
302
306
  // eg makes native spellcheck opt out from checking the text node.
303
307
  // useLayoutEffect: updating our span before browser paint
304
308
 
309
+
305
310
  useIsomorphicLayoutEffect(function () {
306
311
  // null coalescing text to make sure we're not outputing "null" as a string in the extreme case it is nullish at runtime
307
- var textWithTrailing = "".concat(text !== null && text !== void 0 ? text : '').concat(isTrailing ? '\n' : '');
312
+ var textWithTrailing = getTextContent();
308
313
 
309
314
  if (ref.current && ref.current.textContent !== textWithTrailing) {
310
315
  ref.current.textContent = textWithTrailing;
311
316
  } // intentionally not specifying dependencies, so that this effect runs on every render
312
317
  // as this effectively replaces "specifying the text in the virtual DOM under the <span> below" on each render
313
318
 
314
- }); // the span is intentionally same on every render in virtual DOM, actual rendering happens in the layout effect above
319
+ }); // Render text content immediately if it's the first-time render
320
+ // Ensure that text content is rendered on server-side rendering
321
+
322
+ if (!ref.current) {
323
+ return /*#__PURE__*/React__default['default'].createElement("span", {
324
+ "data-slate-string": true,
325
+ ref: ref
326
+ }, getTextContent());
327
+ } // the span is intentionally same on every render in virtual DOM, actual rendering happens in the layout effect above
328
+
315
329
 
316
330
  return /*#__PURE__*/React__default['default'].createElement("span", {
317
331
  "data-slate-string": true,