I think in the case of OP, a better approach is to maintain a pathname -> EditorState map, and switch states using view.setState instead of maintain multiple instances Since EditorState can be persistent, the user can restore the previous editor state even after refreshing the page.