Skip to content

Conversation

@xusd320
Copy link

@xusd320 xusd320 commented Dec 31, 2025

This pull request updates how worker thread data is accessed in the Turbopack codebase. The main change is to consistently use Node.js's worker_threads.workerData and worker_threads.threadId APIs instead of relying on a custom self.workerData object. This improves reliability and aligns the code with standard Node.js worker thread practices.

Worker thread data handling updates:

  • Replaced usage of self.workerData with direct imports from worker_threads (workerData, threadId) in postcss.ts, webpack-loaders.ts, and evaluate.ts to standardize worker data access and remove custom global augmentation. [1] [2] [3]

  • Updated worker entrypoint checks in both postcss.ts and webpack-loaders.ts to use workerData instead of self.workerData for determining if the worker should run, simplifying the worker initialization logic. [1] [2]

  • Refactored the Self type in evaluate.ts to remove the workerData property, since all worker data is now accessed via the worker_threads module.

@gemini-code-assist
Copy link

Summary of Changes

Hello @xusd320, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors how worker thread data is accessed and managed within the Turbopack codebase. The primary goal is to enhance reliability and align with standard Node.js practices by transitioning from a custom self.workerData mechanism to the native worker_threads module for retrieving worker-specific information and thread IDs. This change streamlines worker initialization and data access patterns across several key files, improving maintainability and consistency.

Highlights

  • Standardized Worker Thread Data Access: Replaced custom self.workerData usage with direct imports of workerData and threadId from Node.js's worker_threads module in postcss.ts, webpack-loaders.ts, and evaluate.ts to ensure consistent and standard data handling.
  • Simplified Worker Entrypoint Checks: Updated worker initialization logic in postcss.ts and webpack-loaders.ts to directly use workerData for determining if a worker should run, removing the previous reliance on self.workerData and simplifying the conditional checks.
  • Refactored Self Type Definition: Modified the Self type in evaluate.ts to remove the workerData property, as all worker-specific data is now accessed directly via the worker_threads module, aligning the type definition with the new implementation.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@xusd320 xusd320 merged commit d664fc3 into utoo Dec 31, 2025
9 of 16 checks passed
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a good refactoring that standardizes worker thread data access by using Node.js's worker_threads module instead of a custom self.workerData object. The changes correctly replace self.workerData with workerData and self.workerData.workerId with threadId. My main feedback is to re-introduce type-safety for workerData in evaluate.ts, which was lost during the refactoring. This will improve maintainability and code clarity.

Comment on lines +9 to +15
import { workerData, threadId as workerId } from 'worker_threads'

export type Self = DedicatedWorkerGlobalScope & {
workerData: {
workerId: number
cwd: string
binding: Binding
}
}
export type Self = DedicatedWorkerGlobalScope

export declare const self: Self
// @ts-ignore
const { workerId } = self.workerData

let binding: Binding = self.workerData.binding
let binding: Binding = workerData.binding

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While moving to the standard worker_threads API is a great improvement, this change loses the type definition for workerData that was previously part of the Self type. To maintain type safety and code clarity, it's a good practice to define an interface for workerData and apply it. This also makes it clear what properties are expected, such as cwd which was present in the old type.

import { workerData as untypedWorkerData, threadId as workerId } from 'worker_threads'

interface TurbopackWorkerData {
  binding: Binding
  cwd: string
}

const workerData = untypedWorkerData as TurbopackWorkerData

export type Self = DedicatedWorkerGlobalScope

export declare const self: Self

let binding: Binding = workerData.binding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants