Repository navigation
Conversation
sleeyax
left a comment
There was a problem hiding this comment.
Really nice to see this picked back up, the inline editing feels a lot better than the old toggle 🙂
I left a few AI-assisted review comments.
| const saveContent = useCallback(() => { | ||
| if (editedContent === undefined) return; | ||
| dispatch( | ||
| flowActions.update(flow, { | ||
| [part]: { content: editedContent }, | ||
| }), | ||
| ); | ||
| }, [dispatch, flow, part, editedContent]); |
There was a problem hiding this comment.
The editor shows contentViewData.text, which is the output of the selected view, and this PUTs that text back as the body. On the backend FlowHandler.put just does request.text = v / response.text = v, with no re-encoding. The old edit mode loaded content.data (the raw bytes), so it didn't have this problem.
Some ways this could break:
- An image in Auto view shows its YAML metadata, so editing one character and saving replaces the PNG with YAML.
- URL-encoded, multipart, protobuf, msgpack and hex dump views, and prettified JSON/JS/CSS, all save their display form instead of the original encoding.
- Raw view escapes control characters, so binary bodies get mangled too.
- Error output ("Couldn't parse as …", "Network Error") can also be edited and saved.
The console UI handles this by only allowing edits for an InteractiveContentview and saving through contentviews.reencode_message (see consoleaddons.py). I think we need the same here: a view-aware save endpoint, plus readonly on the editor for views that aren't interactive and for SyntaxHighlight.ERROR.
Also a smaller one: this only checks editedContent === undefined, not isEdited, so typing a character, deleting it and pressing Ctrl+S still sends a PUT.
There was a problem hiding this comment.
Yes, this is definitely the main thing to consider. Should we implement the decode/encode functions on the backend? @mhils what do you think?
| // Drop local edits when the underlying content changes. | ||
| useEffect(() => { | ||
| setEditedContent(undefined); | ||
| }, [contentView, message.contentHash, flow.id, part]); |
There was a problem hiding this comment.
Two ways this can lose edits:
- Switching views while there are unsaved changes throws them away without a warning, since the
keyincludescontentViewas well. - Saving and then continuing to type: once the flow update comes in,
contentHashchanges, this resetseditedContent, and the refetched text gets pushed into the editor that's still mounted throughvalue. Anything typed after the save is overwritten.
For (1), maybe disable the view selector or ask for confirmation while isEdited. For (2), keep the submitted text in a ref and only reset when the incoming text matches it.
| (view | ||
| ? `content/${encodeURIComponent(view)}.json${lineStr}` | ||
| : "content.data") | ||
| (view ? `content/${encodeURIComponent(view)}.json` : "content.data") |
There was a problem hiding this comment.
Removing ?lines= means the web UI no longer respects content_view_lines_cutoff at all, so every body is fetched and loaded into the editor in full just by selecting a flow. With large or minified payloads that's going to hurt, and that option exists specifically "to speedup flows browsing".
Could we keep the cutoff for the initial load, and only fetch the full content once someone starts editing or clicks something like "Load full content"?
There was a problem hiding this comment.
@mhils thoughts on this? I remember seeing a discussion about this somewhere (maybe on Discord), where we were considering removing the "show more" thingy and displaying the content directly, since CodeMirror 6 is more efficient. What do you think?
| <CodeEditor | ||
| content={d.text} | ||
| maxLines={remainingLines} | ||
| showMore={showMore} | ||
| language={d.syntax_highlight} | ||
| readonly | ||
| /> |
There was a problem hiding this comment.
For WebSocket/TCP flows this now mounts a separate CodeMirror instance for every message, with no cap. On top of that, useContentView is keyed on messages_meta.count, so a live connection refetches the entire uncapped history every time a message comes in. A long-running socket with a few thousand messages is going to get very heavy.
Maybe keep a cap plus "show more" for messages, or virtualise the list?
Description
This PR revives what I started back then in #7750.
To summarise:
Let me know your thoughts :)
CC: @sleeyax @mhils
Checklist