jupyter-ui
jupyter-ui copied to clipboard
Bug on saving a file
Description : Getting error on saving a file.
Steps to reproduce :
- Open an ipynb file.
- Making changes and save it (No error till now) (CHANGE ID : 01).
- Reload the page
- The file will be opened containing the very initial content.
- Now, if you try to edit and save(CHANGE ID : 02), it will show the popup to overwrite and revert.
- On revert, it will rollback to CHANGE ID : 01.
- On overwrite it will replace the file with the CHANGE ID : 02 changes.
Note : The file name and id for me were "test.ipynb" But as noted in the popup. The file name is also changed to some {kernel-[uuid()]}. If i check on Jupyter lab, a file without extension is created, with this {kernel-[uuid()]}, not .iypnb
@dbhagesh I have just released 0.10.0 with a fix for this issue. Thank you for patience.
Hello @echarles,
I am using version 0.10.0 and still have this error in my application. One scenario that I have detected 100% is in the component below. After waiting for an open session time and trying to save, I consistently receive the error.
Should I open a new issue?
Evidences follow:
And the code of the component being used:
import React, {useState} from 'react';
import {Notebook, useJupyter} from '@datalayer/jupyter-react';
import {useDispatch} from 'react-redux';
import {Button, Box} from '@primer/react';
import {notebookActions, cellActions} from '@datalayer/jupyter-react';
import MyToolbarWithAutoSave from '../toolbar/CustomToolbar';
const DynamicNotebookComponent: React.FC = () => {
const dispatch = useDispatch();
const { serviceManager } = useJupyter();
const [notebookPath, setNotebookPath] = useState<string | null>(null);
const uuid = `dyna-${Date.now()}`;
const createNotebook = async () => {
if (!serviceManager) {
console.warn('Service manager isn\'t ready yet.');
return;
}
const path = `notebook-${uuid}.ipynb`;
const newNotebook = await serviceManager.contents.newUntitled({
path: '/',
type: 'notebook',
});
await serviceManager.contents.rename(newNotebook.path, path);
setNotebookPath(path);
};
const addCell = (cellType: 'code' | 'markdown') => {
let source = `print(5 + 5)`;
if (cellType === 'markdown') {
source = `### Hello!`
}
dispatch(
notebookActions.insertBelow.started({
uid: uuid,
cellType,
source
})
);
setTimeout(() => {dispatch(notebookActions.run.started(uuid))}, 500);
};
const saveNotebook = () => {
dispatch(notebookActions.save.started({
uid: uuid,
date: new Date(),
}));
};
return (
<Box>
<div style={{ display: 'flex', gap: '10px', flexDirection: 'row', marginTop: 24 }}>
<Button color="primary" onClick={createNotebook}>
Create Notebook
</Button>
<Button
color="secondary"
onClick={() => addCell('code')}
disabled={!notebookPath}
>
Add Code Cell
</Button>
<Button
color="secondary"
onClick={() => addCell('markdown')}
disabled={!notebookPath}
>
Add Markdown Cell
</Button>
<Button
color="secondary"
onClick={saveNotebook}
disabled={!notebookPath}
>
Save
</Button>
</div>
{notebookPath && (
<Box mt={2}>
<h4>Notebook: {notebookPath}</h4>
<Notebook uid={uuid} path={notebookPath} Toolbar={MyToolbarWithAutoSave}/>
</Box>
)}
</Box>
);
};
export default DynamicNotebookComponent;
Should I open a new issue?
Thx for reportin @MarcosVn, no need to open a separated issue. I will look at that asap.
I tested this issue on 0.11 and it might not occur there. I will confirm by testing further and report the results here soon, @echarles
Thank you!