openedx / openedx/paragon

Truncate component breaks JSX conventions

Open
#3,311 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
140
Forks
100
Avg merge
1h 3m
Merged PRs (30d)
30

Description

Feedback summary

The <Truncate> component documentation says:

Note: Truncate supports only plain HTML children and not jsx.

And a supposed example of this can be seen in the "HTML markdown support" section.

However, this is not true. A more accurate statement would be "Truncate supports only a buggy, idiosyncratic version of JSX."

It is JSX, not HTML

First of all, if it was truly HTML instead of JSX, it would have to be passed into the Truncate component as a string; it is in fact being parsed by React's JSX parser. You can clearly see this if you use other JSX syntax like {"string interpolation"}:

Screenshot 2024-12-03 at 10 35 15 AM

Bugs

Second, of all, it throws errors on things that are perfectly valid HTML or JSX:

Screenshot 2024-12-03 at 10 37 43 AM

Screenshot 2024-12-03 at 10 38 01 AM

Incompatibility

Finally, because this is actually JSX but it's not implemented correctly, TypeScript is always going to throw errors like this (which is how I discovered all this):

Type '{ children: Element; class: string; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>'.
  Property 'class' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>'. Did you mean 'className'?

I don't think it is possible to tell TypeScript that some portion of the JSX is using our own special version of JSX and should be using class instead of className.

Suggestion

At the very least, I suggest fixing the bugs and implementing support for className instead of class, htmlFor instead of for, etc. so that we can use this with TypeScript.

But now might be the time to replace the current complex JS implementation with a simple CSS implementation, given that all major browsers have supported -webkit-line-clamp for a while (click "Usage Relative").

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Truncate component and its documentation, especially the “HTML markdown support” section, then reproduce the JSX and TypeScript errors described in the issue. Done would require an agreed scope for correcting JSX behavior, updating the documentation, and verifying the supported syntax; the issue does not name implementation files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, javascript, react, typescript
Domain
documentation, frontend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.