# Editor text not being saved in notebook model

**URL:** <https://discourse.jupyter.org/t/editor-text-not-being-saved-in-notebook-model/18688>\
**Category:** JupyterLab\
**Tags:** jupyterlab, how-to, help-wanted\
**Created:** [March 28, 2023, 3:15pm UTC](https://discourse.jupyter.org/t/editor-text-not-being-saved-in-notebook-model/18688 "2023-03-28T15:15:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![layterz](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/layterz/32/9496_2.png) [@layterz](https://discourse.jupyter.org/u/layterz)\
**Post date:** [March 28, 2023, 3:15pm UTC](https://discourse.jupyter.org/t/editor-text-not-being-saved-in-notebook-model/18688/1 "2023-03-28T15:15:07Z")

</div>

I’m using jupyterlab components via the npm packages to build a custom interface. The cells are rendering correctly and notebook actions work as expected, but code can’t be executed because `cell.model.sharedModel.getSource()` is always an empty string. Relevant code from `CodeCell`:

```auto
(function (CodeCell) {
    /**
     * Execute a cell given a client session.
     */
    async function execute(cell, sessionContext, metadata) {
        var _a;
        const model = cell.model;
        const code = model.sharedModel.getSource();
        if (!code.trim() || !((_a = sessionContext.session) === null || _a === void 0 ? void 0 : _a.kernel)) {
            model.sharedModel.transact(() => {
                model.clearExecution();
            });
            return;
        }

```

This is the code I’m using to instantiate the notebook (based on the code in `/examples/notebook`)

```auto
  const languages = new EditorLanguageRegistry();
  const factoryService = new CodeMirrorEditorFactory({ languages });
  const mimeTypeService = new CodeMirrorMimeTypeService(languages);
  const rendermime = new RenderMimeRegistry({ initialFactories });
  const editorFactory = factoryService.newDocumentEditor;
  const contentFactory = new Notebook.ContentFactory({ editorFactory });

  const context = {
    session: {
      kernel: new BackgroundKernel(),
    },
  } as ISessionContext;

  const nb = new Notebook({
    rendermime,
    mimeTypeService,
    contentFactory,
  });

  nb.model = new NotebookModel({
    defaultCell: 'code',
  });

  const panel = new Panel();
  panel.id = 'main';
  panel.addWidget(nb);
  Widget.attach(panel, container);

```

I’m using a custom `ISessionContext` because I’m loading the UI in a Chrome extension and the network calls to the notebook server need to be made from the background script. `BackgroundKernel` implements `IKernelConnection` and simply proxies the requests to the extension’s background script. I can post the full code for this, but it’s quite long so leaving out for now.

I realise this is an unusual setup so expect it’s something I’m doing wrong, but can’t figure out what’s preventing the shared model’s source being updated with editor state. Any suggestions or pointers very much appreciated.

FWIW, this was working ~2 weeks ago, but stopped after an update. The version that worked had `Notebook.defaultContentFactory`, which was removed at somepoint.
