-
-
Notifications
You must be signed in to change notification settings - Fork 154
fix(kernel): add browser compatibility for timing utility #1663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Fix 'process is not defined' error when building with Vite - Add browser environment detection - Disable timing functionality in browser environments - Preserve Node.js timing functionality when process is available - Update function type signatures for better TypeScript compatibility This change allows @textlint/kernel to work in browser environments while maintaining full compatibility with Node.js environments. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes browser compatibility issues in the timing utility by adding environment detection to handle the absence of Node.js-specific APIs in browser environments.
- Adds browser environment detection using
typeof process === "undefined"
- Disables timing functionality in browsers while preserving Node.js behavior
- Updates function types to better reflect return value constraints
function time<T extends unknown[]>( | ||
key: string, | ||
fn: (...args: T) => void | Promise<void> | ||
): (...args: T) => void | Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function type has been narrowed from unknown
to void | Promise<void>
, but this could be a breaking change if callers expect return values from the wrapped functions. Consider preserving the original return type or using a generic type parameter.
function time<T extends unknown[]>( | |
key: string, | |
fn: (...args: T) => void | Promise<void> | |
): (...args: T) => void | Promise<void> { | |
function time<T extends unknown[], R>( | |
key: string, | |
fn: (...args: T) => R | |
): (...args: T) => R { |
Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
<!-- Release notes generated using configuration in .github/release.yml at master --> ## What's Changed ### Bug Fixes * fix(kernel): add browser compatibility for timing utility by @azu in #1663 ### Documentation * docs: add Claude Code setup instructions to MCP documentation by @azu in #1652 ### CI * chore(deps): update github/codeql-action action to v3.29.2 by @renovate[bot] in #1638 * chore(deps): update rossjrw/pr-preview-action action to v1.6.2 by @renovate[bot] in #1648 ### Dependency Updates * chore(deps): update dependency lerna to ^8.2.3 by @renovate[bot] in #1637 * chore(deps): update eslint to ^8.35.1 (patch) by @renovate[bot] in #1639 * chore(deps): update dependency globals to ^16.3.0 by @renovate[bot] in #1640 * chore(deps): update dependency @eslint/js to ^9.30.1 by @renovate[bot] in #1641 * fix(deps): update patch updates (patch) by @renovate[bot] in #1642 * chore(deps): update dependency @types/node to ^22.16.0 by @renovate[bot] in #1643 * fix(deps): update dependency @babel/core to ^7.28.0 by @renovate[bot] in #1644 * fix(deps): update babel monorepo to ^7.28.0 (minor) by @renovate[bot] in #1645 * fix(deps): update dependency zod to ^3.25.71 by @renovate[bot] in #1646 * fix(deps): update dependency @modelcontextprotocol/sdk to ^1.15.0 by @renovate[bot] in #1649 * fix(deps): update dependency zod to ^3.25.73 by @renovate[bot] in #1650 * fix(deps): update dependency zod to ^3.25.74 by @renovate[bot] in #1651 * fix(deps): update dependency zod to ^3.25.75 by @renovate[bot] in #1653 * chore(deps): update eslint to ^8.36.0 (patch) by @renovate[bot] in #1654 * fix(deps): update dependency zod to ^3.25.76 by @renovate[bot] in #1655 * chore(deps): update patch updates (patch) by @renovate[bot] in #1656 * chore(deps): update pnpm to v10.13.1 by @renovate[bot] in #1657 * fix(deps): update patch updates (patch) by @renovate[bot] in #1658 * chore(deps): update dependency @eslint/js to ^9.31.0 by @renovate[bot] in #1659 * chore(deps): update eslint to ^8.37.0 (minor) by @renovate[bot] in #1661 * chore(deps): update patch updates (patch) by @renovate[bot] in #1662 ### Other Changes * feat(mcp): add debug logging support for MCP server by @azu in #1636 **Full Changelog**: v15.2.0...v15.2.1 Co-authored-by: azu <azu@users.noreply.github.com>
Summary
process is not defined
error when building @textlint/kernel with ViteProblem
When building @textlint/kernel with Vite for browser environments, it throws
Uncaught ReferenceError: process is not defined
at runtime because the timing utility uses Node.js-specificprocess
object.Solution
typeof process === "undefined"
Test plan
🤖 Generated with Claude Code