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

Add ReactMarkerConstants.CONTENT_APPEARED support on Android #43620

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,8 @@ public void run() {

if (mShouldLogContentAppeared) {
mShouldLogContentAppeared = false;

if (mJSModuleName != null) {
ReactMarker.logMarker(ReactMarkerConstants.CONTENT_APPEARED, mJSModuleName, mRootViewTag);
}
String jsModuleName = getJSModuleName();
Copy link
Contributor

@rubennorte rubennorte Jun 11, 2024

Choose a reason for hiding this comment

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

Sorry for the very late review.

This feels risky because getJSModuleName asserts, which could introduce new crashes. I understand you changed this so we can override it, but we should either try/catch here or create a new method that doesn't assert and use it instead (and maybe use it to access instead of mJSModuleName everywhere in this file).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for having the comment. after this pr, mJSModuleName is only access from the getter.

i was thinking that assertion for getJSModuleName() could help us catching the issue as early as possible. if we believe that getJSModuleName() should always be non-nullable. otherwise, if getJSModuleName() could be nullable, i don't really like try-catch or introducing new method, having an alternative e6a722d change, please let me know which makes more sense to you.

Copy link
Contributor

Choose a reason for hiding this comment

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

could help us catching the issue as early as possible

I agree with this when adding a new API, but modifying an API to introduce this, if the previous behavior wasn't crashing, is not ideal.

Given that we already have some callers in the critical path (e.g.: startSurface) that were using the getter with the assert, I think it might be safe to continue using it, even for this use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alright, if that's more toward existing call paths, having try-catch makes more sense than introducing new method.
i've updated the pr to have try-catch. please check again if that makes sense to you. thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I think you misunderstood. I meant that you can keep the implementation you had replacing all usages with getJSModuleName with the assert because we were already calling that when loading a new surface. If there were cases where it was defined, that should've thrown an error in those cases too. So replacing all with getJSModuleName and removing the null checks should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry i was easily mistaken. i've reset the branch to the previous version. hopes that is correct.

ReactMarker.logMarker(ReactMarkerConstants.CONTENT_APPEARED, jsModuleName, mRootViewTag);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ public DevSupportManager getDevSupportManager() {
public ReactSurface createSurface(
Context context, String moduleName, @Nullable Bundle initialProps) {
ReactSurfaceImpl surface = new ReactSurfaceImpl(context, moduleName, initialProps);
surface.attachView(new ReactSurfaceView(context, surface));
ReactSurfaceView surfaceView = new ReactSurfaceView(context, surface);
surfaceView.setShouldLogContentAppeared(true);
surface.attachView(surfaceView);
surface.attach(this);
return surface;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public class ReactSurfaceView(context: Context?, private val surface: ReactSurfa
// This surface view is always on Fabric.
@UIManagerType override fun getUIManagerType(): Int = UIManagerType.FABRIC

override fun getJSModuleName(): String = surface.moduleName

override fun dispatchJSTouchEvent(event: MotionEvent) {
val eventDispatcher = surface.eventDispatcher
if (eventDispatcher != null) {
Expand Down
Loading