···11+---
22+maudit: patch
33+---
44+55+Makes it so styles using Tailwind always have a different hash between builds in order to avoid stale content
+29
crates/maudit/src/assets.rs
···346346 }
347347 HashAssetType::Style(opts) => {
348348 buf.push(opts.tailwind as u8);
349349+350350+ if opts.tailwind {
351351+ // If Tailwind is enabled for that style, we can't calculate the hash purely from the file content, as the final output will depend on the Tailwind configuration and the content of the entire project. So we'll add a random thing to the hash to ensure always a new hash. The way to fix this would be to calculate the hash based on the final output CSS after Tailwind processing, but that'd require holding a lot of pages in memory, transforming after we're done with bundling all assets, etc. Which: Does not feel good. Until a better solution, the hash changing on each build when Tailwind is involved will have to do.
352352+ buf.extend_from_slice(&Instant::now().elapsed().as_nanos().to_le_bytes());
353353+ }
349354 }
350355 HashAssetType::Script => { /* No extra options for scripts yet */ }
351356 }
···641646 assert_ne!(
642647 hash1, hash2,
643648 "Different content should produce different hashes"
649649+ );
650650+ }
651651+652652+ #[test]
653653+ fn test_tailwind_hash_changes_every_time() {
654654+ let temp_dir = setup_temp_dir();
655655+ let style_path = temp_dir.join("tailwind_style.css");
656656+ std::fs::write(&style_path, "body { background: blue; }").unwrap();
657657+658658+ let mut page_assets = RouteAssets::new(&RouteAssetsOptions::default());
659659+660660+ // Add the same tailwind style multiple times with small delays
661661+ let style1 =
662662+ page_assets.add_style_with_options(&style_path, StyleOptions { tailwind: true });
663663+664664+ // Small delay to ensure different timestamp
665665+ std::thread::sleep(std::time::Duration::from_millis(1));
666666+667667+ let style2 =
668668+ page_assets.add_style_with_options(&style_path, StyleOptions { tailwind: true });
669669+670670+ assert_ne!(
671671+ style1.hash, style2.hash,
672672+ "Tailwind styles should produce different hashes due to time-based component"
644673 );
645674 }
646675}