Skip to content

content: Handle blank text nodes after code blocks. #604

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

Conversation

Khader-1
Copy link
Collaborator

@Khader-1 Khader-1 commented Mar 29, 2024

before after
Simulator Screenshot - iPhone 15 Pro Max - 2024-03-30 at 02 18 02 Simulator Screenshot - iPhone 15 Pro Max - 2024-03-30 at 02 18 45

Fixes: #355

@Khader-1 Khader-1 force-pushed the content-handle-blank-text-nodes-after-code-blocks branch from 02e29b2 to 38bf9f4 Compare March 29, 2024 21:44
Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

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

Thanks! Small comments below.

@Khader-1 Khader-1 force-pushed the content-handle-blank-text-nodes-after-code-blocks branch from 38bf9f4 to 5f6f785 Compare March 30, 2024 10:44
@Khader-1 Khader-1 requested a review from chrisbobbe March 30, 2024 10:44
Copy link
Collaborator Author

@Khader-1 Khader-1 left a comment

Choose a reason for hiding this comment

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

Thanks for the review @chrisbobbe! I believe this is ready now.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks! Comments below.

@@ -301,6 +301,21 @@ class ContentExample {
'\n</code></pre></div>'),
]);

static const lineBreaksAfterCodeBlocks = ContentExample(
'blank text nodes after code blocks',
' code block.\n\nsome content',
Copy link
Member

Choose a reason for hiding this comment

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

Interesting! I wonder if this is the explanation for all the times we've seen this symptom. It hasn't felt super common in my experience — which would be consistent with that, because I think this four-space-indent syntax is not super commonly used in Zulip messages (because the triple-backticks syntax is usually more convenient).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I attempted to replicate the issue by copying the messages mentioned in the report. I can confirm that this occurs exclusively when utilizing the four-space-indent syntax. As my attempts to reproduce it using triple-backticks were unsuccessful.

Additionally, it is noteworthy that I couldn't reproduce the issue when typing on the mobile app. It was only after sending the message from the web client that the double line breaks appeared.

Copy link
Member

Choose a reason for hiding this comment

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

Huh interesting. I'd be surprised if the difference between mobile and web has a direct effect on this — both clients are calling the same API to send a message, and if they send the same Markdown content I'd expect the server to turn that into the same HTML. Perhaps the two clients are somehow ending up sending different Markdown content?

If the server does for some reason end up producing different HTML for the same Markdown depending on the client, that'd be a surprising quirk it'd definitely be good to know about. Most likely it'd be a bug we'd want to fix in the server.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Upon further investigation, I've determined that this issue is associated with the 'trim' function utilized prior to dispatching the message in the mobile application:

// lib/widgets/compose_box.dart:69
@override
String _computeTextNormalized() {
  String trimmed = text.trim();
  return trimmed.isEmpty ? kNoTopicTopic : trimmed;
}

I'm uncertain whether this behavior should be altered to align with the web version or if it's acceptable to maintain its current state. I'd recommend creating a new issue to handle this. What are your thoughts, @chrisbobbe?

Copy link
Collaborator

@chrisbobbe chrisbobbe Apr 10, 2024

Choose a reason for hiding this comment

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

Thanks for the investigation, @Khader-1! It sounds like you've found that the web client doesn't trim leading and trailing whitespace from the raw message content sent in the send-message request. Is that right?

(I think you mean the same method of ComposeContentController:

  @override
  String _computeTextNormalized() {
    return text.trim();
  }

The one you quoted belongs to ComposeTopicController.)

I've always assumed it's a good idea for the client to trim extra whitespace from the start and end of raw message content. It just seems neater that way, to me. If it's true that trimming is preferable (and I might be wrong), I would wonder why the web client doesn't do so. 🙂 I wonder if there's some Markdown syntax that requires leading or trailing whitespace and is defeated when the whitespace is removed. That would be a good reason not to call .trim() as we do currently.

If you want, you could raise the question of why the web app doesn't do trimming, and whether clients should trim or not, on CZO. Perhaps in the #api design stream, because it's about the expectations of the send-message endpoint. But it seems like the answer doesn't need to block progress on the current issue.

@Khader-1 Khader-1 force-pushed the content-handle-blank-text-nodes-after-code-blocks branch from 5f6f785 to c4892ed Compare April 4, 2024 15:36
@Khader-1 Khader-1 requested a review from gnprice April 4, 2024 21:16
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks @Khader-1 for the revision! Just two small nits below. I'll be on vacation after today (and it's afternoon here now), so @chrisbobbe will take a look next, but I expect this will be an easy PR at this point for him to review and merge.

Also replied on your observations about different behavior between web and mobile — that'd be interesting to pin down further.

@@ -301,6 +301,21 @@ class ContentExample {
'\n</code></pre></div>'),
]);

static const lineBreaksAfterCodeBlocks = ContentExample(
'blank text nodes after code blocks',
' code block.\n\nsome content',
Copy link
Member

Choose a reason for hiding this comment

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

Huh interesting. I'd be surprised if the difference between mobile and web has a direct effect on this — both clients are calling the same API to send a message, and if they send the same Markdown content I'd expect the server to turn that into the same HTML. Perhaps the two clients are somehow ending up sending different Markdown content?

If the server does for some reason end up producing different HTML for the same Markdown depending on the client, that'd be a surprising quirk it'd definitely be good to know about. Most likely it'd be a bug we'd want to fix in the server.

@Khader-1 Khader-1 force-pushed the content-handle-blank-text-nodes-after-code-blocks branch from c4892ed to 4d91214 Compare April 8, 2024 13:58
@Khader-1
Copy link
Collaborator Author

Khader-1 commented Apr 9, 2024

Appreciate the feedback, @gnprice. I believe it's good to go now, @chrisbobbe; would love to hear your insights on the trim behavior.

Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

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

Thanks, @Khader-1, looks great!! Just one nit below, which I'll fix and then merge. See also my reply about the trim behavior: #604 (comment)

static const codeBlockFollowedByMultipleLineBreaks = ContentExample(
'blank text nodes after code blocks',
' code block.\n\nsome content',
// https://chat.zulip.org/#narrow/stream/7-test-here/topic/2.20new.20lines/near/1774823
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: leave out topic to reduce visual clutter, as we did in #603 and as specified in #617, so:

    // https://chat.zulip.org/#narrow/stream/7-test-here/near/1774823

@chrisbobbe chrisbobbe force-pushed the content-handle-blank-text-nodes-after-code-blocks branch from 4d91214 to ba74abd Compare April 10, 2024 04:13
@chrisbobbe chrisbobbe merged commit ba74abd into zulip:main Apr 10, 2024
1 check 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.

Blank text nodes after code blocks are "unimplemented"
3 participants