Skip to content

Commit

Permalink
feat: RawPropsParser add useRawPropsJsiValue parameter (facebook#…
Browse files Browse the repository at this point in the history
…48231)

Summary:
In this PR we added a change that allows the RawPropsParser to construct its RawValues directly from the `jsi::Value` instead of converting it to `folly::dynamic` first.
We added a global feature flag to turn this on, however, for migrations it might be better to use this functionality as an opt-in on a component basis. With this change `ComponentDescriptors` can now create their RawPropsParser instance with the `useRawPropsJsiValue` flag to opt into it.

(Note: a few more changes are needed to make this accessible to the `ComponentDescriptor`, for which I opened [this follow up PR here](facebook#48232))

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[INTERNAL] [ADDED] - Added `useRawPropsJsiValue` parameter to `RawPropsParser` to opt into skipping folly::dynamic conversions during prop parsing.

Pull Request resolved: facebook#48231

Test Plan: Internal change / just make sure all tests are passing.

Reviewed By: NickGerleman

Differential Revision: D67139641

Pulled By: javache

fbshipit-source-id: 5b243edb8149870aad0a5a1b3998ee67997783d7
  • Loading branch information
hannojg authored and facebook-github-bot committed Dec 12, 2024
1 parent fd5bd3e commit d691952
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "RawPropsParser.h"

#include <react/debug/react_native_assert.h>
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/core/RawProps.h>

#include <glog/logging.h>
Expand Down Expand Up @@ -138,7 +137,7 @@ void RawPropsParser::preparse(const RawProps& rawProps) const noexcept {

auto value = object.getProperty(runtime, nameValue);
RawValue rawValue;
if (ReactNativeFeatureFlags::useRawPropsJsiValue()) {
if (useRawPropsJsiValue_) {
rawValue = RawValue(runtime, std::move(value));
} else {
rawValue = RawValue(jsi::dynamicFromValue(runtime, value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/RawProps.h>
Expand All @@ -26,8 +27,12 @@ class RawPropsParser final {
/*
* Default constructor.
* To be used by `ConcreteComponentDescriptor` only.
* If `useRawPropsJsiValue` is `true`, the parser will use `jsi::Value`
* directly for RawValues instead of converting them to `folly::dynamic`.
*/
RawPropsParser() = default;
RawPropsParser(
bool useRawPropsJsiValue = ReactNativeFeatureFlags::useRawPropsJsiValue())
: useRawPropsJsiValue_(useRawPropsJsiValue){};

/*
* To be used by `ConcreteComponentDescriptor` only.
Expand Down Expand Up @@ -56,6 +61,7 @@ class RawPropsParser final {
template <class ShadowNodeT>
friend class ConcreteComponentDescriptor;
friend class RawProps;
bool useRawPropsJsiValue_{false};

/*
* To be used by `RawProps` only.
Expand Down

0 comments on commit d691952

Please sign in to comment.