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

"null" completion sources causes other sources to update slowly #1506

Open
hrjakobsen opened this issue Jan 15, 2025 · 4 comments
Open

"null" completion sources causes other sources to update slowly #1506

hrjakobsen opened this issue Jan 15, 2025 · 4 comments

Comments

@hrjakobsen
Copy link

Describe the issue

We have multiple completion sources, some of which only apply in specific circumstances. When they don't apply, they simple return null.

This causes all other completion sources, even those sources that provides a validFor property, to be "out-of-date" for at least activateOnTypingDelayms on every keypress. If no "null-sources" are present, the remaining sources work as you'd expect based on the validFor and immediately updates. The same behaviour also occurs if at least one source doesn't specify a validFor which is required when setting filter: false.

This means that after every keypress there's a activateOnTypingDelayms delay where if you press enter, a newline is inserted rather than the autocompletion entry.

Possible this behaviour was introduced with codemirror/autocomplete@5e97bd6

We could work around this by setting activateOnTypingDelay: 0, but the default seems like the sensible option. In the reproduction link I've upped activateOnTypingDelay to 500, but it does occur with the default 100 as well.

Browser and platform

No response

Reproduction link

https://codemirror.net/try/#c=aW1wb3J0IHsgbWluaW1hbFNldHVwIH0gZnJvbSAiY29kZW1pcnJvciIKaW1wb3J0IHsKICBhdXRvY29tcGxldGlvbiwKICBjb21wbGV0ZUZyb21MaXN0Cn0gZnJvbSAnQGNvZGVtaXJyb3IvYXV0b2NvbXBsZXRlJwppbXBvcnQgeyBFZGl0b3JWaWV3IH0gZnJvbSAnQGNvZGVtaXJyb3IvdmlldycKCmNvbnN0IENPTVBMRVRJT05TID0gWwogICJhYWFhYWEiLAogICJhYWFhYWFhIiwKICAiYWFhYWFhYWEiLAogICJhYWFhYWFhYWEiLApdCgpjb25zdCBub1ZhbGlkRm9yU291cmNlID0gY3R4ID0+ICh7CiAgZnJvbTogY3R4LnBvcywKICBvcHRpb25zOiBbXSwKICBmaWx0ZXI6IGZhbHNlLAp9KQoKY29uc3QgbnVsbFNvdXJjZSA9IGN0eCA9PiBudWxsCgpjb25zdCBhdXRvY29tcGxldGVFeHRlbnNpb24gPSBbCiAgYXV0b2NvbXBsZXRpb24oewogICAgb3ZlcnJpZGU6IFsKICAgICAgY29tcGxldGVGcm9tTGlzdChDT01QTEVUSU9OUyksCiAgICAgIC8vIG5vVmFsaWRGb3JTb3VyY2UsCiAgICAgIG51bGxTb3VyY2UKICAgIF0sCiAgICBpbnRlcmFjdGlvbkRlbGF5OiAwLAogICAgYWN0aXZhdGVPblR5cGluZ0RlbGF5OiA1MDAsCiAgfSksCl0KCmNvbnN0IERPQ1VNRU5UID0gYFRvIHJlcHJvZHVjZTogUHJlc3MgImEiIG9uIHRoZSBsaW5lIGJlbG93LAp3aGVuIHRoZSBhdXRvY29tcGxldGUgbWVudSBvcGVucywKcXVpY2tseSBwcmVzcyAiYSIgZm9sbHdlZCBieSBFbnRlci4KUmF0aGVyIHRoYW4gaW5zZXJ0aW5nIHRoZSBoaWdobGlnaHRlZCBhdXRvY29tcGxldGUgZW50cnksCmEgbmV3bGluZSBpcyBpbnNlcnRlZC4KVGhlIG9ubHkgb2NjdXJzIGlmIG5vVmFsaWRGb3JTb3VyY2Ugb3IgbnVsbFNvdXJjZSBpcyBlbmFibGVkLgpcblxuYAoKbmV3IEVkaXRvclZpZXcoewogIGRvYzogRE9DVU1FTlQsCiAgZXh0ZW5zaW9uczogWwogICAgbWluaW1hbFNldHVwLAogICAgYXV0b2NvbXBsZXRlRXh0ZW5zaW9uCiAgXSwKICBwYXJlbnQ6IGRvY3VtZW50LmJvZHkKfSkK

@marijnh
Copy link
Member

marijnh commented Jan 15, 2025

This is intentional—completion sources are only called after that delay, so if there is any source that doesn't have an active, synchronously-reusable result, the completions will only update, on typing, after the delay has elapsed. Before that, the library does not yet know what the set of current completions should look like.

@hrjakobsen
Copy link
Author

hrjakobsen commented Jan 15, 2025

Do we have any workarounds except of setting activateOnTypingDelay to a very low value? While the results are pending, the previous autocomplete results are still visible but unable to be interacted with.

image

The only alternative to the "null-sources" that come to mind is returning { options: [], validFor: () => true } instead of null, but that could mean that the source wouldn't be queried again until the autocomplete is closed and re-opened.

@hrjakobsen
Copy link
Author

hrjakobsen commented Jan 15, 2025

This reproduction is a more realistic representation of our issue.

The "aaaaa" completions are always slow, due to the presence of the "bbbb" completions.

It sounds like from your response that setting activateOnTypingDelay is the intended way to deal with this?

@marijnh
Copy link
Member

marijnh commented Jan 17, 2025

Yes, sounds like you want to set that lower if the 100ms delay bothers you. There's a trade-off between querying the completion sources very often, during fast typing, and delaying completions. The default is intended to be pretty fast while still 'chunking' quickly typed pieces of text together.

Doing a thing where the completion dialog is populated bit-by-bit as the sources complete is problematic, since the list will jump around unpredictably and users are likely to accidentally confirm an option they didn't intend to, when other options pop in right when they press enter.

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