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

Render table in the shadow DOM for @finos/perspective-viewer-datagrid #2482

Merged
merged 1 commit into from
Jan 22, 2024

Conversation

tomjakubowski
Copy link
Contributor

@tomjakubowski tomjakubowski commented Dec 29, 2023

Move the <regular-table> element of datagrid into the shadow DOM by default.

This change isolates the regular-table from global styles, so CSS rules on regular-table or table no longer affect datagrid. Style rules on the regular-table can be ported using the part named regular-table

// old style
perspective-viewer-datagrid regular-table {
  font-family: "Comic Sans MS";
}
// shadow dom
perspective-viewer-datagrid::part(regular-table) {
  font-family: "Comic Sans MS";
}

To disable this feature and continue to use light DOM rendering, set:

HTMLPerspectiveViewerDatagridPluginElement.renderTarget = "light"

@tomjakubowski tomjakubowski force-pushed the bugfix/regular-table-shadow-dom branch from 0132c9f to f34bb03 Compare December 29, 2023 21:30
@texodus texodus changed the title datagrid: add feature flag to render table in shadow DOM Add option to render table in the shadow DOM for @finos/perspective-viewer-datagrid Dec 30, 2023
@texodus texodus added the enhancement Feature requests or improvements label Dec 30, 2023
Copy link
Member

@texodus texodus left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! A couple of things need fixing:

  1. I'm ok with the configuration flag being a global static on the perspective-viewer-datagrid element, because there is no global settings feature yet, but one is obviously needed. However, let's please rename this to enableShadowDOM.
  2. enableShadowDOM should be true by default, e.g. we should default use the Shadow DOM. It looks like the examples work in this mode with this PR (👍 ), so no changes needed there. It is ok if the tests remain as Light DOM tests because they do some DOM surgery to check table elements, but ...
  3. There needs to be at least a few tests added that test Shadow DOM mode specifically. If it's doable, I'd really like to see all the tests run in parameterized in both modes, but this may be a lot of work (?)
  4. The tests are currently failing regardless (looks like perspective-jupyterlab).
  5. Let's remove the examples/blocks code which parses the URL.

examples/blocks/src/editable/index.html Outdated Show resolved Hide resolved
examples/blocks/src/magic/index.js Outdated Show resolved Hide resolved
@tomjakubowski
Copy link
Contributor Author

I'm ok with the configuration flag being a global static on the perspective-viewer-datagrid element, because there is no global settings feature yet, but one is obviously needed. However, let's please rename this to enableShadowDOM.

Another API I was thinking about was sticking it as an attribute/flag on <perspective-viewer>, like <perspective-viewer shadow />. A problem is I imagine it would be disastrous to update a particular element to use/not use shadow DOM at runtime, i.e. to toggle usage of shadow DOM in response to changes to that attribute.

There needs to be at least a few tests added that test Shadow DOM mode specifically. If it's doable, I'd really like to see all the tests run in parameterized in both modes, but this may be a lot of work (?)

I'll try this, it's a good idea to rerun the same tests with shadow DOM enabled/disabled. And I'll think about a test or two just for shadow DOM

@tomjakubowski tomjakubowski force-pushed the bugfix/regular-table-shadow-dom branch from c57c0a0 to 83fe46c Compare January 13, 2024 02:28
@tomjakubowski tomjakubowski changed the title Add option to render table in the shadow DOM for @finos/perspective-viewer-datagrid Render table in the shadow DOM for @finos/perspective-viewer-datagrid Jan 13, 2024
@tomjakubowski tomjakubowski force-pushed the bugfix/regular-table-shadow-dom branch from fffed57 to 6e7b217 Compare January 17, 2024 01:13
@tomjakubowski
Copy link
Contributor Author

All the checks are passing now, re-review?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

curious if you have any recommendations for quickly diffing these tarballs?

Copy link
Member

Choose a reason for hiding this comment

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

Not sure what you mean. In theory, if the snapshots don't change, the tarball should be identical. We've added a few flags to the gzip process to force this to be the case regardless of things like file creation time.

I have noticed that this is not always the case, but I don't know why yet, nor have I even validated that this is an issue with the tarball or the actual files.

Move the `<regular-table>` element of datagrid into the shadow DOM by
default.

This change isolates the regular-table from global styles, so CSS rules
on `regular-table` or `table` no longer affect datagrid. Style rules on
the `regular-table` can be ported using the part named `regular-table`

```
// old style
perspective-viewer-datagrid regular-table {
  font-family: "Comic Sans MS";
}
// shadow dom
perspective-viewer-datagrid::part(regular-table) {
  font-family: "Comic Sans MS";
}
```

To disable this feature and continue to use light DOM rendering, set:

```
HTMLPerspectiveViewerDatagridPluginElement.renderTarget = "light"
```
@tomjakubowski tomjakubowski force-pushed the bugfix/regular-table-shadow-dom branch from 6e7b217 to 5b5624a Compare January 19, 2024 04:48
Copy link
Member

@texodus texodus left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Looks good!

@texodus texodus merged commit 345edf5 into finos:master Jan 22, 2024
13 checks passed
@jakehadar
Copy link

jakehadar commented May 7, 2024

I'm ok with the configuration flag being a global static on the perspective-viewer-datagrid element, because there is no global settings feature yet, but one is obviously needed. However, let's please rename this to enableShadowDOM.

Another API I was thinking about was sticking it as an attribute/flag on <perspective-viewer>, like <perspective-viewer shadow />. A problem is I imagine it would be disastrous to update a particular element to use/not use shadow DOM at runtime, i.e. to toggle usage of shadow DOM in response to changes to that attribute.

There needs to be at least a few tests added that test Shadow DOM mode specifically. If it's doable, I'd really like to see all the tests run in parameterized in both modes, but this may be a lot of work (?)

I'll try this, it's a good idea to rerun the same tests with shadow DOM enabled/disabled. And I'll think about a test or two just for shadow DOM

Hi, was this attribute flag ever exposed publicly? Looks like it is a static/private attribute set at runtime based on browser capaibility https://github.com/finos/perspective/blame/84605851230c3dd1cc58652b47babd04cc9fcc31/packages/perspective-viewer-datagrid/src/js/custom_elements/datagrid.js#L141
This introduces inconsistencies between browsers and i believe the shadow rendering policy should be something the consumer should have the option to opt-out of

@tomjakubowski
Copy link
Contributor Author

@jakehadar The inferred setting is a default. You can override it by using customElements.whenDefined() to access the custom element constructor when it is added to the registry, and then set the renderTarget property on it to whichever you prefer.

customElements.whenDefined("perspective-viewer-datagrid").then((datagrid) => {
  console.log("setting datagrid render target");
  datagrid.renderTarget = "light";
});

datagrid.renderTarget is currently an undocumented API, but I don't anticipate it will change in the near term.

@tomjakubowski tomjakubowski deleted the bugfix/regular-table-shadow-dom branch May 8, 2024 18:01
@jakehadar
Copy link

jakehadar commented May 9, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests or improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants