Skip to content

Commit c676465

Browse files
committed
added support for CTX api
1 parent fa8e5f1 commit c676465

File tree

5 files changed

+73
-8
lines changed

5 files changed

+73
-8
lines changed

src/app/components/StateRoute/ComponentMap/ComponentMap.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ export default function ComponentMap({
153153
return propsFormat;
154154
};
155155

156+
const formatContext = data => {
157+
const propsFormat = [];
158+
const nestedObj = [];
159+
for (const key in data) {
160+
propsFormat.push(
161+
<p className="stateprops">
162+
{`${key}: ${data[key]}`}
163+
</p>,
164+
);
165+
}
166+
return propsFormat;
167+
};
168+
156169
const formatState = state => {
157170
if (state === 'stateless') return ['stateless'];
158171
return ['stateful'];
@@ -378,10 +391,15 @@ export default function ComponentMap({
378391
{formatState(tooltipData.state)}
379392
</div>
380393
<div style={React.scrollStyle}>
381-
<div className="props">
382-
Props:
394+
<div className="tooltipWrapper">
395+
<h2>Props:</h2>
383396
{formatProps(tooltipData.componentData.props)}
384397
</div>
398+
{tooltipData.componentData.context &&
399+
<div className="tooltipWrapper">
400+
<h2>Context:</h2>
401+
{formatContext(tooltipData.componentData.context)}
402+
</div>}
385403
</div>
386404
</div>
387405
</TooltipInPortal>

src/app/styles/main.scss

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
@charset 'UTF-8';
22
@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap');
3+
34
* {
45
font-family: 'Roboto', sans-serif;
56
}
67

8+
.tooltipWrapper {
9+
background-color: #505050;
10+
color: rgb(216, 216, 216);
11+
margin-top: 3px;
12+
padding: 2px;
13+
}
14+
15+
.tooltipWrapper h2 {
16+
margin-top: 1px;
17+
margin-bottom: 1px;
18+
font-size: small;
19+
font-weight: bolder;
20+
}
21+
22+
.tooltipWrapper p {
23+
margin-top: 1px;
24+
margin-bottom: 1px;
25+
margin-left: 10px;
26+
}
27+
728
/* width */
829
::-webkit-scrollbar {
930
width: 5px;
@@ -36,13 +57,13 @@
3657

3758
// 4. Layout-related sections
3859
@import 'layout/mainContainer', 'layout/bodyContainer', 'layout/actionContainer',
39-
'layout/errorContainer', 'layout/stateContainer', 'layout/travelContainer',
40-
'layout/buttonsContainer', 'layout/headContainer.scss';
60+
'layout/errorContainer', 'layout/stateContainer', 'layout/travelContainer',
61+
'layout/buttonsContainer', 'layout/headContainer.scss';
4162

4263
// 5. Components
4364
@import 'components/buttons', 'components/actionComponent',
44-
'components/jsonTree', 'components/renderingFrequency',
45-
'components/performanceVisx';
65+
'components/jsonTree', 'components/renderingFrequency',
66+
'components/performanceVisx';
4667

4768
// slider component
4869
@import './components/rc-slider', './components/sliderHandle';
@@ -51,4 +72,4 @@
5172
@import './components/d3graph.css';
5273

5374
// diff component
54-
@import './components/diff';
75+
@import './components/diff';

src/backend/linkFiber.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,24 @@ function createTree(
181181
actualStartTime,
182182
selfBaseDuration,
183183
treeBaseDuration,
184+
dependencies,
185+
_debugHookTypes,
184186
} = currentFiber;
185187

188+
// if (currentFiber.tag === 10) {
189+
// const queue = [currentFiber];
190+
// while (queue.length > 0) {
191+
// const tempFiber = queue.shift();
192+
// if (tempFiber.tag === 0) console.log(tempFiber);
193+
// if (tempFiber.sibling) {
194+
// queue.push(tempFiber.sibling);
195+
// }
196+
// if (tempFiber.child) {
197+
// queue.push(tempFiber.child);
198+
// }
199+
// }
200+
// }
201+
186202
// check to see if we can get the information we were looking for
187203
if (tag === 5) {
188204
try {
@@ -209,6 +225,7 @@ function createTree(
209225
selfBaseDuration?: number;
210226
treeBaseDuration?: number;
211227
props?: any,
228+
context?: any,
212229
} = {};
213230
let componentFound = false;
214231

@@ -217,6 +234,11 @@ function createTree(
217234
componentData.props = convertDataToString(memoizedProps, null);
218235
}
219236

237+
// if the component uses the useContext hook, we want to grab the co text object and add it to the componentData object for that fiber
238+
if (tag === 0 && _debugHookTypes) {
239+
componentData.context = convertDataToString(dependencies?.firstContext?.memoizedValue, null);
240+
console.log(convertDataToString(componentData.context, null), componentData.context);
241+
}
220242
// Check if node is a stateful class component
221243
if (stateNode && stateNode.state && (tag === 0 || tag === 1 || tag === 2)) {
222244
// Save component's state and setState() function to our record for future

src/backend/types/backendTypes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,8 @@ export type Fiber = {
174174
// This value bubbles up during the "complete" phase.
175175
// This field is only set when the enableProfilerTimer flag is enabled.
176176
treeBaseDuration?: number;
177+
178+
dependencies: any;
179+
180+
_debugHookTypes: any;
177181
};

www/src/pages/components/FeaturesSection.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default function FeaturesSection() {
5252
What makes Reactime so great?
5353
</p>
5454
<p className="mx-auto mt-5 max-w-prose text-xl text-gray-500">
55-
Reactime is full of features that make your life easier as a developer. From time-travel debugging to state snapshot display, check out how using Reactime will improve your developer experience.
55+
Reactime iscd full of features that make your life easier as a developer. From time-travel debugging to state snapshot display, check out how using Reactime will improve your developer experience.
5656
</p>
5757
<div className="mt-20">
5858
<div className="grid grid-cols-1 gap-12 sm:grid-cols-2 lg:grid-cols-3">

0 commit comments

Comments
 (0)