State reconfigure do not apply new plugins

#1

Hey @marijn. Has something changed to state.reconfigure()? It seems that new plugins are not applied correctly anymore (at least the view method).

Here you can see the issue: https://glitch.com/edit/#!/prosemirror-reconfigure-bug?path=index.js:28:2 update view 2 should be logged but it’s not working.

Did I miss something?

const mySchema = new Schema({
  nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),
  marks: schema.spec.marks,
})

const plugin1 = new Plugin({
  props: {
    handleClickOn() {
      // works
      console.log('click view 1')
    },
  },
  view() {
    return {
      update: () => {
        // works
        console.log('update view 1')
      },
    }
  },
})

const plugin2 = new Plugin({
  props: {
    handleClickOn() {
      // works
      console.log('click view 2')
    },
  },
  view() {
    return {
      update: () => {
        // do not work
        console.log('update view 2')
      },
    }
  },
})

const state = EditorState.create({
  doc: DOMParser.fromSchema(mySchema).parse(document.querySelector('#content')),
  plugins: [...exampleSetup({ schema: mySchema }), plugin1],
})

const view = new EditorView(document.querySelector('#editor'), {
  state,
})

const newState = state.reconfigure({
  plugins: state.plugins.concat([plugin2]),
})

view.updateState(newState)
#2

See the console output in the right side. It seems like props does work, but view() not

#4

Push. For some reason this seams to work on glitch. I’ve created a codesandbox where you can see the issue.

#5

It seems that this is broken since prosemirror-view 1.9.0 and fixable with calling updatePluginViews. Is that the intended behavior?

const newState = state.reconfigure({
  plugins: state.plugins.concat([plugin]),
})
view.updateState(newState)
view.updatePluginViews()
#6

No, that’s definitely a bug. I’ve fixed it in this patch. Will do a release in a moment.

#7

Thank you!