-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Removed dynamic stylesheet and migrated to CSS vars #2854
base: master
Are you sure you want to change the base?
Conversation
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 really like the idea of using variables to limit changes, but having 2 styles per items now (we can optimized when 1x1 items like I did) makes me wonder if this will indeed be faster for rendering.
I've wanted to do the same for columns as we only generate CSSS for 1 & 12 and many people forget to include 2-11 and wonder why things don't render. So I would like to do this for column more so actually.
this means complete removal of gs-x,y,w,h as those are only used to refer to classes anyway. We could still support READING them (for backward support), but always clear them during writting so we only have style then.
@@ -2306,7 +2260,7 @@ export class GridStack { | |||
this.resizeToContentCheck(false, node); | |||
if (subGrid) { | |||
subGrid.parentGridNode = node; | |||
if (!subGrid.opts.styleInHead) subGrid._updateStyles(true); // re-create sub-grid styles now that we've moved | |||
subGrid._updateStyles(); // re-create sub-grid styles now that we've moved |
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.
might not be needed. all _updateStyles() need to be verified if needed to be called actually... sicne the external file isn't used 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.
Well, my changes are quite conservative, I don't have the full knowledge about the side effects expected by this call (i.e. _updateContainerHeight)
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.
fair enough. but if there was a condition styleInHead then that means it's location based and therefore entire thing doesn't apply.
I am putting this here as you mentioned it in your comment above @adumesny: we are for example using the attributes It should be no problem, however, if they were replaced with unitless CSS custom properties like |
@adiessl how would unitless CSS work for you ? wouldn't all have --gs-h then and would would you tell them appart (height of 1 vs 2) ? |
I forked the official Fiddle and amended the CSS to show how we are using the attributes at the moment to display the grid cells' dimensions: https://jsfiddle.net/2y7w3jL0/ Unfortunately I was mistaken about being able to use unitless CSS custom properties. A CSS custom property cannot be used as |
@adiessl cool example (missing 1x1 case when no attr). we should add that as a demo. |
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.
do you want to do column as well to match ?
spec/gridstack-spec.ts
Outdated
@@ -1370,41 +1370,24 @@ describe('gridstack', function() { | |||
afterEach(function() { | |||
document.body.removeChild(document.getElementById('gs-cont')); | |||
}); | |||
it('should add STYLE to parent node as a default', function() { | |||
var options = { | |||
it('should not add STYLE to parent node', function() { |
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.
just remove - obsolete code.
@@ -98,6 +100,19 @@ $animation_speed: .3s !default; | |||
> .ui-resizable-sw { cursor: sw-resize; width: 20px; height: 20px;} | |||
> .ui-resizable-w { cursor: w-resize; width: 10px; top: 15px; bottom: 15px; } | |||
|
|||
> .ui-resizable-n { | |||
top: var(--gs-item-margin-top); |
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.
that conflicts with 95. need to figure out why I have 0 while you have '5' - either way we don't want 2 rules...
same with rest below...
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.
This comes from the old code:
Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-n`, `top: ${top};`);
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.
yep ok, so replace my 0 with your var then (just one css rule). all your resize should merge into my existing rules.
@@ -1317,7 +1308,7 @@ export class GridStack { | |||
// restore any sub-grid back | |||
if (n.subGrid?.el) { | |||
itemContent.appendChild(n.subGrid.el); | |||
if (!n.subGrid.opts.styleInHead) n.subGrid._updateStyles(true); // force create | |||
n.subGrid._updateStyles(); |
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.
again if we skipped redoing styles that were global, then most likely we don't need to do anything... need to go though all calls and only call when what we upate changes...
ONLY when cellHeigt OR margin is changed, OR number of rows for grid total height (might need to tweak 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.
Same as above, since my changes are quite conservative, I don't feel that the performances are hurting so much in removing the line. Probably better to split _updateStyles and extract _updateContainerHeight from it?
src/gridstack.ts
Outdated
@@ -1635,7 +1635,12 @@ export class GridStack { | |||
if ((!n._moving && !n._resizing) || this._placeholder === el) { | |||
// Set inline style, refer CSS variables | |||
el.style.top = `calc(${n.y} * var(--gs-cell-height))`; | |||
el.style.height = `calc(${n.h} * var(--gs-cell-height))`; | |||
if (n.h !== 1) { |
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.
n.h > 1 ? el.style.height = calc(${n.h} * var(--gs-cell-height))
: delete el.style.height; // default h=1 set globally
to match above case.
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.
This will trigger the
Extract the assignment of "el.style.height" from this expression.sonarlint(typescript:S1121)
sonar lint issue, part of the recommended TS set.
I quite agree to that, being a "delete" part of else branch as well.
A better way is probably trying to assign an empty string to height, or undefined.
changes in #2874 need to be cherry picked too. |
Description
The proposed change is to remove the dynamic CSS classes generation for rows and margins.
This has many benefits: it will speed up relayout operations, optimize performances for high row count and and fix the CSP style compatibility.
The requirement is CSS variables, that is now widely available: https://caniuse.com/css-variables
This deprecates the
styleInHead
properties as well.It overrides #2852 as well.
Checklist
yarn test
) (well, the failing test count is not increasing after the change, the main trunk has many failures)