-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
core(details-renderer): snippet details renderer type #6999
Conversation
Getting this on local, is there anything else I need to do for i18n?
|
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.
really neat and powerful little snippet renderer! insanely better UX for the code I want to steal this for the unused CSS now :D
lighthouse-core/test/report/html/renderer/code-snippet-renderer-test.js
Outdated
Show resolved
Hide resolved
yeah you'll have to update the |
638ebda
to
3f7e50d
Compare
We'd like the error message text to always wrap within the visible area, so you can read it without scrolling. Like this: But right now it doesn't work if the lines themselves are scrollable: @rviscomi and I are ok with it, since having error messages that long is pretty rare. But let me know if you know some magic CSS trick that would fix this 🙂 |
@patrickhulce What do you think of the PR now? |
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.
lookin' real good!!
for the amount of complexity that's here I'm hoping for a bit broader test coverage if possible. Especially around some of the cases I'm talking about in the code where I'm confused :)
|
||
snippet.append(CodeSnippetRenderer.renderSnippetLines(dom, tmpl, details)); | ||
|
||
// If expanded view still doesn't include all lines then indicate that that |
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.
s/that that/that/
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.
also what about the collapsed view?
I'm very shaky on all the omitted lines placeholder logic, why wouldn't the other chunk of logic handle this case already?
if lines[0].number !== 1
then wouldn't line && !previousLine
be true in renderSnippetLines
for lines[0]
?
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.
let hasSeenHighlight = false; | ||
for (let lineNumber = 1; lineNumber <= lineCount; lineNumber++) { | ||
const {line, previousLine} = getLineAndPreviousLine(lines, lineNumber); | ||
const {line: collapsedLine, previousLine: collapsedPreviousLine} = |
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.
WDYT about some comments or more descriptive names here?
is this right?
!previousLine
is just telling us if this current line is the start of a visible block and we need to render the omitted lines placeholder for the stuff that came before?collapsedLine
is just telling us if this current line should be shown even when the snippet is collapsed?!collapsedPreviousLine
is just telling us if this current line is the start of a visible block and we need to render the omitted lines placeholder for the stuff that came before?
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've cleaned up the rendering logic a bit more, though it's still not exactly nice code 🤔
Let me know what you think.
5bbd284
to
c4237ed
Compare
e490a89
to
624690f
Compare
I think the cases where you're confused about line rendering all already have test cases 😂 Maybe you meant something else, or I need make the test names more descriptive? |
So sad 😞 |
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.
Looking good so far! I'm really liking this new renderer.
Also, very brave to go wading into the details types, sorry they're in such rough shape :S
lighthouse-core/test/report/html/renderer/details-renderer-test.js
Outdated
Show resolved
Hide resolved
}; | ||
} | ||
|
||
class SnippetListRenderer { |
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 feel like we need an overview for this type/renderer somewhere, though I'm not sure exactly where. Basically the only way to understand how it works right now is to read this file :)
In this file? On the details type in audit.d.ts
?
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.
Added some comments in audit-details.d.ts
.
lighthouse-core/test/report/html/renderer/snippet-list-renderer-test.js
Outdated
Show resolved
Hide resolved
lighthouse-core/test/report/html/renderer/snippet-list-renderer-test.js
Outdated
Show resolved
Hide resolved
This might be unavoidable because right now the viewer is like 60K after gzip and it includes all report renderer code twice (once for rendering, once for self replication), so a 11K+ new file would be expected to run right into that. There may be no choice but to bump the limit. |
having spent some time back in I've noticed that we already have several audits using single-column tables to get an ugly list, and switching them to a dedicated export interface DetailsRendererList {
type: 'list',
items: DetailsRendererSnippet[]
} aka
I don't think this will be much of a code change, but it will leave us with plenty of flexibility. WDYT? |
This reverts commit 249dd67b984c0071a29bcd9190092e98dc52f1cb.
4e9b17a
to
8aa311d
Compare
Have separated Also,
|
Dan, see #6750
|
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!
// @ts-ignore - TODO(bckenny): Fix type hierarchy | ||
/** @type {LH.Audit.Details.List} */ (details) | ||
); | ||
case 'snippet': |
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.
let's not add snippet
here (it's just going to be immediately removed anyways)
|
||
details.items.forEach(item => { | ||
// @ts-ignore TODO(bckenny): this can never be null | ||
listContainer.appendChild(this.render(item)); |
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.
rather than call this.render(item)
, just call SnippetRenderer.render()
directly (then also don't have to deal with null
)
type: string, | ||
items: Array<DetailsJSON> | ||
}} ListDetailsJSON | ||
*/ |
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 think this can be deleted?
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.
Yup!
types/audit-details.d.ts
Outdated
* Snippet of text with line numbers and annotations. | ||
*/ | ||
export interface Snippet { | ||
type: "snippet", |
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.
type: "snippet", | |
type: 'snippet', |
types/audit-details.d.ts
Outdated
/** | ||
* Snippet of text with line numbers and annotations. | ||
*/ | ||
export interface Snippet { |
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.
SnippetValue
to keep in line with the others, but otherwise this looks 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.
LGTM!
📜 🔼
📜✂️📜
📜 🔽
Summary
Details renderer type that shows a code snippet with error highlights.
Example LH report using code snippets for structured data
Status
Not 100% finished but would be good to get some initial review.Functionality is complete now.
Reverted JSON-LD commit is just here because I use it for testing.
Related Issues/PRs
Closes: #6901