Skip to content

refactor(nuxt,schema): use oxc for onPrehydrate transform #32045

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

Merged
merged 15 commits into from
Jun 2, 2025

Conversation

TheAlexLichter
Copy link
Member

📚 Description

Simple refactor to replace esbuild with oxc for transforming onPrehydrate

@Copilot Copilot AI review requested due to automatic review settings May 8, 2025 18:34
@TheAlexLichter TheAlexLichter requested a review from danielroe as a code owner May 8, 2025 18:34
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

@Copilot Copilot AI left a 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 refactors the onPrehydrate transformation logic to replace esbuild with oxc, streamlining code transformation in both testing and build configurations. Key changes include updating test regex callbacks, adding oxc configuration to the schema, refactoring the transform utility to use synchronous oxc calls, and updating package dependencies accordingly.

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/basic.test.ts Revised selector callback parameter names and regex matching to align with the new transformation behavior
packages/schema/src/types/schema.ts Extended the configuration schema with a new oxc transform options field
packages/schema/src/config/oxc.ts Added a new configuration file for oxc using custom resolvers
packages/schema/src/config/index.ts Imported and spread the new oxc configuration
packages/schema/package.json Added dependency for oxc-transform
packages/nuxt/src/core/utils/parse.ts Replaced esbuild transform with a synchronous oxc transform and minify implementation
packages/nuxt/src/core/plugins/prehydrate.ts Updated prehydrate plugin to use the synchronous transformAndMinify with error handling
packages/nuxt/package.json Added dependencies for oxc-transform and oxc-minify
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

test/basic.test.ts:734

  • [nitpick] Consider using a more descriptive parameter name (e.g. 'element') in the forEach callback to improve code clarity.
* <script>document.querySelectorAll('[data-prehydrate-id*=":b3qlvSiBeH:"]').forEach(e=>{console.log(e.outerHTML)})</script>

Copy link

coderabbitai bot commented May 8, 2025

Warning

Rate limit exceeded

@danielroe has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 4 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 83844de and 1d34f30.

⛔ Files ignored due to path filters (2)
  • packages/nuxt/package.json is excluded by !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (2)
  • packages/nuxt/src/core/plugins/prehydrate.ts (3 hunks)
  • packages/nuxt/src/core/utils/parse.ts (1 hunks)

Walkthrough

This change transitions the code transformation and minification process from an asynchronous model using esbuild to a synchronous model using oxc-transform and oxc-minify. The prehydrate plugin is updated to synchronously transform and minify code blocks with per-call error handling, removing the previous asynchronous promise aggregation. A new synchronous transformAndMinify function replaces the former asynchronous transform function. The Nuxt configuration schema is extended to include oxc transformation options alongside existing esbuild options, with dynamic resolution of target environments and JSX settings. The build configuration marks oxc-transform as external. Tests are updated to reflect minor changes in variable naming and string literal formatting in example scripts. No public API signatures are changed.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/nuxt/src/core/utils/parse.ts (1)

11-12: Type utility definition for oxc options

Added a helpful type utility to ensure shape compatibility between provided options and expected types. The TODO comment suggests this might be reconsidered in the future, which is good for maintainability.

Consider removing the TODO comment if this type utility is actually necessary, or adding more context about why it might not be needed in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d79e146 and e170709.

⛔ Files ignored due to path filters (3)
  • packages/nuxt/package.json is excluded by !**/package.json
  • packages/schema/package.json is excluded by !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (6)
  • packages/nuxt/src/core/plugins/prehydrate.ts (2 hunks)
  • packages/nuxt/src/core/utils/parse.ts (1 hunks)
  • packages/schema/src/config/index.ts (2 hunks)
  • packages/schema/src/config/oxc.ts (1 hunks)
  • packages/schema/src/types/schema.ts (1 hunks)
  • test/basic.test.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/schema/src/config/oxc.ts (1)
packages/schema/src/utils/definition.ts (1)
  • defineResolvers (50-52)
packages/nuxt/src/core/plugins/prehydrate.ts (1)
packages/nuxt/src/core/utils/parse.ts (1)
  • transformAndMinify (14-23)
🔇 Additional comments (9)
packages/schema/src/config/index.ts (2)

9-9: Clean import addition for oxc.

This import correctly adds the oxc configuration module to be included in the schema, following the alphabetical ordering convention of the imports.


34-34: Proper integration of oxc configuration.

The oxc configuration is correctly spread into the default export, maintaining alphabetical ordering with the other configuration modules. This makes the oxc configuration available to the Nuxt application.

packages/schema/src/types/schema.ts (1)

1870-1874: Well-structured schema addition for oxc.

The oxc configuration schema is correctly added, following the same pattern as the existing esbuild configuration. The typing using import('oxc-transform').TransformOptions ensures proper type checking for oxc transformation options.

packages/schema/src/config/oxc.ts (1)

3-34: Appropriate configuration for oxc transformation options

This new configuration module adds support for oxc transformation options in Nuxt, with sensible defaults for JSX handling and target selection based on decorator support. The logic for resolving the target environment is well-structured, checking for explicit configuration before falling back to feature detection.

The configuration correctly uses the async resolver pattern to dynamically determine the ECMAScript target based on feature usage, defaulting to the most appropriate target for the application's needs.

packages/nuxt/src/core/plugins/prehydrate.ts (2)

5-5: Updated import to use the new synchronous transformation function

Correctly replaced the import of the async transform function with the synchronous transformAndMinify function to align with the new transformation approach.


31-41: Improved transformation and error handling with synchronous approach

The refactoring from asynchronous to synchronous transformation improves error handling and simplifies the code flow. The try-catch pattern provides immediate feedback when transformation fails, which is more robust than the previous approach.

The string cleanup is also more focused, only removing trailing semicolons rather than potentially removing trailing whitespace.

packages/nuxt/src/core/utils/parse.ts (2)

6-7: Updated imports for oxc-based transformation

Correctly removed esbuild dependencies and added imports for oxc-transform and oxc-minify, setting up the foundation for the new transformation approach.


14-23: Well-implemented synchronous transformation and minification function

The new transformAndMinify function effectively combines transformation and minification in a single synchronous operation, with proper merging of configuration options from the Nuxt instance. The comment about the synchronous nature being temporary due to a pending issue is informative for future maintainers.

The function returns a properly merged result object containing all necessary properties from both the transformation and minification processes.

test/basic.test.ts (1)

742-743: Correct regex updates for onPrehydrate scripts.

The new patterns accurately match the transformed inline scripts—using e instead of the old variable and correctly detecting the template literal other. LGTM.

TheAlexLichter and others added 4 commits May 8, 2025 20:39
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@TheAlexLichter TheAlexLichter changed the title refactor: use oxc for onprehydrate refactor: use oxc for onPrehydrate May 8, 2025
@TheAlexLichter TheAlexLichter changed the title refactor: use oxc for onPrehydrate refactor: use oxc for onPrehydrate transform May 8, 2025
@danielroe danielroe changed the title refactor: use oxc for onPrehydrate transform refactor(nuxt,schema): use oxc for onPrehydrate transform May 8, 2025
Copy link

pkg-pr-new bot commented May 8, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@32045

nuxt

npm i https://pkg.pr.new/nuxt@32045

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@32045

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@32045

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@32045

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@32045

commit: 1d34f30

Copy link

codspeed-hq bot commented May 8, 2025

CodSpeed Performance Report

Merging #32045 will not alter performance

Comparing feat/oxc-transform (1d34f30) with main (8f8db53)

Summary

✅ 10 untouched benchmarks

@danielroe danielroe added this to the 3.18 milestone May 8, 2025
@danielroe danielroe requested a review from cernymatej June 2, 2025 14:15
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

we might also be able to replace the usage of esbuild in packages/vite/src/plugins/analyze.ts

@danielroe danielroe merged commit aaa7545 into main Jun 2, 2025
47 checks passed
@danielroe danielroe deleted the feat/oxc-transform branch June 2, 2025 17:33
@github-actions github-actions bot mentioned this pull request Jun 2, 2025
@TheAlexLichter
Copy link
Member Author

@danielroe will check!

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

Successfully merging this pull request may close these issues.

2 participants