Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(Debug): Add CSSinJS debug panel #1974

Merged
merged 114 commits into from
Oct 15, 2019
Merged

feat(Debug): Add CSSinJS debug panel #1974

merged 114 commits into from
Oct 15, 2019

Conversation

miroslavstastny
Copy link
Member

@miroslavstastny miroslavstastny commented Sep 25, 2019

Motivation

Debugging Stardust Component styles is difficult. Stardust uses CSSinJS - styles are computed in JS using site variables, component variables and component style functions with possibility to override any of these using mergeThemes or by nesting Provider, styles are applied as atomic CSS classes which can result in tens of CSS classes applied to individual dom elements, developers have no idea where the styles came from:

image

Solution

This PR adds a debug panel which displays the flow of site variables, component variables and component style functions, including all overrides, which resulted in the styles applied on the element:
image

How to use

  • In your application use development version of both React and Stardust.
  • Add <Debug /> component anywhere to your application.
  • Enable Stardust debugging by setting window.localStorage.stardustDebug = true and reloading the page
  • Press Alt-Shift-d to open element selector.
  • Hover over a Stardust component:
    image
  • Select the component to show the panel with all information. 🔍
  • As an alternative, you can select the component which you want to inspect, from the React's debugging tools, and invoke from the console the openDebugPanel() function (it's still a requirement to have the <Debug /> component in your application.

miroslavstastny and others added 30 commits September 12, 2019 15:49
-added search and highlighting of the styles
-made filter to work on values as well
-strike variables which are overriden
-styles improvements
@@ -0,0 +1,35 @@
import * as React from 'react'

const Line: React.FC<{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const Line: React.FC<{
const DebugLine: React.FC<{

Copy link
Member Author

Choose a reason for hiding this comment

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

done


public whosValueContains(substring: string) {
return this.whosValue(value => containsSubstring(value, substring))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

  1. Make it type
  2. Reuse in DebugPanel, Debug???

Copy link
Member Author

Choose a reason for hiding this comment

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

Converted to type, reuse will be done later as part of Debug panel refactoring

@@ -42,7 +42,7 @@ const createComponent = <P extends ObjectOf<any> = any>({
const StardustComponent: CreateComponentReturnType<P> = (props): React.ReactElement<P> => {
// Stores debug information for component.
// Note that this ref should go as the first one, to be discoverable by debug utils.
const stardustDebug = React.useRef(null)
const ref = React.useRef(null)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const ref = React.useRef(null)
if (process.env.NODE_ENV !== 'production') {
const ref = React.useRef(null)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

The ref was already there. I am not sure we want to have different shape of the createComponent in prod vs dev.

resolvedStyles[slotName] = callable(mergedStyles[slotName])(styleParam)
const { _debug, ...resolvedSlotStyles } = callable(mergedStyles[slotName])(styleParam)
resolvedStyles[slotName] = resolvedSlotStyles
resolvedStylesDebug[slotName] = _debug
Copy link
Member

Choose a reason for hiding this comment

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

Wrap in production check

Copy link
Member Author

Choose a reason for hiding this comment

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

done

if (accessibility.focusZone) {
return renderWithFocusZone(render, accessibility.focusZone, resolvedConfig)
}

// conditionally add sources for evaluating debug information to component
if (isDebugEnabled) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (isDebugEnabled) {
if (process.env === ''' || isDebugEnabled) {

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@miroslavstastny miroslavstastny merged commit 0a715ab into master Oct 15, 2019
@miroslavstastny miroslavstastny deleted the feat/debug-panel branch October 15, 2019 16:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants