Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions NativeScript/runtime/DevFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ namespace tns {
// Controlled by package.json setting: "logScriptLoading": true|false
bool IsScriptLoadingLogEnabled();

// HTTP module loader flags
//
// Returns true when speculative HTTP module prefetching (the dep-graph BFS
// kicked off after each successful HttpFetchText) should be enabled. Default
// OFF so cold-boot behaviour is unchanged for users who have not opted in.
// Controlled by package.json / nativescript.config: "httpModulePrefetch": true|false
bool IsHttpModulePrefetchEnabled();

// Returns true when one log line should be emitted per HTTP fetch URL.
// Default OFF because the volume is high (one line per fetch, hundreds per
// cold boot, hundreds per HMR refresh). Opt in via package.json /
// nativescript.config: "httpFetchUrlLog": true|false
bool IsHttpFetchUrlLogEnabled();

// Security config

// In debug mode (RuntimeConfig.IsDebug): always returns true.
Expand Down
63 changes: 63 additions & 0 deletions NativeScript/runtime/DevFlags.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import <Foundation/Foundation.h>

#include "DevFlags.h"
#include "Helpers.h"
#include "Runtime.h"
#include "RuntimeConfig.h"
#include <vector>
Expand All @@ -13,6 +14,68 @@ bool IsScriptLoadingLogEnabled() {
return value ? [value boolValue] : false;
}

// HTTP module loader flags

// Reads `httpModulePrefetch` from app config (default: DISABLED).
//
// Apps that want to opt in for testing can set:
//
// // nativescript.config.ts
// export default {
// httpModulePrefetch: true,
// } as NativeScriptConfig;
//
// Returning false here short-circuits both the cache lookup and the prefetch
// wave in HttpFetchText, restoring the pre-prefetcher behavior bit-for-bit.
bool IsHttpModulePrefetchEnabled() {
static std::once_flag s_initFlag;
static bool s_enabled = false;
std::call_once(s_initFlag, []() {
@autoreleasepool {
id value = Runtime::GetAppConfigValue("httpModulePrefetch");
if (value && [value respondsToSelector:@selector(boolValue)]) {
s_enabled = [value boolValue];
}
}
// Startup banner. Gated on the logScriptLoading flag so it stays silent
// by default — flip the flag in nativescript.config.ts when diagnosing
// why prefetch is or isn't engaging.
//
// [http-loader] prefetch=disabled ← expected default
// [http-loader] prefetch=enabled ← only if config opt-in
if (IsScriptLoadingLogEnabled()) {
Log(@"[http-loader] prefetch=%s shared-session=on hmr-kickstart=on",
s_enabled ? "enabled" : "disabled");
}
});
return s_enabled;
}

// Default OFF because the volume is high (one line per fetch, hundreds per
// cold boot, hundreds per HMR refresh). Opt in via `nativescript.config.ts`:
//
// export default {
// httpFetchUrlLog: true, // turn on for diagnosis only
// …
// };
bool IsHttpFetchUrlLogEnabled() {
static std::once_flag s_initFlag;
static bool s_enabled = false;
std::call_once(s_initFlag, []() {
@autoreleasepool {
id value = Runtime::GetAppConfigValue("httpFetchUrlLog");
if (value && [value respondsToSelector:@selector(boolValue)]) {
s_enabled = [value boolValue];
}
}
if (IsScriptLoadingLogEnabled()) {
Log(@"[http-loader] fetch-url-log=%s",
s_enabled ? "enabled" : "disabled");
}
});
return s_enabled;
}

// Security config

static std::once_flag s_securityConfigInitFlag;
Expand Down
321 changes: 312 additions & 9 deletions NativeScript/runtime/HMRSupport.h

Large diffs are not rendered by default.

Loading
Loading