Skip to content

Commit

Permalink
Remove intermediate render cycle from useEditor
Browse files Browse the repository at this point in the history
Possibly fixes ueberdosis#3345
  • Loading branch information
C-Hess authored and janthurau committed Nov 18, 2023
1 parent 55377eb commit 1892b70
Show file tree
Hide file tree
Showing 49 changed files with 4 additions and 204 deletions.
4 changes: 0 additions & 4 deletions demos/src/Commands/Cut/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import StarterKit from '@tiptap/starter-kit'
import React, { useCallback } from 'react'

const MenuBar = ({ editor }) => {
if (!editor) {
return null
}

const onCutToStart = useCallback(() => {
editor.chain().cut({ from: editor.state.selection.$from.pos, to: editor.state.selection.$to.pos }, 1).run()
}, [editor])
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Examples/Book/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import React from 'react'
import { content } from '../content.js'

const MenuBar = ({ editor }) => {
if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Examples/CSSModules/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import React from 'react'
import styles from './index.module.css'

const MenuBar = ({ editor }) => {
if (!editor) {
return null
}

return (
<div className={`toolbar ${styles.toolbar}`}>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Examples/CodeBlockLanguage/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ lowlight.registerLanguage('js', js)
lowlight.registerLanguage('ts', ts)

const MenuBar = ({ editor }) => {
if (!editor) {
return null
}

return (
<button onClick={() => editor.chain().focus().toggleCodeBlock().run()} className={editor.isActive('codeBlock') ? 'is-active' : ''}>
code block
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Examples/Default/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import React from 'react'
const MenuBar = () => {
const { editor } = useCurrentEditor()

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Examples/Formatting/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import StarterKit from '@tiptap/starter-kit'
import React from 'react'

const MenuBar = ({ editor }) => {
if (!editor) {
return null
}

return (
<>
<button onClick={() => editor.chain().focus().toggleHeading({ level: 1 }).run()} className={editor.isActive('heading', { level: 1 }) ? 'is-active' : ''}>
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Examples/Tables/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ export const tableHTML = `
`

const MenuBar = ({ editor }) => {
if (!editor) {
return null
}

return (
<>
<button onClick={() => editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run()}>
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Experiments/IsolatingClear/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ const WrapperBlock = Node.create({
})

const MenuBar = ({ editor }) => {
if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Extensions/CharacterCount/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<div>
<EditorContent editor={editor} />
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Extensions/Color/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<div>
<input
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Extensions/History/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<div>
<button onClick={() => editor.chain().focus().undo().run()} disabled={!editor.can().undo()}>
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Extensions/ListKeymap/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Extensions/TextAlign/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<div>
<button
Expand Down
8 changes: 0 additions & 8 deletions demos/src/GuideContent/ExportJSON/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export default () => {
})

useEffect(() => {
if (!editor) {
return undefined
}

// Get the initial content …
setJson(editor.getJSON())

Expand Down Expand Up @@ -57,10 +53,6 @@ export default () => {
editor.chain().clearContent(true).focus().run()
}, [editor])

if (!editor) {
return null
}

return (
<>
<div className="actions">
Expand Down
8 changes: 0 additions & 8 deletions demos/src/GuideContent/ReadOnly/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,9 @@ export default () => {
})

useEffect(() => {
if (!editor) {
return undefined
}

editor.setEditable(editable)
}, [editor, editable])

if (!editor) {
return null
}

return (
<>
<div className="checkbox">
Expand Down
4 changes: 0 additions & 4 deletions demos/src/GuideNodeViews/TableOfContents/React/Component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export default ({ editor }) => {
useEffect(handleUpdate, [])

useEffect(() => {
if (!editor) {
return null
}

editor.on('update', handleUpdate)

return () => {
Expand Down
4 changes: 0 additions & 4 deletions demos/src/GuideNodeViews/TableOfContents/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,5 @@ export default () => {
`,
})

if (!editor) {
return null
}

return <EditorContent editor={editor} />
}
4 changes: 0 additions & 4 deletions demos/src/Marks/Bold/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Marks/Code/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Marks/Highlight/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Marks/Italic/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Marks/Link/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ export default () => {
.run()
}, [editor])

if (!editor) {
return null
}

return (
<>
<button onClick={setLink} className={editor.isActive('link') ? 'is-active' : ''}>
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Marks/Strike/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Marks/Subscript/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Marks/Superscript/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Marks/TextStyle/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,5 @@ export default () => {
`,
})

if (!editor) {
return null
}

return <EditorContent editor={editor} />
}
4 changes: 0 additions & 4 deletions demos/src/Marks/Underline/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Nodes/Blockquote/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<div>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Nodes/BulletList/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Nodes/CodeBlock/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Nodes/CodeBlockLowlight/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Nodes/Document/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ export default () => {
`,
})

if (!editor) {
return null
}

return <EditorContent editor={editor} />
}
4 changes: 0 additions & 4 deletions demos/src/Nodes/HardBreak/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button onClick={() => editor.chain().focus().setHardBreak().run()}>setHardBreak</button>
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Nodes/Heading/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button
Expand Down
4 changes: 0 additions & 4 deletions demos/src/Nodes/HorizontalRule/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ export default () => {
`,
})

if (!editor) {
return null
}

return (
<>
<button onClick={() => editor.chain().focus().setHorizontalRule().run()}>
Expand Down
Loading

0 comments on commit 1892b70

Please sign in to comment.