-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React warns about flushSync
usage when dynamically adding or removing plugins that use widgetViewFactory
#70
Comments
That's a problem. I'll try some other solutions like micro task. |
After doing some research and experiments, I found that by default ProseMirror doesn't allow appending the But I also seemed to found a way to add import { NodeViewConstructor } from 'prosemirror-view'
export const createTableNodeView: NodeViewConstructor = () => {
const container = document.createElement('div')
container.className = 'table-container'
const table = document.createElement('table')
setTimeout(function simulateAsyncRender() {
const somethingInTheMiddle = document.createElement('div')
somethingInTheMiddle.append(table)
container.append(somethingInTheMiddle)
}, 1000)
// You can also use a microtask.
// Promise.resolve().then(function simulateAsyncRender() {
// const somethingInTheMiddle = document.createElement('div')
// somethingInTheMiddle.append(table)
// container.append(somethingInTheMiddle)
// })
return {
dom: container,
contentDOM: table,
ignoreMutation: (mutation) => {
// Prevent DOMObserver.observer infinite loop.
if (mutation.type === 'childList' && mutation.target === container) {
return true
}
return false
},
}
} I wonder if there are edge cases where this wouldn't work. But if this is robust enough, we may not need |
After some investigation. I found out that seems you just need to wrap queueMicrotask(() => {
view.updateState(newState)
}) I also tried to figure out if we can get rid of |
In my editor, I use a piece of React state to control whether a plugin should be added to or removed from ProseMirror's
plugins
list, to achieve the effect of enabling or disabling.For example,
The problem is that whenever a plugin that renders React components with
widgetViewFactory
is added or removed, I get an error message in the console saying:Although rendering still works, I wonder if there's a way to suppress the error.
Here is the complete and working code adapted from the react example: https://github.com/dragonman225/prosemirror-adapter/blob/main/examples/react/components/Editor.tsx
The text was updated successfully, but these errors were encountered: