Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(browser-repl)!: keep operation in progress COMPASS-8576 MONGOSH-1966 #2284

Merged
merged 33 commits into from
Dec 13, 2024

Conversation

lerouxb
Copy link
Contributor

@lerouxb lerouxb commented Nov 28, 2024

Required for mongodb-js/compass#6538

Changes:

  • output, history and isOperationInProgress are now all controlled props. So initialOutput and initialHistory was removed.
  • I took the chance to rewrite Shell to be a function component. So I also converted the tests to use testing-library.

@@ -35,7 +35,8 @@
"depcheck": "depcheck",
"compile": "tsc -p tsconfig.json",
"prettier": "prettier",
"reformat": "npm run prettier -- --write . && npm run eslint --fix"
"reformat": "npm run prettier -- --write . && npm run eslint --fix",
"sync-to-compass": "node scripts/sync-to-compass.js"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful in combination with this. Based on https://github.com/mongodb-js/compass/blob/main/packages/compass-web/scripts/sync-dist-to-mms.js

This way you can save a file in browser-repl in mongosh and it hot-reloads in compass.

@lerouxb lerouxb changed the title chore(browser-repl): Keep operation in progress COMPASS-8576 fix(browser-repl): Keep operation in progress COMPASS-8576 Nov 28, 2024
@addaleax addaleax changed the title fix(browser-repl): Keep operation in progress COMPASS-8576 fix(browser-repl): keep operation in progress COMPASS-8576 Nov 28, 2024
@kraenhansen
Copy link
Contributor

Just to clarify, is there a reason a simple npm link won't work for this use-case? It seems to me it's serving the same purpose (keeping cross-repo dependencies updated while developing).

@lerouxb
Copy link
Contributor Author

lerouxb commented Dec 5, 2024

@kraenhansen I don't have a better explanation than https://github.com/mongodb-js/compass/blob/117c32f8ddd5d2bf4f8fceec5b324bf9866de66e/packages/compass-web/scripts/sync-dist-to-mms.js#L47-L52

I don't think any of us have managed to get that work. This is by far the closest to "it just works, instantly and reliably" that I've managed.

(More and more I'm thinking we should just move this code to Compass)

packages/browser-repl/scripts/sync-to-compass.js Outdated Show resolved Hide resolved
packages/browser-repl/scripts/sync-to-compass.js Outdated Show resolved Hide resolved
packages/browser-repl/src/components/shell-input.tsx Outdated Show resolved Hide resolved
packages/browser-repl/src/components/shell.tsx Outdated Show resolved Hide resolved
packages/browser-repl/src/components/shell.tsx Outdated Show resolved Hide resolved
packages/browser-repl/src/components/shell.tsx Outdated Show resolved Hide resolved
lerouxb and others added 8 commits December 9, 2024 15:28
Co-authored-by: Anna Henningsen <anna.henningsen@mongodb.com>
Co-authored-by: Anna Henningsen <anna.henningsen@mongodb.com>
Co-authored-by: Anna Henningsen <anna.henningsen@mongodb.com>
Co-authored-by: Anna Henningsen <anna.henningsen@mongodb.com>
Co-authored-by: Anna Henningsen <anna.henningsen@mongodb.com>
Copy link
Member

@Anemy Anemy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small things I noticed initially, trying it out now, and taking a look at the usage in Compass.
Nice!

packages/browser-repl/src/components/shell.tsx Outdated Show resolved Hide resolved
packages/browser-repl/README.md Outdated Show resolved Hide resolved
packages/browser-repl/README.md Show resolved Hide resolved
packages/browser-repl/src/components/shell.tsx Outdated Show resolved Hide resolved
await this.updateShellPrompt();
this.props.onOperationEnd();
}
const [editor, setEditor] = useState<EditorRef | null>(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is any particular reason this should be a state instead of a ref? Using a ref would be more idiomatic here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this now. Does have the problem where it isn't set in time for the useEffect in compass, though.

packages/browser-repl/src/components/shell.tsx Outdated Show resolved Hide resolved
const editorChanged = useCallback(
(editor: EditorRef | null) => {
setEditor(editor);
onEditorChanged?.(editor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but idiomatically this should probably be done by using a forwarded ref instead of a prop callback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good now?

packages/browser-repl/src/components/shell.tsx Outdated Show resolved Hide resolved
packages/browser-repl/src/components/shell.tsx Outdated Show resolved Hide resolved
packages/browser-repl/src/components/shell.tsx Outdated Show resolved Hide resolved

this.setState({ output });
}
const [isFirstRun, setIsFirstRun] = useState(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit / fyi, I think it's okay to keep like that also: this works, but causes unnecessary re-renders. As we discussed, usually anything that is not directly related to rendering should be a ref (or all deps of the effect should be made into refs to avoid dependencies here, depends on what flavor of weird React workarounds you would have a preference for). You'd usually want to limit the amount of unnecessary updates your component will do, performance aside, it just means that you have less cascading side-effects that you might not expect otherwise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this? 4e66b19

Copy link
Contributor Author

@lerouxb lerouxb Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know why I didn't consider just updating the ref. This stuff still isn't muscle memory for me - somehow I still don't do enough react often enough.

There are tons of improvements we can make in future, though. Maybe easier once we move this to Compass.

@lerouxb lerouxb merged commit 1e43c79 into main Dec 13, 2024
118 of 123 checks passed
@lerouxb lerouxb deleted the keep-operation-in-progress2 branch December 13, 2024 13:34
@lerouxb lerouxb changed the title fix(browser-repl): keep operation in progress COMPASS-8576 fix(browser-repl)!: keep operation in progress COMPASS-8576 Dec 13, 2024
@lerouxb lerouxb changed the title fix(browser-repl)!: keep operation in progress COMPASS-8576 fix(browser-repl)!: keep operation in progress COMPASS-8576 MONGOSH-1966 Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants