aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-01-29 23:51:37 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-01-29 23:51:37 -0800
commit5922ba29acab512ff0aab51e64199d86f148c020 (patch)
treef56bfbbc2cb2c17d4a7abf6d84ad1cac390fc535
parent1de275325ee3067b3eb230ec644ed4765cb50c7d (diff)
downloadbun-5922ba29acab512ff0aab51e64199d86f148c020.tar.gz
bun-5922ba29acab512ff0aab51e64199d86f148c020.tar.zst
bun-5922ba29acab512ff0aab51e64199d86f148c020.zip
Bundle embedded fast refresh if using react and no fast refresh is found
-rw-r--r--src/bundler.zig25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/bundler.zig b/src/bundler.zig
index 8891b3eb6..211f368d3 100644
--- a/src/bundler.zig
+++ b/src/bundler.zig
@@ -831,12 +831,6 @@ pub const Bundler = struct {
var this = generator;
// Always inline the runtime into the bundle
try generator.appendBytes(&initial_header);
- if (Environment.isDebug) {
- try generator.appendBytes(runtime.Runtime.sourceContent());
- try generator.appendBytes("\n\n");
- } else {
- try generator.appendBytes(comptime runtime.Runtime.sourceContent() ++ "\n\n");
- }
if (bundler.log.level == .verbose) {
bundler.resolver.debug_logs = try DebugLogs.init(allocator);
@@ -926,8 +920,6 @@ pub const Bundler = struct {
this.bundler.options.jsx.supports_fast_refresh and
bundler.options.platform.isWebLike();
- Analytics.Features.fast_refresh = this.bundler.options.jsx.supports_fast_refresh;
-
if (bundler.router) |router| {
defer this.bundler.resetStore();
Analytics.Features.filesystem_router = true;
@@ -1004,6 +996,7 @@ pub const Bundler = struct {
.require,
)) |new_jsx_runtime| {
try this.enqueueItem(new_jsx_runtime);
+ Analytics.Features.jsx = true;
} else |_| {}
}
@@ -1017,6 +1010,8 @@ pub const Bundler = struct {
.require,
)) |refresh_runtime| {
try this.enqueueItem(refresh_runtime);
+ Analytics.Features.fast_refresh = true;
+
if (BundledModuleData.get(this, &refresh_runtime)) |mod| {
refresh_runtime_module_id = mod.module_id;
}
@@ -1026,6 +1021,18 @@ pub const Bundler = struct {
this.bundler.resetStore();
if (bundler.options.platform != .bun) Analytics.enqueue(Analytics.EventName.bundle_start);
+
+ const include_fast_refresh_in_bundle = Analytics.Features.jsx and
+ include_refresh_runtime and
+ !Analytics.Features.fast_refresh;
+
+ if (Environment.isDebug) {
+ try generator.appendBytes(runtime.Runtime.sourceContent(include_fast_refresh_in_bundle));
+ try generator.appendBytes("\n\n");
+ } else {
+ try generator.appendBytes(comptime runtime.Runtime.sourceContent(include_fast_refresh_in_bundle) ++ "\n\n");
+ }
+
this.pool.start(this) catch |err| {
Analytics.enqueue(Analytics.EventName.bundle_fail);
return err;
@@ -3081,7 +3088,7 @@ pub const Bundler = struct {
if (bundler.linker.any_needs_runtime) {
try bundler.output_files.append(
- options.OutputFile.initBuf(runtime.Runtime.sourceContent(), Linker.runtime_source_path, .js),
+ options.OutputFile.initBuf(runtime.Runtime.sourceContent(false), Linker.runtime_source_path, .js),
);
}