Unverified Commit 80384ac1 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

Revert "feat(turbopack): Add an env var to debug-print the fast refresh…

Revert "feat(turbopack): Add an env var to debug-print the fast refresh invalidation reason (#72296)" (#72421)

Not sure why this is happening, but @kdy1 bisected this commit to a null pointer assertion error in napi: https://vercel.slack.com/archives/C03EWR7LGEN/p1730901839682439?thread_ts=1730899709.760659&cid=C03EWR7LGEN

Reverting until I can repro and root cause.

Closes PACK-3402
parent edb19db5
...@@ -893,10 +893,6 @@ pub fn project_hmr_identifiers_subscribe( ...@@ -893,10 +893,6 @@ pub fn project_hmr_identifiers_subscribe(
) )
} }
struct NapiUpdateInfoOpts {
include_reasons: bool,
}
enum UpdateMessage { enum UpdateMessage {
Start, Start,
End(UpdateInfo), End(UpdateInfo),
...@@ -908,8 +904,8 @@ struct NapiUpdateMessage { ...@@ -908,8 +904,8 @@ struct NapiUpdateMessage {
pub value: Option<NapiUpdateInfo>, pub value: Option<NapiUpdateInfo>,
} }
impl NapiUpdateMessage { impl From<UpdateMessage> for NapiUpdateMessage {
fn from_update_message(update_message: UpdateMessage, opts: NapiUpdateInfoOpts) -> Self { fn from(update_message: UpdateMessage) -> Self {
match update_message { match update_message {
UpdateMessage::Start => NapiUpdateMessage { UpdateMessage::Start => NapiUpdateMessage {
update_type: "start".to_string(), update_type: "start".to_string(),
...@@ -917,7 +913,7 @@ impl NapiUpdateMessage { ...@@ -917,7 +913,7 @@ impl NapiUpdateMessage {
}, },
UpdateMessage::End(info) => NapiUpdateMessage { UpdateMessage::End(info) => NapiUpdateMessage {
update_type: "end".to_string(), update_type: "end".to_string(),
value: Some(NapiUpdateInfo::from_update_info(info, opts)), value: Some(info.into()),
}, },
} }
} }
...@@ -927,27 +923,13 @@ impl NapiUpdateMessage { ...@@ -927,27 +923,13 @@ impl NapiUpdateMessage {
struct NapiUpdateInfo { struct NapiUpdateInfo {
pub duration: u32, pub duration: u32,
pub tasks: u32, pub tasks: u32,
/// A human-readable list of invalidation reasons (typically changed file paths) if known. Will
/// be `None` if [`NapiUpdateInfoOpts::include_reasons`] is `false` or if no reason was
/// specified (not every invalidation includes a reason).
pub reasons: Option<String>,
} }
impl NapiUpdateInfo { impl From<UpdateInfo> for NapiUpdateInfo {
fn from_update_info(update_info: UpdateInfo, opts: NapiUpdateInfoOpts) -> Self { fn from(update_info: UpdateInfo) -> Self {
Self { Self {
// u32::MAX in milliseconds is 49.71 days duration: update_info.duration.as_millis() as u32,
duration: update_info tasks: update_info.tasks as u32,
.duration
.as_millis()
.try_into()
.expect("update duration in milliseconds should not exceed u32::MAX"),
tasks: update_info
.tasks
.try_into()
.expect("number of tasks should not exceed u32::MAX"),
reasons: (opts.include_reasons && !update_info.reasons.is_empty())
.then(|| update_info.reasons.to_string()),
} }
} }
} }
...@@ -967,17 +949,12 @@ impl NapiUpdateInfo { ...@@ -967,17 +949,12 @@ impl NapiUpdateInfo {
pub fn project_update_info_subscribe( pub fn project_update_info_subscribe(
#[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>, #[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>,
aggregation_ms: u32, aggregation_ms: u32,
include_reasons: bool,
func: JsFunction, func: JsFunction,
) -> napi::Result<()> { ) -> napi::Result<()> {
let func: ThreadsafeFunction<UpdateMessage> = let func: ThreadsafeFunction<UpdateMessage> = func.create_threadsafe_function(0, |ctx| {
func.create_threadsafe_function(0, move |ctx| { let message = ctx.value;
let message = ctx.value; Ok(vec![NapiUpdateMessage::from(message)])
Ok(vec![NapiUpdateMessage::from_update_message( })?;
message,
NapiUpdateInfoOpts { include_reasons },
)])
})?;
let turbo_tasks = project.turbo_tasks.clone(); let turbo_tasks = project.turbo_tasks.clone();
tokio::spawn(async move { tokio::spawn(async move {
loop { loop {
......
...@@ -246,12 +246,6 @@ export interface NapiUpdateMessage { ...@@ -246,12 +246,6 @@ export interface NapiUpdateMessage {
export interface NapiUpdateInfo { export interface NapiUpdateInfo {
duration: number duration: number
tasks: number tasks: number
/**
* A human-readable list of invalidation reasons (typically changed file paths) if known. Will
* be `None` if [`NapiUpdateInfoOpts::include_reasons`] is `false` or if no reason was
* specified (not every invalidation includes a reason).
*/
reasons?: string
} }
/** /**
* Subscribes to lifecycle events of the compilation. * Subscribes to lifecycle events of the compilation.
...@@ -269,7 +263,6 @@ export interface NapiUpdateInfo { ...@@ -269,7 +263,6 @@ export interface NapiUpdateInfo {
export function projectUpdateInfoSubscribe( export function projectUpdateInfoSubscribe(
project: { __napiType: 'Project' }, project: { __napiType: 'Project' },
aggregationMs: number, aggregationMs: number,
includeReasons: boolean,
func: (...args: any[]) => any func: (...args: any[]) => any
): void ): void
export interface StackFrame { export interface StackFrame {
......
...@@ -40,7 +40,6 @@ import type { ...@@ -40,7 +40,6 @@ import type {
TurbopackResult, TurbopackResult,
TurbopackStackFrame, TurbopackStackFrame,
Update, Update,
UpdateInfoOpts,
UpdateMessage, UpdateMessage,
WrittenEndpoint, WrittenEndpoint,
} from './types' } from './types'
...@@ -762,12 +761,11 @@ function bindingToApi( ...@@ -762,12 +761,11 @@ function bindingToApi(
return binding.projectGetSourceMap(this._nativeProject, filePath) return binding.projectGetSourceMap(this._nativeProject, filePath)
} }
updateInfoSubscribe(opts: UpdateInfoOpts) { updateInfoSubscribe(aggregationMs: number) {
return subscribe<TurbopackResult<UpdateMessage>>(true, async (callback) => return subscribe<TurbopackResult<UpdateMessage>>(true, async (callback) =>
binding.projectUpdateInfoSubscribe( binding.projectUpdateInfoSubscribe(
this._nativeProject, this._nativeProject,
opts.aggregationMs, aggregationMs,
opts.includeReasons ?? false,
callback callback
) )
) )
......
...@@ -4,11 +4,8 @@ import type { ...@@ -4,11 +4,8 @@ import type {
ExternalObject, ExternalObject,
NextTurboTasks, NextTurboTasks,
RefCell, RefCell,
NapiUpdateInfo as UpdateInfo,
} from './generated-native' } from './generated-native'
export type { NapiUpdateInfo as UpdateInfo } from './generated-native'
export interface Binding { export interface Binding {
isWasm: boolean isWasm: boolean
turbo: { turbo: {
...@@ -198,9 +195,9 @@ export type UpdateMessage = ...@@ -198,9 +195,9 @@ export type UpdateMessage =
value: UpdateInfo value: UpdateInfo
} }
export interface UpdateInfoOpts { export interface UpdateInfo {
aggregationMs: number duration: number
includeReasons?: boolean tasks: number
} }
export interface Project { export interface Project {
...@@ -223,7 +220,7 @@ export interface Project { ...@@ -223,7 +220,7 @@ export interface Project {
): Promise<TurbopackStackFrame | null> ): Promise<TurbopackStackFrame | null>
updateInfoSubscribe( updateInfoSubscribe(
opts?: UpdateInfoOpts aggregationMs: number
): AsyncIterableIterator<TurbopackResult<UpdateMessage>> ): AsyncIterableIterator<TurbopackResult<UpdateMessage>>
shutdown(): Promise<void> shutdown(): Promise<void>
......
...@@ -93,7 +93,6 @@ const isTestMode = !!( ...@@ -93,7 +93,6 @@ const isTestMode = !!(
process.env.__NEXT_TEST_MODE || process.env.__NEXT_TEST_MODE ||
process.env.DEBUG process.env.DEBUG
) )
const includeUpdateReasons = !!process.env.NEXT_TURBOPACK_INCLUDE_UPDATE_REASONS
const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random()) const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random())
...@@ -1019,21 +1018,13 @@ export async function createHotReloaderTurbopack( ...@@ -1019,21 +1018,13 @@ export async function createHotReloaderTurbopack(
}) })
async function handleProjectUpdates() { async function handleProjectUpdates() {
for await (const updateMessage of project.updateInfoSubscribe({ for await (const updateMessage of project.updateInfoSubscribe(30)) {
aggregationMs: 30,
includeReasons: includeUpdateReasons,
})) {
switch (updateMessage.updateType) { switch (updateMessage.updateType) {
case 'start': { case 'start': {
hotReloader.send({ action: HMR_ACTIONS_SENT_TO_BROWSER.BUILDING }) hotReloader.send({ action: HMR_ACTIONS_SENT_TO_BROWSER.BUILDING })
break break
} }
case 'end': { case 'end': {
if (updateMessage.value.reasons) {
// debug: only populated when `process.env.NEXT_TURBOPACK_INCLUDE_UPDATE_REASONS` is set
// and a reason was supplied when the invalidation happened (not always true)
console.log('[Update Reasons]', updateMessage.value.reasons)
}
sendEnqueuedMessages() sendEnqueuedMessages()
function addErrors( function addErrors(
......
...@@ -231,7 +231,7 @@ describe('next.rs api', () => { ...@@ -231,7 +231,7 @@ describe('next.rs api', () => {
browserslistQuery: 'last 2 versions', browserslistQuery: 'last 2 versions',
}) })
projectUpdateSubscription = filterMapAsyncIterator( projectUpdateSubscription = filterMapAsyncIterator(
project.updateInfoSubscribe({ aggregationMs: 1000 }), project.updateInfoSubscribe(1000),
(update) => (update.updateType === 'end' ? update.value : undefined) (update) => (update.updateType === 'end' ? update.value : undefined)
) )
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment