Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
do not re-render one-line-editor's code-mirror unnecessarily; fix #43
Browse files Browse the repository at this point in the history
  • Loading branch information
archywillhe committed Oct 16, 2023
1 parent 7361f11 commit 8abe223
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Binary file added packages/insomnia/src/icons/256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,15 @@ export const OneLineEditor = forwardRef<OneLineEditorHandle, OneLineEditorProps>
codeMirror.current.on('dragstart', preventDefault);
codeMirror.current.setCursor({ line: -1, ch: -1 });

// Actually set the value
codeMirror.current?.setValue(defaultValue || '');
// Clear history so we can't undo the initial set
codeMirror.current?.clearHistory();

// console.log("did mount - " + defaultValue, "_:" + codeMirror.current.getValue())

if (defaultValue === codeMirror.current.getValue()) {
// Actually set the value
codeMirror.current?.setValue(defaultValue || '');
// Clear history so we can't undo the initial set
codeMirror.current?.clearHistory()
}
// Setup nunjucks listeners
if (!readOnly && handleRender && !settings.nunjucksPowerUserMode) {
codeMirror.current?.enableNunjucksTags(
Expand Down
5 changes: 3 additions & 2 deletions packages/insomnia/src/ui/components/panes/request-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export const RequestPane: FC<Props> = ({
':workspaceId',
) as WorkspaceLoaderData;
// Force re-render when we switch requests, the environment gets modified, or the (Git|Sync)VCS version changes
const uniqueKey = `${activeEnvironment?.modified}::${requestId}::${gitVersion}::${activeRequestSyncVersion}::${activeRequestMeta?.activeResponseId}`;
const uniqueKeyReq = `${activeEnvironment?.modified}::${requestId}::${gitVersion}::${activeRequestSyncVersion}`
const uniqueKey = `${uniqueKeyReq}::${activeRequestMeta?.activeResponseId}`;

if (!activeRequest) {
return <PlaceholderRequestPane />;
Expand All @@ -129,7 +130,7 @@ export const RequestPane: FC<Props> = ({
<ErrorBoundary errorClassName="font-error pad text-center">
<RequestUrlBar
key={requestId}
uniquenessKey={uniqueKey}
uniquenessKey={uniqueKeyReq}
handleAutocompleteUrls={() => queryAllWorkspaceUrls(workspaceId, models.request.type, requestId)}
nunjucksPowerUserMode={settings.nunjucksPowerUserMode}
setLoading={setLoading}
Expand Down
4 changes: 4 additions & 0 deletions packages/insomnia/src/ui/components/request-url-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ export const RequestUrlBar = forwardRef<RequestUrlBarHandle, Props>(({
const { url, method } = activeRequest;
const isEventStreamOpen = useReadyState({ requestId: activeRequest._id, protocol: 'curl' });
const isCancellable = currentInterval || currentTimeout || isEventStreamOpen;


console.log("did mount uniquenessKey", uniquenessKey);

return (
<div className="urlbar">
<MethodDropdown
Expand Down

0 comments on commit 8abe223

Please sign in to comment.