Skip to content

Commit b1849a1

Browse files
fix: avoid false positives in import protection
1 parent a562eb4 commit b1849a1

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

  • packages/start-plugin-core/src/import-protection-plugin

packages/start-plugin-core/src/import-protection-plugin/plugin.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,12 +682,16 @@ export function importProtectionPlugin(
682682

683683
// Check all code-split variants for this parent. The edge is
684684
// live if ANY variant's resolved imports include `current`.
685+
// Skip SERVER_FN_LOOKUP variants — they contain untransformed
686+
// code (the compiler excludes them), so their import lists
687+
// include imports that the compiler would normally strip.
685688
const keySet = env.transformResultKeysByFile.get(parent)
686689
let anyVariantCached = false
687690
let edgeLive = false
688691

689692
if (keySet) {
690693
for (const k of keySet) {
694+
if (k.includes(SERVER_FN_LOOKUP_QUERY)) continue
691695
const resolvedImports = env.postTransformImports.get(k)
692696
if (resolvedImports) {
693697
anyVariantCached = true
@@ -752,10 +756,15 @@ export function importProtectionPlugin(
752756
const toDelete: Array<string> = []
753757

754758
for (const [file, violations] of env.pendingViolations) {
755-
// On warm start, skip graph reachability — confirm immediately.
756-
const status = env.hasSeenEntry
757-
? checkPostTransformReachability(env, file)
758-
: 'reachable'
759+
// If no entries are registered yet, keep pending — the graph
760+
// isn't ready for reachability analysis. registerEntries()
761+
// populates entries during buildStart, and resolveId(!importer)
762+
// may add more. Once entries exist, the reachability check can
763+
// trace paths and confirm or discard pending violations.
764+
const status =
765+
env.graph.entries.size > 0
766+
? checkPostTransformReachability(env, file)
767+
: 'unknown'
759768

760769
if (status === 'reachable') {
761770
for (const pv of violations) {
@@ -1142,6 +1151,9 @@ export function importProtectionPlugin(
11421151
if (!importer) {
11431152
env.graph.addEntry(source)
11441153
env.hasSeenEntry = true
1154+
// Flush pending violations now that the entry is known and
1155+
// reachability analysis can proceed.
1156+
await processPendingViolations(env, this.warn.bind(this))
11451157
return undefined
11461158
}
11471159

0 commit comments

Comments
 (0)