Skip to content

Conversation

@jaygarcia
Copy link
Contributor

I've had issues recently where I wanted debugging enabled upon launch of the application. This patch does just that.

From AppDelegate.m, the end developer can change one boolean on the RootView initialization.

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                withDebugEnabled:NO  // YES to enable debugging upon app launch
                                                      moduleName:@"UIExplorerApp"
                                                   launchOptions:launchOptions];

This Boolean cascades the RootView into the Bridge instantiation,

- (instancetype)initWithBundleURL:(NSURL *)bundleURL
                  withDebugEnabled:(BOOL)debugEnabled
                       moduleName:(NSString *)moduleName
                    launchOptions:(NSDictionary *)launchOptions
{
  RCTBridge *bridge = [[RCTBridge alloc] initWithBundlePath:bundleURL.absoluteString
                                           withDebugEnabled:debugEnabled
                                             moduleProvider:nil
                                              launchOptions:launchOptions];
  return [self initWithBridge:bridge
                   moduleName:moduleName];
}

where if YES, the executor class is configured as

self.executorClass = NSClassFromString(@"RCTWebSocketExecutor");

- (instancetype)initWithBundlePath:(NSString *)bundlePath
                  withDebugEnabled:(BOOL)debugEnabled
                    moduleProvider:(RCTBridgeModuleProviderBlock)block
                     launchOptions:(NSDictionary *)launchOptions
{
  if ((self = [super init])) {
    _bundlePath = bundlePath;
    _moduleProvider = block;
    _launchOptions = launchOptions;
#if DEBUG
    if (debugEnabled == YES) {
      self.executorClass = NSClassFromString(@"RCTWebSocketExecutor");
    }
#endif
    [self setUp];
    [self bindKeys];
  }

  return self;
}

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 8, 2015
@jaygarcia
Copy link
Contributor Author

For anyone at FB looking at this, what could I have done differently not to break the TravisCI build?
The log states:

"No output has been received in the last ... minutes, this potentially indicates a stalled build or something wrong with the build itself.
"```

@frantic
Copy link
Contributor

frantic commented Apr 9, 2015

What is the use-case for this? Make it easier to develop apps? If so, I'd suggest making "is debugger enabled" a setting that survives app restarts.

@ide
Copy link
Contributor

ide commented Apr 9, 2015

I submitted #652 a couple days ago which lets you specify the primary executor. So one thing you could do is create a bridge that defaults to the WebSocketExecutor:

[[RCTBridge alloc] initWithBundlePath:bundlePath
                   moduleProvider:block
                    launchOptions:launchOptions
                    executorBlock:^{
                 Class executorClass = NSClassFromString(@"RCTWebSocketExecutor");
                 if (!executorClass) {
                   RCTLogError(@"WebSocket debugger is not available. Did you forget to include RCTWebSocketExecutor?");
                   executorClass = [RCTContextExecutor class];
                 }
                 return [[executorClass alloc] init];
               }
               debugExecutorBlock:nil];

One thing that's nice about this approach is you can configure the WebSocketExecutor to support using the Chrome debugger while running the app on your phone.

@jaygarcia
Copy link
Contributor Author

@frantic , the use case is simple.
1 Run my app
2 Enable debug (key strokes, clicks, etc)
3 Critical condition hit, App shits the bed

This PR simply pulls step 2 out of the loop, which is really 2 steps.

Think about what life would be like if you were a web developer that had to reopen dev tools upon every page refresh. This PR is synonymous to keeping the web debug tools open & on the ready on every page refresh.

@ide,
This PR, in contrast to what you've posted, is end-developer friendly. It's configured so that developers can change a simple boolean without having to know what a WebSocketExecutor is =). They can also do it from a higher-level of exposure (AppDelegate.m) instead of diving into the core React framework.

@frantic
Copy link
Contributor

frantic commented Apr 9, 2015

@jaygarcia - how about the suggestion I made with remembering the last executor? I think this would be even more friendly and you don't have to remember to change your code before shipping to the appstore

@jaygarcia
Copy link
Contributor Author

@frantic, that is probably the best idea/pattern, but we'd still need the #if DEBUG/#endif around it. That way when it is shipped to the app store, and the developer forgets to turn it off, it will never be enabled.

Want me to push that into the Info.plist? That's a trivial action. =)

@jaygarcia
Copy link
Contributor Author

@frantic gentle nudge. =)

@jaygarcia
Copy link
Contributor Author

I imagine that this code is very outdated, given lots of changes since this PR nearly two weeks ago. I remain interested in making this happen, even if it requires refactoring on my part. =)

@nicklockwood
Copy link
Contributor

One major change that landed recently is that the executor and debug mode, etc. are all controlled via the bridge now, rather than the root view.

We're going to be doing some more refactoring of this soon, so I'd probably hold off on trying to update this for now.

As @frantic suggests, the eventual solution will probably be for the app to simply remember it's last state, so if you set debug mode in the dev menu and then do a cold start, it should still be in debug mode.

@brentvatne
Copy link
Collaborator

As @frantic suggests, the eventual solution will probably be for the app to simply remember it's last state, so if you set debug mode in the dev menu and then do a cold start, it should still be in debug mode.

It looks like you folks got around to doing this, works great, so I will close this

@brentvatne brentvatne closed this Jun 1, 2015
ayushjainrksh referenced this pull request in MLH-Fellowship/react-native Jul 2, 2020
* Reduce versions to build on Netlify

* Remove imagebackground and safeareaview from 0.5

* Keep 0.46 and 0.50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants