An editor shell should own common interaction patterns while leaving document-specific fields to the feature that understands them. Reuse the save state, keyboard behavior, preview frame, and publish controls; avoid forcing unrelated editors into one large component with dozens of optional props.
Separate draft from persisted content
The editor needs to represent at least the last saved value and the current draft. Make save status explicit—idle, dirty, saving, saved, or error—so a user can tell whether a change reached the server. Prevent duplicate submissions while a save is in flight, and do not mark a draft saved until the server confirms success.
Autosave can be useful, but it needs debounce, cancellation or request ordering, and a visible failure state. If an older save can complete after a newer save, include a version or serialize writes. Warn about unsaved changes on navigation only when there is actually a draft that would be lost.
Keep preview and publishing safe
Render preview through the same sanitization path as published content. Treat preview as untrusted input and do not create a separate renderer with weaker rules. Publishing should be a separate action if it changes visibility, triggers notifications, or needs confirmation. Check permission on the server for every mutation; hiding a button is not access control.
Test keyboard-only editing, slow requests, failed saves, rapid consecutive changes, and navigation with a dirty draft. A shared shell is worthwhile when it makes these behaviors consistent without obscuring the content model.
Track which version the editor has saved
An editor has at least three useful boundaries. The document is the current content, the saved revision is the last acknowledged content, and the preview is a rendered view with its own format and permissions. If autosave responds after the writer has made another edit, a boolean saved field alone can hide newer unsaved content. Compare the acknowledged revision with the one on screen and leave the editor dirty when they differ.
Use one owner for state that the toolbar, status text, and navigation guard need to share. React describes this as lifting state to the closest common parent and passing the relevant values or handlers down. Keep editor-specific rendering behind a clear interface, while persistence and access checks stay on the server. Test late responses and navigation with unsaved changes before relying on the save indicator. React on sharing state
Worked example
Keep persistence and authorization outside this interface. The content representation must be documented; readOnly controls interaction and is not a server permission check.
tsinterface EditorShellProps { content: string; onChange: (value: string) => void; readOnly?: boolean; }




Community
Discussion
Loading comments…