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

Playground: slow on Safari #282

Open
rauschma opened this issue Mar 27, 2024 · 5 comments
Open

Playground: slow on Safari #282

rauschma opened this issue Mar 27, 2024 · 5 comments

Comments

@rauschma
Copy link

Currently, typing is slowed down. Does the code parse and render after every keystroke?

If yes then you could wait until the user pauses typing – e.g., like this:

const input = document.getElementById('my-input');
let timeout = null;
input.addEventListener('keyup', () => {
  if (timeout !== null) {
    clearTimeout(timeout);
  }
  timeout = setTimeout(
    () => {
      timeout = null;
      console.log('Parse and render:', textInput.value);
    },
    1000); // wait 1 second
});
@jgm
Copy link
Owner

jgm commented Mar 27, 2024

There's already a debounce function. The debounce time is determined dynamically as follows:

    var elapsedTime = endTime - startTime;
    debounceMs = elapsedTime * 8;

The factor could be increased, but it doesn't feel laggy to me.

@rauschma
Copy link
Author

Ah, I should have checked other browsers:

  • This is only an issue in Safari (Mac with M1 Pro processor) – where I can type faster than my input is being processed. The playground works fine in Chrome and Firefox.
  • The CommonMark Dingus does not have this issue in Safari. It’s very responsive there.

@rauschma rauschma changed the title Playground: Wait with rendering until user pauses typing? Playground: slow on Safari Mar 27, 2024
@jgm
Copy link
Owner

jgm commented Mar 27, 2024

Interesting. I use it with Safari on M1 mac and have no issues.

@jgm
Copy link
Owner

jgm commented Mar 27, 2024

You can try editing the code locally and changing that 8 to a higher number?

@jgm
Copy link
Owner

jgm commented Mar 27, 2024

Also try with a large file and make sure the debounce is kicking in. When I try it with 240K file, I see exactly the behavior you're requesting -- I type and then when I stop, it renders. That's because the debounce time is determined dynamically based on how long it takes to parse and render the document.

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

No branches or pull requests

2 participants