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: recreating keyboardShortcuts interface on file changes. #1465

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nishu-murmu
Copy link
Contributor

Overview

I noticed that keyboard shortcuts weren't working after files were being saved or HMR was triggered.
Hope this fixes it.

Copy link

netlify bot commented Feb 28, 2025

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit 417676f
🔍 Latest deploy log https://app.netlify.com/sites/creative-fairy-df92c4/deploys/67e19c5d7894b900082cf7b3
😎 Deploy Preview https://deploy-preview-1465--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@nishu-murmu nishu-murmu changed the title fix: restarting keyboardShortcuts listener on file changes. fix: recreating keyboardShortcuts interface on file changes. Feb 28, 2025
Copy link
Member

@Timeraa Timeraa left a comment

Choose a reason for hiding this comment

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

Was noticing this too but wouldn't this potentially be a memory leak since we keep creating it?

@nishu-murmu
Copy link
Contributor Author

Was noticing this too but wouldn't this potentially be a memory leak since we keep creating it?

Yeah, now that I think about it, it really can be. as such there are already existing issues for windows.
We can just close the listeners instead of the interface. That way only one interface will be used.

Copy link

pkg-pr-new bot commented Mar 23, 2025

Open in Stackblitz

@wxt-dev/analytics

npm i https://pkg.pr.new/@wxt-dev/analytics@1465

@wxt-dev/auto-icons

npm i https://pkg.pr.new/@wxt-dev/auto-icons@1465

@wxt-dev/browser

npm i https://pkg.pr.new/@wxt-dev/browser@1465

@wxt-dev/i18n

npm i https://pkg.pr.new/@wxt-dev/i18n@1465

@wxt-dev/module-react

npm i https://pkg.pr.new/@wxt-dev/module-react@1465

@wxt-dev/module-solid

npm i https://pkg.pr.new/@wxt-dev/module-solid@1465

@wxt-dev/module-svelte

npm i https://pkg.pr.new/@wxt-dev/module-svelte@1465

@wxt-dev/module-vue

npm i https://pkg.pr.new/@wxt-dev/module-vue@1465

@wxt-dev/storage

npm i https://pkg.pr.new/@wxt-dev/storage@1465

@wxt-dev/unocss

npm i https://pkg.pr.new/@wxt-dev/unocss@1465

wxt

npm i https://pkg.pr.new/wxt@1465

commit: 417676f

Comment on lines -114 to -120
const reloadOnChange = createFileReloader(server);
const reloadOnChange = () => {
keyboardShortcuts.start();
keyboardShortcuts.printHelp({
canReopenBrowser:
!wxt.config.runnerConfig.config.disabled && !!runner.canOpen?.(),
});
return createFileReloader(server);
};
server.watcher.on('all', reloadOnChange);
keyboardShortcuts.start();
keyboardShortcuts.printHelp({
canReopenBrowser:
!wxt.config.runnerConfig.config.disabled && !!runner.canOpen?.(),
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

One side-effect to this change is that the help message is printed after every file is saved, right? Should we leave the printHelp call outside the reloadOnChange where it was before so we only print the message when the server is started/restarted?

Copy link
Collaborator

@aklinker1 aklinker1 left a comment

Choose a reason for hiding this comment

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

Do we know why the readline interface stops working when a file is saved? Or are we just making a change in hopes that it fixes the problem?

Comment on lines +114 to 122
const reloadOnChange = () => {
keyboardShortcuts.start();
keyboardShortcuts.printHelp({
canReopenBrowser:
!wxt.config.runnerConfig.config.disabled && !!runner.canOpen?.(),
});
return createFileReloader(server);
};
server.watcher.on('all', reloadOnChange);
Copy link
Collaborator

@aklinker1 aklinker1 Mar 29, 2025

Choose a reason for hiding this comment

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

I think this change is still wrong... The file watcher args aren't being passed into the function returned by createFileReloader properly.

This is the right way to do it:

Suggested change
const reloadOnChange = () => {
keyboardShortcuts.start();
keyboardShortcuts.printHelp({
canReopenBrowser:
!wxt.config.runnerConfig.config.disabled && !!runner.canOpen?.(),
});
return createFileReloader(server);
};
server.watcher.on('all', reloadOnChange);
const reloadOnChange = createFileReloader(server);
server.watcher.on('all', async (...args) => {
await reloadOnChange(...args);
// Restart keyboard shortcuts after file is changed - for some reason they stop working.
keyboardShortcuts.start();
});
keyboardShortcuts.printHelp({
canReopenBrowser:
!wxt.config.runnerConfig.config.disabled && !!runner.canOpen?.(),
});

I also included moving the printHelp call out so it's only printed once. See #1465 (comment)

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.

4 participants