Skip to content

Commit 21e6aa3

Browse files
sammy-SCmeta-codesync[bot]
authored andcommitted
Fix Fantom getRenderedOutput not reflecting removed props (#55891)
Summary: Pull Request resolved: #55891 `RenderOutput::renderView` merged old cached props with new debug props via `mergeDynamicProps`. Since `getDebugProps()` omits default-valued props, removed props were never cleared from the cache. Also, `renderedViews_.insert()` never overwrote existing entries. Changelog: [Internal] Reviewed By: javache Differential Revision: D95055704 fbshipit-source-id: 6cdcbde0473a1d03785f49a9eac79be18395a0bf
1 parent e1c2968 commit 21e6aa3

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

packages/react-native/Libraries/Components/View/__tests__/View-itest.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,28 @@ describe('<View>', () => {
670670
);
671671
});
672672
});
673+
674+
describe('nativeID', () => {
675+
it('resets nativeID when removed', () => {
676+
const root = Fantom.createRoot();
677+
678+
Fantom.runTask(() => {
679+
root.render(<View nativeID="my-id" collapsable={false} />);
680+
});
681+
682+
expect(root.getRenderedOutput({props: ['nativeID']}).toJSX()).toEqual(
683+
<rn-view nativeID="my-id" />,
684+
);
685+
686+
Fantom.runTask(() => {
687+
root.render(<View collapsable={false} />);
688+
});
689+
690+
expect(root.getRenderedOutput({props: ['nativeID']}).toJSX()).toEqual(
691+
<rn-view />,
692+
);
693+
});
694+
});
673695
});
674696

675697
describe('ref', () => {

private/react-native-fantom/tester/src/render/RenderOutput.cpp

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <react/debug/react_native_assert.h>
1010
#include <react/renderer/components/text/ParagraphState.h>
1111
#include <react/renderer/core/ConcreteState.h>
12-
#include <react/renderer/core/DynamicPropsUtilities.h>
1312

1413
namespace facebook::react {
1514

@@ -35,41 +34,18 @@ std::string RenderOutput::render(
3534
result.push_back(renderView(*child, options));
3635
}
3736

38-
// Remove any views from renderedViews_ that are no longer in the tree.
39-
for (auto it = renderedViews_.begin(); it != renderedViews_.end();) {
40-
if (!tree.hasTag(it->first)) {
41-
it = renderedViews_.erase(it);
42-
} else {
43-
++it;
44-
}
45-
}
46-
4737
treesMutated_.erase(tree.getRootStubView().surfaceId);
4838
return folly::toJson(result);
4939
}
5040

5141
folly::dynamic RenderOutput::renderView(
5242
const StubView& view,
5343
const RenderFormatOptions& options) {
54-
if (!treesMutated_.contains(view.surfaceId)) {
55-
if (auto it = renderedViews_.find(view.tag); it != renderedViews_.end()) {
56-
return it->second;
57-
}
58-
}
59-
6044
folly::dynamic element = folly::dynamic::object;
6145
element["type"] = view.componentName;
6246

6347
#if RN_DEBUG_STRING_CONVERTIBLE
64-
folly::dynamic props = nullptr;
65-
if (auto it = renderedViews_.find(view.tag); it != renderedViews_.end()) {
66-
props = mergeDynamicProps(
67-
it->second["props"],
68-
renderProps(view.props->getDebugProps()),
69-
NullValueStrategy::Override);
70-
} else {
71-
props = renderProps(view.props->getDebugProps());
72-
}
48+
folly::dynamic props = renderProps(view.props->getDebugProps());
7349
#else
7450
folly::dynamic props = folly::dynamic::object;
7551
#endif
@@ -96,8 +72,6 @@ folly::dynamic RenderOutput::renderView(
9672
#endif
9773
element["props"] = props;
9874

99-
renderedViews_.insert({view.tag, element});
100-
10175
return element;
10276
}
10377

private/react-native-fantom/tester/src/render/RenderOutput.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class RenderOutput {
3131

3232
folly::dynamic renderAttributedString(const Tag &selfTag, const AttributedString &string);
3333

34-
std::unordered_map<Tag, folly::dynamic> renderedViews_{};
35-
3634
// If true, the next call to render() will re-render the entire tree.
3735
std::unordered_set<SurfaceId> treesMutated_{};
3836
};

0 commit comments

Comments
 (0)