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

input lag fix #708

Merged
merged 7 commits into from
Nov 3, 2024
Merged

input lag fix #708

merged 7 commits into from
Nov 3, 2024

Conversation

tarasglek
Copy link
Owner

Stopped keeping prompt in react. @humphd how's this change?

Copy link

cloudflare-workers-and-pages bot commented Nov 2, 2024

Deploying chatcraft-org with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2548100
Status: ✅  Deploy successful!
Preview URL: https://904e2aa3.console-overthinker-dev.pages.dev
Branch Preview URL: https://taras-input-lag.console-overthinker-dev.pages.dev

View logs

@tarasglek
Copy link
Owner Author

Not super excited to duplicate this fix for mobile..would be nice to unify the logic and just keep rendering separate

Copy link
Collaborator

@humphd humphd left a comment

Choose a reason for hiding this comment

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

Seems to work, not sure what it loses, if anything.

I wonder if we can further drop state here and compare to values whenever necessary.

@@ -164,27 +161,25 @@ function DesktopPromptForm({
switch (e.key) {
// Allow the user to cursor-up to repeat last prompt
case "ArrowUp":
if (!isDirty && previousMessage) {
if (isPromptEmpty && previousMessage && inputPromptRef.current) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you get rid of the isPromptEmpty state completely and do:

if (inputPromptRef.current?.value === "" && previousMessage) {

Copy link
Owner Author

Choose a reason for hiding this comment

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

here either would work, this is just more consistent cos it does trim in state

@@ -422,7 +418,7 @@ function DesktopPromptForm({
/>

<Flex alignItems="center" gap={2}>
<KeyboardHint isVisible={!!prompt.length && !isLoading} />
<KeyboardHint isVisible={!isPromptEmpty && !isLoading} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if doing inputPromptRef.current.value !== "" works here, but it might

Copy link
Owner Author

Choose a reason for hiding this comment

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

doesnt cos you need to trigger a react rerender

if (settings.enterBehaviour === "newline") {
handleMetaEnter(e);
} else if (settings.enterBehaviour === "send") {
if (!e.shiftKey && prompt.length) {
if (!e.shiftKey && !isPromptEmpty) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

@tarasglek tarasglek merged commit 55ae773 into main Nov 3, 2024
4 checks passed
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.

2 participants