Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 28, 2025

Leverage Vite's native hook filter feature (https://vite.dev/guide/api-plugin.html#hook-filters) to optimize file filtering instead of performing redundant checks in handler functions.

Changes

@vitejs/plugin-rsc

  • Add @rolldown/pluginutils as a dependency
  • Add hook filters to transform hooks to filter by code content:
    • rsc:vite-client-raw-import: Filter by code containing __vite_rsc_raw_import__
    • rsc:inject-async-local-storage: Filter by code containing AsyncLocalStorage
    • rsc:rsc-css-self-accept: Filter by CSS files with ?direct query parameter
  • Add hook filter to resolveId hook:
    • rsc:react-server-dom-webpack-alias: Filter by id prefix @vitejs/plugin-rsc/vendor/react-server-dom/
  • Add hook filters to load hooks for virtual modules:
    • \0virtual:vite-rsc/assets-manifest
    • \0virtual:vite-rsc/client-references
  • Remove redundant conditional checks where hook filters handle the filtering

Example

Before:

transform: {
  order: 'post',
  handler(code) {
    if (code.includes('__vite_rsc_raw_import__')) {
      return code.replace('__vite_rsc_raw_import__', 'import')
    }
  },
}

After:

transform: {
  filter: { code: '__vite_rsc_raw_import__' },
  order: 'post',
  handler(code) {
    // Filter already applied by Vite
    return code.replace('__vite_rsc_raw_import__', 'import')
  },
}

Benefits

  • Performance improvement: Vite's native filtering is more efficient as it can filter files before calling the handler

  • Cleaner code: Removes redundant filtering logic where appropriate

  • Maintains backward compatibility: All existing tests pass

  • Fixes use plugin hook filter internally #861

Original prompt

This section details on the original issue you should resolve

<issue_title>use plugin hook filter internally</issue_title>
<issue_description>https://vite.dev/guide/rolldown.html#hook-filter-feature
https://vite.dev/guide/api-plugin.html#hook-filters</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 28, 2025 08:02
- plugin-react: Remove redundant filter check since hook filter handles it
- plugin-react-swc: Add hook filters for default file extensions (.tsx, .ts, .mts, .jsx, .mdx)
- Conditional filter application: Only use filters when parserConfig is not custom

Co-authored-by: hi-ogawa <4232207+hi-ogawa@users.noreply.github.com>
Change tsx? to (tsx|ts) to make it clearer that both extensions are matched

Co-authored-by: hi-ogawa <4232207+hi-ogawa@users.noreply.github.com>
Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

@copilot update only packages/plugin-rsc/src

Copilot AI changed the title [WIP] Implement plugin hook filter functionality internally Use plugin hook filters internally Oct 28, 2025
Copilot finished work on behalf of hi-ogawa October 28, 2025 08:08
Copilot AI requested a review from hi-ogawa October 28, 2025 08:08
- Revert changes to plugin-react and plugin-react-swc (per review feedback)
- Add @rolldown/pluginutils dependency to plugin-rsc
- Add hook filters to transform hooks: rsc:vite-client-raw-import, rsc:inject-async-local-storage, rsc:rsc-css-self-accept
- Add hook filters to resolveId hook: rsc:react-server-dom-webpack-alias
- Add hook filters to load hooks: virtual modules for assets-manifest and client-references
- Remove redundant conditional checks where hook filters now handle the filtering

Co-authored-by: hi-ogawa <4232207+hi-ogawa@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 28, 2025

@copilot update only packages/plugin-rsc/src

Updated to only apply hook filters to packages/plugin-rsc/src. Changes reverted for plugin-react and plugin-react-swc. Added filters to transform, resolveId, and load hooks in plugin-rsc. Commit: b1d3676

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • emotion.sh
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1194/chrome-linux/headless_shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AvoidUnnecessaryBeforeUnloadCheckSync,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate,AutoDeElevate,RenderDocument --enable-features=CDPScreenshotNewSurface --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --edge-skip-compat-layer-relaunch --enable-automation --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-jitIFz --remote-debugging-pipe --no-startup-window (dns block)
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1194/chrome-linux/headless_shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AvoidUnnecessaryBeforeUnloadCheckSync,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate,AutoDeElevate,RenderDocument --enable-features=CDPScreenshotNewSurface --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --edge-skip-compat-layer-relaunch --enable-automation --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-FI97U0 --remote-debugging-pipe --no-startup-window (dns block)
  • styled-components.com
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1194/chrome-linux/headless_shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AvoidUnnecessaryBeforeUnloadCheckSync,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate,AutoDeElevate,RenderDocument --enable-features=CDPScreenshotNewSurface --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --edge-skip-compat-layer-relaunch --enable-automation --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-jitIFz --remote-debugging-pipe --no-startup-window (dns block)
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1194/chrome-linux/headless_shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AvoidUnnecessaryBeforeUnloadCheckSync,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate,AutoDeElevate,RenderDocument --enable-features=CDPScreenshotNewSurface --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --edge-skip-compat-layer-relaunch --enable-automation --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-FI97U0 --remote-debugging-pipe --no-startup-window (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

The filter already matches CSS files, so this check is redundant

Co-authored-by: hi-ogawa <4232207+hi-ogawa@users.noreply.github.com>
Copilot AI changed the title Use plugin hook filters internally Use plugin hook filters internally in plugin-rsc Oct 28, 2025
Copilot finished work on behalf of hi-ogawa October 28, 2025 08:26
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.

use plugin hook filter internally

2 participants