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
CodeBlock
: update to support dynamic content
#1853
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
b93bdf3
to
49306c0
Compare
code, | ||
element, | ||
}); | ||
}, 100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using next
to replace this setTimeout
and it still functions.
I tried using schedule
instead and got errors but maybe I was using it wrong so I'll experiment a bit more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed up the variation using next
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, then let's wait for @alex-ju to come back from PTO and we can then decide how to take it from here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using next
sounds like a great idea to me (not sure how I've not thought about it) – do all the examples work as expected with this change, or is it something that prevents us from moving forward with this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to work although I can do more testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we could also test this change to make sure it addresses the actual need in boundary
(where you identified the issue) that would be even better – let me know if I can be of help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alex-ju I tried figuring out how to add an integration test but haven't been able to figure out a way to do it.
I can try to test it just in Boundary next though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool! I can look into the integration test bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the CodeBlock updates in Boundary and everything worked as expected. The content updates dynamically.
6884711
to
5017c1f
Compare
CodeBlock
: update to support dynamic content
.dom('#test-code-block pre code') | ||
.hasText("console.log('Hello world');"); | ||
this.set('value', "console.log('Lorem ipsum');"); | ||
await settled(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially tried with rerender
, but it's too 'quick' (in a sense that it doesn't wait for the whole promise to end) so I ended up using settled
.
Ember idiomatic and more deterministic
9be22d4
to
b7a1e14
Compare
This was caused by incorrect `font-family` declaration
7aff5aa
to
fb501b4
Compare
7ee9c5e
to
bba003c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple of comments.
@value={{this.codeValue}} | ||
@language="javascript" | ||
@hasCopyButton={{true}} | ||
@hasLineNumbers={{false}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that if you set this to "true" (and probably we should) when the lines gets updated, the line numbers don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, no – I'll look and see if I can find a workaround for this – doesn't look great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into this during the first week of January and today again. Unfortunately, I can not see a way in which the @hasLineNumbers
feature would work with dynamic content.
For this reason, I suggest the pragmatic approach of fixing the immediate issues (I updated the PR description to highlight what this PR covers and what doesn't) to address current instances in HCP and Boundary then leave the hasLineNumbers
issue for future evaluation (it may require us to fork the addon or move away from Prism altogether). If you find this approach acceptable, I can create a ticket to track this use case and update the CodeBlock guidance to call out the current limitations.
bba003c
to
5d2cfbd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
📌 Summary
If merged, this PR:
CodeBlock
component to enable it to render updated dynamic contentLimitations:
@hasLineNumbers={{true}}
; this comes from a limitation with the line-numbers Prism plugin where it can only be instantiated/called once.@hasLineNumbers={{true}}
does not work as expected when used in aTabs
tab that is not visible at render time.Showcase: https://hds-showcase-git-test-codeblock-with-dynamic-content-hashicorp.vercel.app/components/code-block
📸 Screenshots
Misalignment issue in HCP. The more line there are the more you can see the issue.
🔗 External links
👀 Component checklist
yarn test:a11y --filter="COMPONENT-NAME"
)a11yAudit
has been added💬 Please consider using conventional comments when reviewing this PR.