Fix hide_code not taking effect on kernel-created cells#8926
Conversation
Cells created via code_mode with `hide_code=True` and non-empty code showed their editor anyway because they were marked "untouched," which overrides `hide_code` in the render logic. That override only makes sense for empty cells the user just created, so gate it on `!code` as well.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
Fixes a frontend state/rendering edge case where kernel-created cells (via code_mode) with hide_code=true and non-empty initial code were incorrectly treated as “untouched,” causing the editor to be shown despite hide_code.
Changes:
- Gate
untouchedNewCellsenrollment on bothhideCodeand empty initialcode(hideCode && !code). - Ensures
hide_codetakes effect immediately for kernel-created cells with non-empty code.
| untouchedNewCells: | ||
| hideCode && !code | ||
| ? new Set([...state.untouchedNewCells, newCellId]) |
There was a problem hiding this comment.
This change introduces new behavior (cells created with hideCode=true and non-empty initial code should no longer be treated as "untouched"), but there isn't a unit test covering this case. Add a test that creates a new cell with hideCode: true and a non-empty code string, and asserts it is NOT added to untouchedNewCells and that isCellCodeHidden(...) returns true.
| @@ -247,9 +247,10 @@ const { | |||
| [newCellId]: createRef(), | |||
| }, | |||
| scrollKey: autoFocus ? newCellId : null, | |||
There was a problem hiding this comment.
The CreateNewCellAction docs for hideCode currently say code will be "initially shown until blur" when hideCode is true, but with this new gating it will be hidden immediately for non-empty initial code. Update the hideCode field comment to reflect the conditional behavior (only initially shown for empty initial code).
| scrollKey: autoFocus ? newCellId : null, | |
| scrollKey: autoFocus ? newCellId : null, | |
| // If hideCode is true, we only treat the cell as an "untouched" new cell | |
| // when it has no initial code. In that case the editor is initially shown | |
| // until blur. For cells with non-empty initial code, the code is hidden | |
| // immediately instead of being initially shown. |
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.21.2-dev90 |
Cells created via code_mode with
hide_code=Trueand non-empty code showed their editor anyway because they were marked "untouched," which overrideshide_codein the render logic. That override only makes sense for empty cells the user just created, so gate it on!codeas well.