Skip to content
Open
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
78 changes: 51 additions & 27 deletions src/runtime/bake/DevServer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2527,13 +2527,15 @@ impl DevServer {
// here is the *only* one in this fn — no other `&`/`&mut`
// derived from `*this` is live across it (`router_type` /
// `keys` / `route` were all consumed in earlier arms).
let js = unsafe {
let (js, complete) = unsafe {
(*this).generate_css_js_array(
&(&(*this).route_bundles)[route_bundle_index.get() as usize],
)
}?;
framework_bundle.cached_css_file_array =
jsc::StrongOptional::create(js, global);
if complete {
framework_bundle.cached_css_file_array =
Comment thread
robobun marked this conversation as resolved.
Resolved
jsc::StrongOptional::create(js, global);
}
break 'arr js;
}
},
Expand Down Expand Up @@ -3551,7 +3553,8 @@ impl DevServer {
Ok(client_bundle)
}

fn generate_css_js_array(&mut self, route_bundle: &RouteBundle) -> JsResult<JSValue> {
/// The `bool` is false when the list is incomplete and must not be cached.
fn generate_css_js_array(&mut self, route_bundle: &RouteBundle) -> JsResult<(JSValue, bool)> {
debug_assert!(matches!(
route_bundle.data,
route_bundle::Data::Framework(_)
Expand All @@ -3568,6 +3571,19 @@ impl DevServer {
self.client_graph.reset();
self.trace_all_route_imports(route_bundle, &mut gts, TraceImportGoal::FindCss)?;

// A stylesheet whose build failed is not a CSS root, and its fix marks no route.
let mut complete = true;
{
let files = self.client_graph.bundled_files.values();
let mut visited = gts.client_bits.iterator::<true, true>();
while let Some(i) = visited.next() {
if files[i].failed {
complete = false;
break;
}
}
}

let names: &[u64] = &self.client_graph.current_css_files;
let global = self.vm().global();
let arr = jsc::JSArray::create_empty(global, names.len())?;
Expand Down Expand Up @@ -3595,7 +3611,7 @@ impl DevServer {
bun_string_jsc::create_utf8_for_js(global, path)?,
)?;
}
Ok(arr)
Ok((arr, complete))
}

fn trace_all_route_imports(
Expand Down Expand Up @@ -4339,6 +4355,32 @@ pub(super) fn finalize_bundle(

let mut has_route_bits_set = false;

// Unlike the payload below, this must not depend on anybody listening for hot updates.
let mut framework_route_bits = DynamicBitSet::init_empty(dev.route_bundles.len())?;
for request in &dev.incremental_result.framework_routes_affected {
let route = dev.router.route_ptr(request.route_index());
if let Some(id) = route.bundle {
framework_route_bits.set(id.get() as usize);
}
if request.should_recurse_when_visiting() {
mark_all_route_children(
&dev.router,
&mut [&mut framework_route_bits],
request.route_index(),
);
}
}
{
let mut it = framework_route_bits.iterator::<true, true>();
while let Some(bundled_route_index) = it.next() {
dev.route_bundles[bundled_route_index]
.data
.framework_mut()
.cached_css_file_array
.clear_without_deallocation();
Comment thread
robobun marked this conversation as resolved.
Resolved
}
}

let mut hot_update_payload: Vec<u8> = Vec::with_capacity(65536);
hot_update_payload.push(MessageId::HotUpdate.char());

Expand Down Expand Up @@ -4369,15 +4411,7 @@ pub(super) fn finalize_bundle(
{
has_route_bits_set = true;

for request in &dev.incremental_result.framework_routes_affected {
let route = dev.router.route_ptr(request.route_index());
if let Some(id) = route.bundle {
route_bits.set(id.get() as usize);
}
if request.should_recurse_when_visiting() {
mark_all_route_children(&dev.router, &mut [&mut route_bits], request.route_index());
}
}
framework_route_bits.copy_into(&mut route_bits);
for route_bundle_index in &dev.incremental_result.html_routes_hard_affected {
route_bits.set(route_bundle_index.get() as usize);
route_bits_client.set(route_bundle_index.get() as usize);
Expand Down Expand Up @@ -4452,7 +4486,7 @@ pub(super) fn finalize_bundle(
}

// `route_bits` will have all of the routes that were modified.
if has_route_bits_set && (will_hear_hot_update || dev.incremental_result.had_adjusted_edges) {
if has_route_bits_set && will_hear_hot_update {
// Note: copy out before the loop so the `&mut RouteBundle` borrow
// below doesn't overlap a `&dev.incremental_result` read.
let had_adjusted_edges = dev.incremental_result.had_adjusted_edges;
Expand All @@ -4465,24 +4499,14 @@ pub(super) fn finalize_bundle(
let route_bundle: *mut RouteBundle = dev.route_bundle_ptr(route_bundle::Index::init(
u32::try_from(i).expect("int cast"),
));
if had_adjusted_edges {
// SAFETY: `route_bundle` points into `dev.route_bundles` (not
// resized in this loop); the exclusive borrow is scoped to this match.
match unsafe { &mut (*route_bundle).data } {
route_bundle::Data::Framework(fw_bundle) => {
fw_bundle.cached_css_file_array.clear_without_deallocation()
}
route_bundle::Data::Html(html) => html.cached_response = None,
}
}
// SAFETY: statement-scoped read; no `&mut` into `*route_bundle` is live.
if unsafe { (*route_bundle).active_viewers } == 0 || !will_hear_hot_update {
if unsafe { (*route_bundle).active_viewers } == 0 {
continue;
}
w_int!(i32, i32::try_from(i).expect("int cast"));

// If no edges were changed, then it is impossible to
// change the list of CSS files.
// change the set of CSS files.
if had_adjusted_edges {
ctx.gts.clear();
dev.client_graph.current_css_files.clear();
Expand Down
13 changes: 12 additions & 1 deletion src/runtime/bake/dev_server/route_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum State {

pub struct Framework {
pub(crate) route_index: framework_router::RouteIndex,
/// Only depends on the router, which does not change after startup.
pub(crate) cached_module_list: jsc::StrongOptional,
pub(crate) cached_client_bundle_url: jsc::StrongOptional,
pub(crate) cached_css_file_array: jsc::StrongOptional,
Expand Down Expand Up @@ -57,6 +58,12 @@ impl Data {
Data::Html(_) => unreachable!("expected .framework"),
}
}
pub(crate) fn framework_mut(&mut self) -> &mut Framework {
match self {
Data::Framework(f) => f,
Data::Html(_) => unreachable!("expected .framework"),
}
}
/// `Html` payload accessor (asserts active variant).
pub(crate) fn html(&self) -> &Html {
match self {
Expand Down Expand Up @@ -90,7 +97,11 @@ impl RouteBundle {
u32::from_ne_bytes(buf)
};
match &mut self.data {
Data::Framework(fw) => fw.cached_client_bundle_url.clear_without_deallocation(),
Data::Framework(fw) => {
fw.cached_client_bundle_url.clear_without_deallocation();
// `meta.styles` includes the CSS imported by client components.
fw.cached_css_file_array.clear_without_deallocation();
}
Data::Html(html) => html.cached_response = None,
}
}
Expand Down
Loading
Loading