question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve Slate's `readOnly` bundle size [ Discussion ]

See original GitHub issue

The easiest, and I would imagine the most common way to interpret the data that Slate Editor has produced is to set readOnly prop in Slate to true. Doing that means there’s no need to force HTML down React’s throat and we’re using a well-tested data structure that’s easy to store, especially in databases like MongoDB.

The problem with this approach, however is the download size for the user. In my case it’s almost 80KB (GZipped, almost 300KB actual) of data that she has to receive, decompress, parse and execute. Much of which might not be necessary at all. screen shot 2018-01-25 at 9 17 27 am

Here are the things that I feel might not be necessary if the <Editor /> is in read-only mode:

  • history.js, change.js and changes - since no changes are being made to the document, there’s no history to store and process
  • text.js - if I understand this correctly it’s a utility module that lets you export plain text compiled from the Editor’s data; which isn’t necessary to display content
  • immutable.js - don’t know if this could be trimmed as this tool seems to be deep within the core of Slate, but perhaps if we don’t use history and changes?
  • react-portal - maybe?

I’d imagine there are a few ways of doing this:

  • use conditional imports within Slate for a few large packages (although I’d imagine this could introduce a whole bunch of browser requests and get ugly, eventually): historyIsNeeded && import("history.js").then(history => { /* ... */ })
  • break Slate into more packages (sounds painful)
  • create a fork with an absolute minimum code required to render, like slate-lite and maintain it separately or as a module within this repo with Learna
  • change how the package is being minified and tree-shaken (perhaps there are some signals we can create to let WebPack know that under read-only we won’t need all the code (guessing that #1568 is related here)

Would love to know if anyone here has any thoughts or ideas about this. Thank you!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

9reactions
dacioromerocommented, Jul 27, 2019

I think it would be incredibly useful if Slate provided a “Reader” component themselves that renders the same as an Editor without the overhead of the editing functions.

7reactions
ianstormtaylorcommented, Oct 26, 2018

@dmitrizzle nice, that’s the best way to do it! I’m going to close this out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactPage
We try minimize bundle size as much as possible. Any UI solely used for editing is not loaded when in readOnly mode.
Read more >
Property Specifiers | Unreal Engine 4.27 Documentation
Implies ReadOnly. Property is native: C++ code is responsible for serializing it and exposing to Garbage Collection.
Read more >
Caching general build artifacts between stages - GitLab.org
What I talk about are really dependencies like vendor/ folders. But actually cache do not work for passing them between stages. Would be...
Read more >
GILTI Conscience: Casual Discussions on Transfer Pricing ...
GILTI Conscience: Casual Discussions on Transfer Pricing, Tax Treaties and Related Topics. 2022. Skadden, Arps, Slate, Meagher & Flom LLP.
Read more >
yjs - npm
It scales well with an unlimited number of users and is well suited for even large documents. Demos: https://github.com/yjs/yjs-demos; Discuss: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found