Skip to content

Commit 86bb64f

Browse files
committed
fix(exclude): don't cache excluded scripts
1 parent aa31ba4 commit 86bb64f

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/workers/cache-grouped-scripts-worker.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,45 @@ test('benchmark - worker CACHE_MAIN_SCRIPTS', async (t) => {
205205

206206
t.pass()
207207
})
208+
209+
test('Worker filters out scripts with exclude metadata', async (t) => {
210+
const { msg, worker } = await runWorkerMessage({
211+
channel: Channel.CACHE_MAIN_SCRIPTS,
212+
value: null,
213+
id: 'test-exclude-filter'
214+
})
215+
216+
t.is(msg.channel, Channel.CACHE_MAIN_SCRIPTS)
217+
t.true(Array.isArray(msg.scripts), 'scripts should be an array')
218+
219+
// Verify no scripts have exclude property set to true
220+
const excludedScriptsFound = msg.scripts.filter((script: any) => script.exclude === true)
221+
t.is(excludedScriptsFound.length, 0, 'No scripts with exclude:true should be present in cached scripts')
222+
223+
// Log for debugging
224+
if (msg.scripts.length > 0) {
225+
t.log(`Total scripts after exclude filter: ${msg.scripts.length}`)
226+
}
227+
228+
worker.terminate()
229+
})
230+
231+
test('Worker preserves non-excluded scripts', async (t) => {
232+
const { msg, worker } = await runWorkerMessage({
233+
channel: Channel.CACHE_MAIN_SCRIPTS,
234+
value: null,
235+
id: 'test-preserve-non-excluded'
236+
})
237+
238+
t.is(msg.channel, Channel.CACHE_MAIN_SCRIPTS)
239+
t.true(Array.isArray(msg.scripts), 'scripts should be an array')
240+
241+
// Verify that scripts without exclude or with exclude:false are preserved
242+
const nonExcludedScripts = msg.scripts.filter((script: any) =>
243+
script.exclude === undefined || script.exclude === false
244+
)
245+
246+
t.is(nonExcludedScripts.length, msg.scripts.length, 'All cached scripts should be non-excluded')
247+
248+
worker.terminate()
249+
})

src/workers/cache-grouped-scripts-worker.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ const parseMainMenu = async (stamp: Stamp | null) => {
129129
// Fetch grouped scripts and format
130130
const groupedScripts = await getGroupedScripts(false)
131131
logToParent(`Grouped scripts: ${groupedScripts.map((s) => s.name).join(', ')}`)
132-
const scripts = formatChoices(groupedScripts)
132+
const allScripts = formatChoices(groupedScripts)
133+
// Filter out excluded scripts to prevent flicker in main menu
134+
const scripts = allScripts.filter((s) => !s?.exclude)
133135
logToParent(
134-
`Formatted scripts: ${scripts
136+
`Formatted scripts (after exclude filter): ${scripts
135137
.slice(0, 10)
136138
.map((s) => s.name)
137-
.join(', ')}`
139+
.join(', ')} (${allScripts.length} total, ${scripts.length} after filter)`
138140
)
139141

140142
const firstScript = scripts.find((script) => !script.skip) as Script | undefined

0 commit comments

Comments
 (0)