Skip to content

[FIX] Fix Vite plugin to handle intra-plugin sibling imports#1809

Merged
hari-kuriakose merged 2 commits intomainfrom
fix/vite-optional-plugin-imports
Feb 27, 2026
Merged

[FIX] Fix Vite plugin to handle intra-plugin sibling imports#1809
hari-kuriakose merged 2 commits intomainfrom
fix/vite-optional-plugin-imports

Conversation

@vishnuszipstack
Copy link
Contributor

@vishnuszipstack vishnuszipstack commented Feb 27, 2026

What

  • Fix the optionalPluginImports Vite plugin to handle intra-plugin sibling imports (e.g. ./TrialMessage from within plugins/login-form/)

Why

  • The on-prem frontend Docker build fails with Could not resolve "./TrialMessage" from "src/plugins/login-form/LoginForm.jsx"
  • The on-prem build workflow copies cloud plugins then explicitly deletes cloud-only files like TrialMessage.jsx and SwitchRegion.jsx
  • LoginForm.jsx uses await import("./TrialMessage") inside a try/catch — Rollup resolves this at build time, and the Vite plugin was supposed to intercept missing files and return an empty module
  • But the plugin's filter (source.includes("plugins/")) only matched imports with "plugins/" in the source path (e.g. ../plugins/foo), missing sibling imports like "./TrialMessage" that don't contain "plugins/" in the source string

How

  • Changed the filter to check the resolved path instead of the source string
  • The resolved path for "./TrialMessage" imported from plugins/login-form/LoginForm.jsx is /path/to/plugins/login-form/TrialMessage — which correctly contains "/plugins/"
  • This covers both cross-plugin imports (e.g. ../plugins/foo) and intra-plugin sibling imports

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

  • No. The plugin only returns an empty module when the target file does not exist on disk. For all existing files, it returns null (normal Rollup resolution). The change only widens the filter to catch more missing-file cases within the plugins directory, so existing builds with all files present are unaffected.
  • Verified: build succeeds with all files present (no regression), build succeeds with files removed (fix works), build fails without the fix when files are removed (reproduces the on-prem error).

Database Migrations

  • None

Env Config

  • None

Relevant Docs

  • N/A

Related Issues or PRs

Dependencies Versions

  • None

The optionalPluginImports Vite plugin previously only intercepted
imports where the source path contained "plugins/" (e.g.
"../plugins/foo"). This missed sibling relative imports within a
plugin directory (e.g. "./TrialMessage" from plugins/login-form/),
causing the on-prem frontend build to fail when cloud-only files
like TrialMessage.jsx are removed from the build context.

Fix: check the resolved path instead of the source string so both
cross-plugin and intra-plugin imports are handled correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

Summary by CodeRabbit

  • Chores
    • Optimized build configuration logic for improved plugin import resolution.

Walkthrough

Modified the conditional logic in optionalPluginImports within Vite configuration to separate and refine plugin directory detection. The initial guard now only checks for the importer's presence, while a new guard resolves relative imports and verifies the resolved path contains "/plugins/".

Changes

Cohort / File(s) Summary
Vite Configuration
frontend/vite.config.js
Refactored optionalPluginImports guard logic to remove source string checking and add resolved path validation for plugin directory inclusion, narrowing applicability to imports that resolve under plugins paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: resolving Vite plugin handling of intra-plugin sibling imports, which matches the primary change in the changeset.
Description check ✅ Passed The description is comprehensive and complete, covering all required template sections: What, Why, How, impact analysis, and addressing the admin-required safety section with detailed testing verification.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/vite-optional-plugin-imports

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@frontend/vite.config.js`:
- Line 29: The check using resolved.includes("/plugins/") is platform-dependent
and fails on Windows; normalize the resolved path before checking by converting
backslashes to forward slashes (or using path.posix/path.normalize) and then
test for "/plugins/". Update the logic around the resolved variable (the result
of path.resolve()) where includes("/plugins/") is used so the path is normalized
first, then perform the includes check and return null accordingly.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to Reviews > Disable Cache setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 62dd072 and 834d365.

📒 Files selected for processing (1)
  • frontend/vite.config.js

@github-actions
Copy link
Contributor

Frontend Lint Report (Biome)

All checks passed! No linting or formatting issues found.

@sonarqubecloud
Copy link

Copy link
Contributor

@hari-kuriakose hari-kuriakose left a comment

Choose a reason for hiding this comment

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

@vishnuszipstack LGTM overall

@hari-kuriakose hari-kuriakose merged commit 3dee1c3 into main Feb 27, 2026
7 checks passed
@hari-kuriakose hari-kuriakose deleted the fix/vite-optional-plugin-imports branch February 27, 2026 06:18
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.

3 participants