-
Shipping Way More JavaScript than We Need.Should we consider dropping our replicated native elements? I intend to outline the reasons that I think that we should. I also outline all of the elements that currently replicate native behavior in the browser. SummaryWe could effectively ship less JavaScript and provide a better experience for our users by doing so. Shipping less JavaScript means decreased build times, decreased load times, and a smaller burden on our CDN. All three of these would amount to a cost savings. All of these benefits are either passed directly onto the user or benefit Twilio in a large capacity since Paste is the default UI library now. Additionally less time would be required for maintaining the code for effectively reimplementing the native elements. This could save development time. Many of the components do little outside of forward props to the native implementation and style the element. Why not just make a CSS file that makes the elements look like Paste elements. For instance... ExampleThe button code we use today like this... <Button variant="primary">
Hello World!
</Button> ...would simply become. <button class="primary">
Hello World!
</button>
<!--You could keep it as variant instead of class if you wanted I guess...--> As you can see it is actually a little shorter to write the non paste version, and it doesn't incur any JavaScript penalty for using it (aside from the penalty from our framework.) Our button elements when using paste, would just be button elements. It still frees us to use CSS to override the styles as we still can today if needed. 99% of the time this won't be a problem. Developers would have to look up the Paste API less because more of the elements being used would be native elements. Hopefully we all know the native HTML APIs relatively well. This will also lead to less accessibility issue surface area. We can be more effective by using the semantic elements in some cases. Proposed components to changeForm elementsI'm going to give a few examples of purely duplicated form controls.
Visual elementsA list of visual components that we effectively duplicate are below.
Proposed SolutionI propose that we do not kill the components outright. Instead we can take a two pronged approach to properly deprecating the components. We should be very careful about the roll out as to not create a burden on the engineering teams to migrate again. Also we should roll the changes out to each product slowly iterating migration tools and bug fixes along the way.
Potential Problems
I finally will assert that my opinion is that the potential DX improvements here will never reach the customer. The customer doesn't care if you've got a custom React element that saves you two seconds by not forcing you to write a label tag. They will however notice if the page loads slower. The will notice when bugfixes take longer to get out because the bundle is bigger. These changes I've proposed are intended to put the customer first and potentially have a big impact across the org. This is not intended to be a criticism of the Paste library, but trying to make broad stroke improvements for the developers that use it. Feel free to disagree with any of the topics above. If any of this gets through it'll make the experience better IMO. I also don't think anyone should take this on all at once. It should be done slowly. Thank you for hearing out my rant. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Disclaimer: This is a very experimental bot using OpenAI's GPT-4. The answers may not be correct, a human will review the answer and update it if necessary. Sorry, I don't know how to help with that. I did do a search though, and I managed to find these other Discussions that might be similar or related to your question. Give them a read to see if they answer your question. If they do, head back here and update this discussion and mark it as answered, pointing others to the related discussion:
|
Beta Was this translation helpful? Give feedback.
-
Hi @cogwizzle, I appreciate your perspective, though I think there might be some nuances to consider regarding design systems. While the concept of using native elements with CSS classes to minimize JavaScript payload is valid, the reasons behind the current architecture are more intricate than a simple discussion reply can cover. I might consider delving into this topic further in a series of blog posts in the future, but for now, I'll offer a brief overview below. Why do some companies need design systemsAs tech companies expand, so does the number of engineers working on user-facing products. Those engineers come from varying backgrounds and levels of experience. How do the people working at the company ensure quality, consistent, and brand guidelines are followed?
So you need a centralized team to create a system that satisfies the needs of that particular company, can budget in education and documentation, as well as manage the codebase so competing products or groups within the organization don't cause rifts. A funded design system team signals that you take product design and engineering seriously and supports new hires with onboarding. Now what do design systems actually do?Many things, but for the sake of this discussion I will focus on one: change management. More or less, every tech company attempts to do a UI refresh every 3 or so years. Technologies change, styles change, the brand evolves, etc. It doesn't always have to be a conscious thing. Let me try to paint a picture. Say we said to use Problems in the codebase occur creepingly, and by the time you notice it it is usually quite late. The first problem is that the design system team cannot reasonably affect change in the product as the designs evolve due to the overrides battling each other on top of the base designs. The second problem is that new engineers who aren't part of this override history have no idea why things don't look the way they should. They may not even have repo access to where the CSS overrides are happening in order to fix them. Lastly, someone has to eventually look at all the variations and remedy the situation in the codebase to create a new single source of truth without overrides. This is where Twilio Console was when this team got funded, and that's exactly what we did. Cascading Style Sheets are great until they're not. The Cascade part is an anti-pattern at scale. If you research the cascade and why it's bad, you'll find plenty of blogs talking about it. So the design system team needs to restrict access to overrides. CSS modules is a solution, but while it fixes the cascade you can still add classes to any element over the existing ones. This prevents a central team like us to affect any change. Also it's confusing, because people think CSS class ordering on elements matters but it does not. Take for example We need guardrailsIt hurts to say, but we need guardrails. Good intentions don't always lead to good outcomes. It could be an early-in-career engineer or it could be a lead, but things always slip given enough time. At Twilio scale, and at the time when we started, the best technological solution for this problem was Emotion + Styled-system. I had come from a background of PostCSS + CSS Modules but it didn't allow us the same level of control and change management as a CSS-in-JS solution. This solution comes at a minor runtime cost, but allows us to operate at Twilio scale and ship design updates without breaking changes. The price we pay for this degree of confidence and resiliency is truly worth it. In other companies that are structured differently, a different solution may make sense. Duplicating semantic HTML into React componentsNot every engineer is a semantic HTML expert. A lot of engineers at Twilio are backend engineers trying to get by on the frontend. They may not know things you consider common knowledge. Aside from that, we have carefully crafted each component to work harmoniously with each other in a design language that is entirely Twilio. Instead of reaching for a Questions we asked ourselves
Technology todayAny workable solution, even by today's standards, will employ a minor runtime overhead to achieve the guardrails we need at enterprise scale. By design, only specific props are allowed on Paste components; the only technological surface upon which we can restrict that is through Javascript. When we started, no one was using Typescript. Even today we aren't completely a Typescript shop, and it's too easy to This has been a long answer, but is still very superficial and misses many key elements. Let me know if this has helped at all clarify why some things are the way they are, and if anything requires further explanation. |
Beta Was this translation helpful? Give feedback.
Hi @cogwizzle,
I appreciate your perspective, though I think there might be some nuances to consider regarding design systems. While the concept of using native elements with CSS classes to minimize JavaScript payload is valid, the reasons behind the current architecture are more intricate than a simple discussion reply can cover. I might consider delving into this topic further in a series of blog posts in the future, but for now, I'll offer a brief overview below.
Why do some companies need design systems
As tech companies expand, so does the number of engineers working on user-facing products. Those engineers come from varying backgrounds and levels of experience. How do the people wor…