-
Notifications
You must be signed in to change notification settings - Fork 67
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
Conversation
@@ -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" |
There was a problem hiding this comment.
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.
Just to clarify, is there a reason a simple |
@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) |
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>
There was a problem hiding this 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!
await this.updateShellPrompt(); | ||
this.props.onOperationEnd(); | ||
} | ||
const [editor, setEditor] = useState<EditorRef | null>(null); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
const editorChanged = useCallback( | ||
(editor: EditorRef | null) => { | ||
setEditor(editor); | ||
onEditorChanged?.(editor); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be good now?
|
||
this.setState({ output }); | ||
} | ||
const [isFirstRun, setIsFirstRun] = useState(true); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this? 4e66b19
There was a problem hiding this comment.
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.
Required for mongodb-js/compass#6538
Changes: