Skip to content

Commit c76b164

Browse files
committed
fix: accept semantic watch hmr output updates
1 parent 76c5c68 commit c76b164

3 files changed

Lines changed: 99 additions & 0 deletions

File tree

packages/weapp-tailwindcss/test/watch-hmr-regression.unit.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
waitForCompileSettled,
4747
waitForInitialWarmup,
4848
waitForOutputsReady,
49+
waitForOutputsUpdated,
4950
waitForOutputFilesUpdated,
5051
} from '../../../tools/weapp-tailwindcss-scripts/src/watch-hmr-regression/mutations/shared'
5152
import {
@@ -342,6 +343,44 @@ describe('watch-hmr regression text helpers', () => {
342343
expect(attempts).toBeGreaterThanOrEqual(2)
343344
})
344345

346+
it('allows primary output update waits to pass via semantic fallback when mtimes stay unchanged', async () => {
347+
const tempDir = await mkdtemp(path.join(os.tmpdir(), 'weapp-tw-watch-primary-output-update-'))
348+
tempDirs.push(tempDir)
349+
const wxmlFile = path.join(tempDir, 'index.wxml')
350+
const jsFile = path.join(tempDir, 'index.js')
351+
await writeFilePreserveEol(wxmlFile, '<view class="base"></view>', '<view />')
352+
await writeFilePreserveEol(jsFile, 'Page({})', 'Page({})')
353+
const baseline = {
354+
wxml: await getMtime(wxmlFile),
355+
js: await getMtime(jsFile),
356+
}
357+
let attempts = 0
358+
359+
const elapsed = await waitForOutputsUpdated(
360+
{
361+
label: 'demo/taro-vite-vue3-tailwindcss-v4',
362+
outputWxml: wxmlFile,
363+
outputJs: jsFile,
364+
} as any,
365+
baseline,
366+
{
367+
timeoutMs: 100,
368+
pollMs: 1,
369+
} as CliOptions,
370+
{
371+
ensureRunning() {},
372+
} as any,
373+
Date.now(),
374+
async () => {
375+
attempts += 1
376+
return attempts >= 2
377+
},
378+
)
379+
380+
expect(elapsed).toBeGreaterThanOrEqual(0)
381+
expect(attempts).toBeGreaterThanOrEqual(2)
382+
})
383+
345384
it('allows output file update waits to pass via semantic fallback when optional exact files are missing', async () => {
346385
const tempDir = await mkdtemp(path.join(os.tmpdir(), 'weapp-tw-watch-output-missing-'))
347386
tempDirs.push(tempDir)

tools/weapp-tailwindcss-scripts/src/watch-hmr-regression/mutations/class.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,23 @@ export async function runClassMutation(
556556
options,
557557
session,
558558
hotUpdateStartedAt,
559+
async () => {
560+
const outputs = await loadRoundOutputsSafe(watchCase, globalStyleOutputs)
561+
assertRoundOutputs(
562+
watchCase,
563+
mutationKind,
564+
sourcePath,
565+
'add',
566+
mutation,
567+
verifyClassLiteralIn,
568+
forbidBgHexTruncationIn,
569+
minRequiredGlobalStyleEscapedClasses,
570+
classTokens,
571+
escapedClasses,
572+
outputs,
573+
)
574+
return true
575+
},
559576
)
560577
const hotUpdateEffectiveMs = isContentMutation
561578
? hotUpdateOutputMs
@@ -713,6 +730,23 @@ export async function runClassMutation(
713730
options,
714731
session,
715732
modifyStartedAt,
733+
async () => {
734+
const outputs = await loadRoundOutputsSafe(watchCase, globalStyleOutputs)
735+
assertRoundOutputs(
736+
watchCase,
737+
mutationKind,
738+
sourcePath,
739+
'modify',
740+
mutation,
741+
verifyClassLiteralIn,
742+
forbidBgHexTruncationIn,
743+
minRequiredGlobalStyleEscapedClasses,
744+
modifyClassTokens,
745+
modifyEscapedClasses,
746+
outputs,
747+
)
748+
return true
749+
},
716750
)
717751
const modifyEffectiveMs = isContentMutation
718752
? modifyOutputMs
@@ -847,6 +881,15 @@ export async function runClassMutation(
847881
options,
848882
session,
849883
rollbackStartedAt,
884+
async () => {
885+
const outputs = await loadRoundOutputsSafe(watchCase, globalStyleOutputs)
886+
if (!outputs.wxml || !outputs.js) {
887+
return false
888+
}
889+
return !outputs.wxml.includes(effectiveMarker)
890+
&& !outputs.js.includes(effectiveMarker)
891+
&& !outputs.globalStyle.includes(effectiveMarker)
892+
},
850893
)
851894
rollbackEffectiveMs = isContentMutation
852895
? rollbackOutputMs

tools/weapp-tailwindcss-scripts/src/watch-hmr-regression/mutations/shared.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,30 @@ export async function waitForOutputsUpdated(
203203
options: CliOptions,
204204
session: WatchSession,
205205
startedAt = Date.now(),
206+
acceptWhen?: () => Promise<boolean>,
206207
) {
208+
const acceptsSemanticOutput = async () => {
209+
if (!acceptWhen) {
210+
return false
211+
}
212+
213+
try {
214+
return await acceptWhen()
215+
}
216+
catch {
217+
return false
218+
}
219+
}
220+
207221
return waitFor(
208222
async () => {
209223
const [wxmlMtime, jsMtime] = await Promise.all([
210224
getMtime(watchCase.outputWxml),
211225
getMtime(watchCase.outputJs),
212226
])
227+
if (await acceptsSemanticOutput()) {
228+
return true
229+
}
213230
return wxmlMtime > baseline.wxml || jsMtime > baseline.js
214231
},
215232
{

0 commit comments

Comments
 (0)