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

fix(flamegraph): fix its styling #1388

Merged
merged 16 commits into from Aug 15, 2022
Merged

fix(flamegraph): fix its styling #1388

merged 16 commits into from Aug 15, 2022

Conversation

eh-am
Copy link
Collaborator

@eh-am eh-am commented Aug 11, 2022

  • Makes @pyroscope/flamegraph and webapp have the same styling rules (mostly the normalization ones)
  • Publish storybook under github action artifacts, so that we can visually inspect the components
  • Inline sanitize.css, for some reason I could make it so that a nested import ~sanitize.css would be inlined (tried with postcss plugin and nothing)

The original problem is that the webapp and flamegraph (standalone) shipped different sets of CSS. Which means it would look just fine in webapp (which is what most people would be running), then in the standalone version (imported via @pyroscope/flamegraph package), it would look slightly off.

Turns out the difference is that the flamegraph was not shipping the styles from normalize.css.
However, we can't just ship those styles, since they are global and they may affect end user's style (imagine I embed the flamegraph into my component, and then somehow it overrides my app's button!).

Therefore we need to scope those rules.

However, if we scope those rules, then they start to override the ones from css modules. The reason is simple.
Consider a sanitize.css rule for table:

table {
  border-collapse: collapse;
}

If we scope under .pyroscope it will become:

.pyroscope table {
  border-collapse: collapse;
}

Then let's say we have a css modules rule, which normally would override the one from sanitize css (since class has higher precedence over a simple tag)

.oiJX5Zp1+W8aJOcWSU-baQ== {
  border-collapse: separate;
}

In our case, .pyroscope table is higher than .oiJX5Zp1+W8aJOcWSU-baQ==, therefore our css module style would never be applied.

To "solve" this I ended up using a "custom" element (not confuse with real custom elements), here called pyro-flamegraph.

That way, pyro-flamegraph table still has a lower specificity than .oiJX5Zp1+W8aJOcWSU-baQ==, restoring the original behavior of having classes generated by CSS modules to overwrite the styles from the reset.


Disclaimer

This may break for people that assume the flamegraph component has a certain shape, eg in snapshot tests.
Since we publish the component as < 1.0.0, I won't publish as a breaking change (even though it is).

@codecov
Copy link

codecov bot commented Aug 11, 2022

Codecov Report

Merging #1388 (d798256) into main (a23c80d) will increase coverage by 0.06%.
The diff coverage is 61.54%.

@@            Coverage Diff             @@
##             main    #1388      +/-   ##
==========================================
+ Coverage   67.60%   67.66%   +0.06%     
==========================================
  Files         123      123              
  Lines        4040     4047       +7     
  Branches      930      932       +2     
==========================================
+ Hits         2731     2738       +7     
  Misses       1305     1305              
  Partials        4        4              
Impacted Files Coverage Δ
...e-flamegraph/src/FlameGraph/FlameGraphRenderer.tsx 48.26% <ø> (ø)
...ckages/pyroscope-flamegraph/src/Toolbar.module.css 61.54% <ø> (ø)
packages/pyroscope-flamegraph/src/Toolbar.tsx 90.09% <ø> (ø)
...javascript/components/AppSelector/SelectButton.tsx 100.00% <ø> (ø)
webapp/javascript/components/AppSelector/index.tsx 86.21% <0.00%> (ø)
...ages/pyroscope-flamegraph/src/sass/flamegraph.scss 30.77% <50.00%> (ø)
...es/pyroscope-flamegraph/src/FlamegraphRenderer.tsx 100.00% <100.00%> (ø)
webapp/javascript/redux/reducers/continuous.ts 26.22% <0.00%> (ø)
...javascript/pages/tagExplorer/components/Legend.tsx 100.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 11, 2022

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
webapp/public/assets/app.js 411.24 KB (-0.01% 🔽) 8.3 s (-0.01% 🔽) 2.9 s (-23% 🔽) 11.1 s
webapp/public/assets/app.css 15.13 KB (+7.82% 🔺) 303 ms (+7.82% 🔺) 0 ms (+100% 🔺) 303 ms
webapp/public/assets/styles.css 9.74 KB (-0.84% 🔽) 195 ms (-0.84% 🔽) 0 ms (+100% 🔺) 195 ms
packages/pyroscope-flamegraph/dist/index.js 90.13 KB (+0.01% 🔺) 1.9 s (+0.01% 🔺) 1.5 s (-13.83% 🔽) 3.4 s
packages/pyroscope-flamegraph/dist/index.node.js 90.02 KB (+0.01% 🔺) 1.9 s (+0.01% 🔺) 438 ms (-16.99% 🔽) 2.3 s
packages/pyroscope-flamegraph/dist/index.css 6.77 KB (+15.99% 🔺) 136 ms (+15.99% 🔺) 0 ms (+100% 🔺) 136 ms

@eh-am
Copy link
Collaborator Author

eh-am commented Aug 11, 2022

/create-server

@eh-am eh-am changed the title chore: fix flamegraph css fix(flamegraph): fix its styling Aug 12, 2022
@eh-am
Copy link
Collaborator Author

eh-am commented Aug 12, 2022

/create-server

@eh-am
Copy link
Collaborator Author

eh-am commented Aug 12, 2022

/create-server

@eh-am
Copy link
Collaborator Author

eh-am commented Aug 12, 2022

/create-server

@eh-am eh-am marked this pull request as ready for review August 12, 2022 15:45
@@ -0,0 +1,38 @@
name: Storybook
Copy link
Member

Choose a reason for hiding this comment

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

storybook is back! ❤️

@petethepig petethepig self-requested a review August 12, 2022 16:08
Copy link
Member

@petethepig petethepig left a comment

Choose a reason for hiding this comment

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

Interesting solution! LGTM

@eh-am eh-am merged commit 5788cf9 into main Aug 15, 2022
@eh-am eh-am deleted the chore/fix-flamegraph-css branch August 15, 2022 18:37
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.

None yet

2 participants