-
Notifications
You must be signed in to change notification settings - Fork 220
Create a slight delay in on shortcut keys so you can't spam theme in theme dev #6711
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
base: main
Are you sure you want to change the base?
Conversation
Coverage report
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success3493 tests passing in 1407 suites. Report generated by 🧪jest coverage report action from eda441d |
|
/snapit |
graygilmore
left a comment
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.
🎩 went great but I'm a little confused about the unused function
|
|
||
| // This prevents the keypress handler from being called multiple times in a short span | ||
| keyBlock = true | ||
| setTimeout(() => { |
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.
Are you familiar with debouncing? We have a debounce helper function that we could potentially use here instead? Might be overkill for what you're doing but it's there if you want! https://github.com/Shopify/cli/blob/main/packages/cli-kit/src/public/common/function.ts#L39
We could use leading: true to make sure we don't delay the first keypress.
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.
Sure I could use the helper since it's already available. Let me check this out!
d29fe1e to
cd9753f
Compare
…open multiple tabs.
cd9753f to
eda441d
Compare
| switch (key.name) { | ||
| case 't': | ||
| openURLSafely(urls.local, 'localhost') | ||
| debouncedOpenURL(urls.local, 'localhost') |
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 might've debounced the click handler instead of the URL opening itself but this works, too!
dejmedus
left a comment
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 was a super fun 🎩 Looks great!
WHY are these changes introduced?
Fixes https://github.com/Shopify/developer-tools-team/issues/918
If you copy and paste in the terminal when running
theme devyou can end up with a ton of tabs opening.Since we are watching for certain keys like
tto open localhost, if you were to copy and paste text that had multiplet|p|e|g<-- shortcut keys, you can end up opening a lot of tabs.WHAT is this pull request doing?
When a key is pressed we create a short lived lock, and any other keys pressed during that time will be ignored. The delay is set to 100ms so we shouldn't see any problems with someone quickly doing something like opening localhost and then the editor for themselves.
I also added some extra keypress tests that we didn't originally have.
How to test your changes?
This is a fun one to test.
theme devand in the console, pastetteeppggtt. This should open 10 tabs.t) and open localhost once.Post-release steps
Measuring impact
How do we know this change was effective? Please choose one:
Checklist