Skip to content

feat(platform): add selectorless compilation support#2292

Draft
benpsnyder wants to merge 22 commits intoanalogjs:alphafrom
benpsnyder:feat/selectorless-investigation-preserved
Draft

feat(platform): add selectorless compilation support#2292
benpsnyder wants to merge 22 commits intoanalogjs:alphafrom
benpsnyder:feat/selectorless-investigation-preserved

Conversation

@benpsnyder
Copy link
Copy Markdown
Contributor

@benpsnyder benpsnyder commented Apr 15, 2026

PR Checklist

Closes #

Affected scope

  • Primary scope: platform
  • Secondary scopes: vite-plugin-angular

Recommended merge strategy for maintainer [optional]

  • Squash merge
  • Rebase merge
  • Other

Commit preservation note [optional]

The branch history is noisy and includes merge/investigation commits, but the net diff is one related feature across platform and vite-plugin-angular. Squash merge is the safest maintainer path.

What is the new behavior?

  • Adds a top-level experimental.enableSelectorless option to analog() and forwards it to @analogjs/vite-plugin-angular.
  • Preserves the legacy vite.experimental.enableSelectorless compatibility path, with the top-level Analog option taking precedence when both are set.
  • Auto-enables selectorless compilation in the Angular plugin when Angular 20+ apps include file-based pages, while still allowing apps to pin the behavior explicitly.
  • Adds tests for selectorless option forwarding and compiler-option mutation.

Test plan

  • nx format:check
  • pnpm build
  • pnpm test
  • Manual verification

Executed for this branch:

  • pnpm nx test platform
  • pnpm nx test vite-plugin-angular

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This PR intentionally touches both platform and vite-plugin-angular so the public Analog config surface stays aligned with the lower-level Angular compiler integration.

…o plugins by clarifying HMR behavior and config handling
…d comments do not interfere with directive detection
…SS comment handling for directive detection
… for Tailwind reference detection and improving test case timeout
…mentHostWithResources, enhancing error management in CSS processing
…ancing experimental options and test coverage
…and test coverage

- Enhanced documentation for the selectorless compilation option in the Angular plugin.
- Added tests to ensure top-level selectorless configuration takes precedence over legacy settings.
- Updated logic to maintain consistency between top-level and legacy experimental configurations.
- Improved handling of selectorless support detection in the live reload plugin.
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 15, 2026

Deploy Preview for analog-app ready!

Name Link
🔨 Latest commit 756a1de
🔍 Latest deploy log https://app.netlify.com/projects/analog-app/deploys/69df0021c3b1ce000921745d
😎 Deploy Preview https://deploy-preview-2292--analog-app.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 15, 2026

📝 Walkthrough

Walkthrough

This pull request introduces experimental support for selectorless component compilation across the platform and Vite plugin layers. The changes add an enableSelectorless option to both Options.experimental and the Angular plugin configuration, with automatic detection when Angular version is >= 20.0.0 and route-like files are present. Implementation includes tsconfig graph expansion logic, cache mechanisms, debug infrastructure, and comprehensive test coverage validating the option's forwarding, precedence, and compilation behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

The diff introduces significant structural additions across multiple layers: tsconfig graph traversal and caching, auto-detection logic coupling Angular version detection with file globbing, configuration forwarding with precedence handling, and extensive test scenarios covering selectorless defaults and overrides. While individual changes follow consistent patterns (option plumbing, debug scope additions), the logic density is high, particularly around tsconfig expansion and compiler option mapping. The heterogeneous nature of edits—ranging from configuration forwarding to complex graph manipulation to test infrastructure—demands separate reasoning per affected code path.

🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning No description was provided by the author; this makes it difficult to understand the intent and context of the changes. Add a description explaining the enableSelectorless feature, its purpose, and how it forwards Angular compilation support.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(platform): add selectorless compilation support' follows Conventional Commit style with a supported package scope (platform) and accurately summarizes the main change—adding selectorless compilation support to the platform package.

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


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.

@github-actions github-actions bot added scope:platform Changes in @analogjs/platform scope:vite-plugin-angular Changes in @analogjs/vite-plugin-angular labels Apr 15, 2026
@github-actions
Copy link
Copy Markdown

This PR touches multiple package scopes: platform, vite-plugin-angular.

Please confirm the changes are closely related. Squash merge is highly preferred. If you recommend a non-squash merge, add a brief note explaining why the commit boundaries matter and why this PR should bypass focused changes per package.

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 15, 2026

Deploy Preview for analog-blog ready!

Name Link
🔨 Latest commit 756a1de
🔍 Latest deploy log https://app.netlify.com/projects/analog-blog/deploys/69df00210fb3b90007f2f880
😎 Deploy Preview https://deploy-preview-2292--analog-blog.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown

@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/platform/src/lib/platform-plugin.spec.ts (1)

144-179: Add one test for the legacy-only selectorless path.

These two cases cover the top-level flag and precedence, but they still leave the documented compatibility branch untested when only vite.experimental.enableSelectorless is set. A single legacy-only assertion here would pin that fallback behavior too.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/platform/src/lib/platform-plugin.spec.ts` around lines 144 - 179,
Add a third unit test that asserts the legacy-only path where only
vite.experimental.enableSelectorless is set is handled: call platformPlugin with
no top-level experimental but with vite: { experimental: { enableSelectorless:
true } }, then assert angularSpy was called with an options object containing
experimental.enableSelectorless: true; place this alongside the existing tests
that call platformPlugin and check angularSpy so the fallback behavior is
pinned.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts`:
- Around line 320-367: The selectorless detection enables routes under
src/app/routes and app/routes via detectSelectorlessRouteUsage but
isLikelyPageOnlyComponent still only treats /pages/ and .page.* as route-like;
update isLikelyPageOnlyComponent to reuse the same route-file predicate
(isSelectorlessRouteFile) or extract the predicate into a shared helper so files
matching '/src/app/routes/' or '/app/routes/' are considered route entries as
well, ensuring components that triggered _enableSelectorless won't then fail the
explicit-selector check.

---

Nitpick comments:
In `@packages/platform/src/lib/platform-plugin.spec.ts`:
- Around line 144-179: Add a third unit test that asserts the legacy-only path
where only vite.experimental.enableSelectorless is set is handled: call
platformPlugin with no top-level experimental but with vite: { experimental: {
enableSelectorless: true } }, then assert angularSpy was called with an options
object containing experimental.enableSelectorless: true; place this alongside
the existing tests that call platformPlugin and check angularSpy so the fallback
behavior is pinned.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4a7517c2-8896-459d-b4a7-86ae14fcd7d9

📥 Commits

Reviewing files that changed from the base of the PR and between 45799f9 and 638d30e.

📒 Files selected for processing (6)
  • packages/platform/src/lib/options.ts
  • packages/platform/src/lib/platform-plugin.spec.ts
  • packages/platform/src/lib/platform-plugin.ts
  • packages/vite-plugin-angular/src/lib/angular-vite-plugin-live-reload.spec.ts
  • packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
  • packages/vite-plugin-angular/src/lib/utils/debug.ts

Comment on lines +320 to +367
function isSelectorlessRouteFile(file: string): boolean {
const normalized = normalizePath(file);
return (
normalized.endsWith('.page.ts') ||
normalized.includes('/src/app/routes/') ||
normalized.includes('/app/routes/')
);
}

/**
* Infer selectorless support from route/page entry points.
*
* This heuristic is intentionally broad because file-based routing commonly
* relies on selectorless components. The resulting Angular compiler flag is
* program-wide, not route-scoped, so a matching route-like include can affect
* every file in the current Angular program.
*/
function detectSelectorlessRouteUsage(
root: string,
workspaceRoot: string,
includeGlobs: string[],
): { enabled: boolean; routeFileCount: number } {
const normalizedRoot = normalizePath(resolve(root));
const normalizedWorkspaceRoot = normalizePath(resolve(workspaceRoot));
const appRouteGlobs = [
`${normalizedRoot}/src/app/pages/**/*.page.ts`,
`${normalizedRoot}/src/app/routes/**/*.ts`,
`${normalizedRoot}/app/routes/**/*.ts`,
];
const routeLikeIncludeGlobs = includeGlobs
.map((glob) => normalizeIncludeGlob(normalizedWorkspaceRoot, glob))
.filter(
(glob) =>
glob.includes('.page.') ||
glob.includes('/pages/') ||
glob.includes('/app/routes/') ||
glob.includes('/src/app/routes/'),
);
const routeFiles = globSync([...appRouteGlobs, ...routeLikeIncludeGlobs], {
absolute: true,
dot: true,
onlyFiles: true,
}).filter(isSelectorlessRouteFile);

return {
enabled: routeFiles.length > 0,
routeFileCount: routeFiles.length,
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Route auto-detection now outruns the selectorless safety gate.

This new heuristic enables selectorless mode for src/app/routes / app/routes, but the later validation path still only exempts /pages/ and .page.* in isLikelyPageOnlyComponent(). A selectorless route entry component will therefore get _enableSelectorless and then still fail with the explicit-selector error. Reuse the same route-file predicate in both places so route entries stay supported.

Possible fix
 function isLikelyPageOnlyComponent(id: string): boolean {
   return (
+    isSelectorlessRouteFile(id) ||
     id.includes('/pages/') ||
     /\.page\.[cm]?[jt]sx?$/i.test(id) ||
     /\([^/]+\)\.page\.[cm]?[jt]sx?$/i.test(id)
   );
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts` around lines 320
- 367, The selectorless detection enables routes under src/app/routes and
app/routes via detectSelectorlessRouteUsage but isLikelyPageOnlyComponent still
only treats /pages/ and .page.* as route-like; update isLikelyPageOnlyComponent
to reuse the same route-file predicate (isSelectorlessRouteFile) or extract the
predicate into a shared helper so files matching '/src/app/routes/' or
'/app/routes/' are considered route entries as well, ensuring components that
triggered _enableSelectorless won't then fail the explicit-selector check.

@benpsnyder benpsnyder marked this pull request as draft April 15, 2026 02:39
@benpsnyder benpsnyder changed the title Feat/selectorless investigation preserved feat(platform): add selectorless compilation support Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:platform Changes in @analogjs/platform scope:vite-plugin-angular Changes in @analogjs/vite-plugin-angular

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant