Skip to content
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

refactor(table): refactor internals to work around HTML parser issue #10649

Merged

Conversation

jcfranco
Copy link
Member

@jcfranco jcfranco commented Oct 30, 2024

Related Issue: #10495

Summary

Split up table rendering to bypass HTML parser corrections that would break functionality and styling.

@jcfranco jcfranco marked this pull request as draft October 30, 2024 05:53
@@ -410,11 +410,27 @@ export class TableRow extends LitElement implements InteractiveComponent {
ariaSelected={this.selected}
class={{ [CSS.lastVisibleRow]: this.lastVisibleRow }}
onKeyDown={this.keyDownHandler}
ref={this.tableRowEl}
ref={(el) => {
if (!el || this.tableRowEl) {
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: improve how internal structure is updated, cleaned up

@@ -108,7 +108,7 @@ export class Table extends LitElement implements LoadableComponent {
* @notPublic
*/
/** TODO: [MIGRATION] This component has been updated to use the useT9n() controller. Documentation: https://qawebgis.esri.com/arcgis-components/?path=/docs/references-t9n-for-components--docs */
messages = useT9n<typeof T9nStrings>();
messages = useT9n<typeof T9nStrings>({ blocking: true });
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: need to investigate why blocking the table's messages helps tests succeed consistently (possibly extra delay helps?)

@@ -127,7 +127,11 @@ export class Table extends LitElement implements LoadableComponent {
*
* @readonly
*/
@property() selectedItems: TableRow["el"][] = [];
@property() get selectedItems(): TableRow["el"][] {
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: clean up

ariaRowCount={this.allRows?.length}
class={{ [CSS.tableFixed]: this.layout === "fixed" }}
ref={(el) => {
if (!el || this.tableHeadSlotEl) {
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: tidy up, improve naming

packages/calcite-components/src/components/table/table.tsx Outdated Show resolved Hide resolved
@@ -74,7 +74,7 @@ export class TableHeader extends LitElement implements LoadableComponent {
* @notPublic
*/
/** TODO: [MIGRATION] This component has been updated to use the useT9n() controller. Documentation: https://qawebgis.esri.com/arcgis-components/?path=/docs/references-t9n-for-components--docs */
messages = useT9n<typeof T9nStrings>();
messages = useT9n<typeof T9nStrings>({ blocking: true });
Copy link
Member Author

Choose a reason for hiding this comment

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

Needed to block these to ensure an a11y test passes (https://dequeuniversity.com/rules/axe/4.10/empty-table-header?application=axeAPI).

/>
);
private renderSelectableCell(): void {
const cell: any =
Copy link
Member

Choose a reason for hiding this comment

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

(optional) store the reference to the element that was created on previous render and update it rather than create a new element?
that would improve re-render performance

/>
);
private renderNumberedCell(): void {
const cell =
Copy link
Member

Choose a reason for hiding this comment

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

(optional) store the reference to the element that was created on previous render and update it rather than create a new element?
that would improve re-render performance

packages/calcite-components/src/components/table/table.tsx Outdated Show resolved Hide resolved
packages/calcite-components/src/components/table/table.tsx Outdated Show resolved Hide resolved
@maxpatiiuk
Copy link
Member

Did you find out what was the main issue with rendering the table in parts with JSX?
was is that each lit-html template is parsed independently and so is not valid unless taken wholistically?
or that lit-html doesn't correctly append the elements to the table element? (appends them, but browser moves them out?)

depending on what was the cause, you might be able to make this PR a bit more declarative by directly calling lit-html's render() function to render desired content into the desired container. I have an example of this in the docs: https://qawebgis.esri.com/arcgis-components/?path=/docs/lumina-jsx--docs#rendering-jsx-outside-the-component

render() will also take care of updating the previously rendered element in place if you call it again with the same markup

a limitation though: you can only render one template into some parent container at a given time using render() - if you try to render() a different template into the same container, the 2nd render() call will overwrite the result of the 1st call. this might be a deal breaker since you need to render thead, tbody and tfoot into the same parent

@jcfranco
Copy link
Member Author

jcfranco commented Nov 2, 2024

Did you find out what was the main issue with rendering the table in parts with JSX?
was is that each lit-html template is parsed independently and so is not valid unless taken wholistically?
or that lit-html doesn't correctly append the elements to the table element? (appends them, but browser moves them out?)

My guess is that the final template was processed and adjusted by the HTML parser, whereas dynamically creating the table structure through DOM APIs bypasses the parser.

@jcfranco jcfranco marked this pull request as ready for review November 3, 2024 23:59
@jcfranco jcfranco merged commit f629a5f into lumina Nov 4, 2024
5 checks passed
@jcfranco jcfranco deleted the jcfranco/refactor-table-to-workaround-html-parser-issue branch November 4, 2024 00:01
jcfranco added a commit that referenced this pull request Nov 5, 2024
…10649)

**Related Issue:** #10495

## Summary

Split up table rendering to bypass HTML parser corrections that would
break functionality and styling.
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.

3 participants