From 193731536de7bff792c1f94e74c3efcf01cb51f0 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Wed, 14 Jan 2026 16:28:05 +0800 Subject: [PATCH 1/3] fix: fix the issue where the application's assets_path_ignore is being overridden --- dash_vite_plugin/plugin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dash_vite_plugin/plugin.py b/dash_vite_plugin/plugin.py index 63a5b3e..4a26ee6 100644 --- a/dash_vite_plugin/plugin.py +++ b/dash_vite_plugin/plugin.py @@ -181,9 +181,11 @@ def _set_assets_path_ignore(self, app: Dash) -> None: # Remove prefix2 prefix assets_to_ignore.append(path[len(prefix2) :]) - # Set as assets_path_ignore if any paths were found + # Set assets_path_ignore if any paths were found if assets_to_ignore: - app.config.assets_path_ignore = assets_to_ignore + if not app.config.assets_path_ignore: + app.config.assets_path_ignore = [] + app.config.assets_path_ignore.extend(assets_to_ignore) def _should_skip_build(self) -> bool: """ From 770d3fe876773d6b691168bc063941fb70c42304 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Wed, 14 Jan 2026 16:28:19 +0800 Subject: [PATCH 2/3] test: add more tests --- tests/test_plugin.py | 108 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 36a64d5..400d1e4 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -730,6 +730,114 @@ def __init__(self): expected_ignore = ['css', 'js'] assert mock_app.config.assets_path_ignore == expected_ignore + def test_set_assets_path_ignore_extends_existing(self): + """Test _set_assets_path_ignore method extends existing assets_path_ignore.""" + build_assets_paths = ['./assets/css', 'assets/js'] + entry_js_paths = ['assets/js/main.js'] + npm_packages = [NpmPackage('react')] + + plugin = VitePlugin( + build_assets_paths=build_assets_paths, entry_js_paths=entry_js_paths, npm_packages=npm_packages + ) + + # Create a mock Dash app with existing assets_path_ignore + class MockConfig: + def __init__(self): + self.assets_folder = 'assets' + self.assets_path_ignore = ['existing/ignore'] + + mock_app = MagicMock() + mock_app.config = MockConfig() + + # Call _set_assets_path_ignore + plugin._set_assets_path_ignore(mock_app) + + # Check that assets_path_ignore was extended correctly + expected_ignore = ['existing/ignore', 'css', 'js'] + assert mock_app.config.assets_path_ignore == expected_ignore + + def test_set_assets_path_ignore_no_matching_paths(self): + """Test _set_assets_path_ignore method when no paths match assets_dir_name.""" + build_assets_paths = ['other/css', './public/js'] + entry_js_paths = ['assets/js/main.js'] + npm_packages = [NpmPackage('react')] + + plugin = VitePlugin( + build_assets_paths=build_assets_paths, entry_js_paths=entry_js_paths, npm_packages=npm_packages + ) + + # Create a mock Dash app with real config object + class MockConfig: + def __init__(self): + self.assets_folder = 'assets' + self.assets_path_ignore = [] + + mock_app = MagicMock() + mock_app.config = MockConfig() + + # Call _set_assets_path_ignore + plugin._set_assets_path_ignore(mock_app) + + # Check that assets_path_ignore remains empty + assert mock_app.config.assets_path_ignore == [] + + def test_set_assets_path_ignore_empty_build_assets_paths(self): + """Test _set_assets_path_ignore method when build_assets_paths is empty.""" + build_assets_paths = [] + entry_js_paths = ['assets/js/main.js'] + npm_packages = [NpmPackage('react')] + + plugin = VitePlugin( + build_assets_paths=build_assets_paths, entry_js_paths=entry_js_paths, npm_packages=npm_packages + ) + + # Create a mock Dash app with real config object + class MockConfig: + def __init__(self): + self.assets_folder = 'assets' + self.assets_path_ignore = [] + + mock_app = MagicMock() + mock_app.config = MockConfig() + + # Call _set_assets_path_ignore + plugin._set_assets_path_ignore(mock_app) + + # Check that assets_path_ignore remains empty + assert mock_app.config.assets_path_ignore == [] + + def test_set_assets_path_ignore_complex_paths(self): + """Test _set_assets_path_ignore method with complex paths.""" + build_assets_paths = [ + 'assets/js', + './assets/css/styles', + 'assets/images/icons', + 'public/assets/js', # Should not match + './public/css' # Should not match + ] + entry_js_paths = ['assets/js/main.js'] + npm_packages = [NpmPackage('react')] + + plugin = VitePlugin( + build_assets_paths=build_assets_paths, entry_js_paths=entry_js_paths, npm_packages=npm_packages + ) + + # Create a mock Dash app with real config object + class MockConfig: + def __init__(self): + self.assets_folder = 'assets' + self.assets_path_ignore = [] + + mock_app = MagicMock() + mock_app.config = MockConfig() + + # Call _set_assets_path_ignore + plugin._set_assets_path_ignore(mock_app) + + # Check that assets_path_ignore contains the correct paths + expected_ignore = ['js', 'css/styles', 'images/icons'] + assert mock_app.config.assets_path_ignore == expected_ignore + def test_build_assets_with_vite(self): """Test _build_assets_with_vite method.""" build_assets_paths = ['assets/js'] From 60326f23ed6f248a5d575efe1b6d5c1f0ec97753 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Wed, 14 Jan 2026 16:30:07 +0800 Subject: [PATCH 3/3] style: fix format --- tests/test_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 400d1e4..0641ea0 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -813,7 +813,7 @@ def test_set_assets_path_ignore_complex_paths(self): './assets/css/styles', 'assets/images/icons', 'public/assets/js', # Should not match - './public/css' # Should not match + './public/css', # Should not match ] entry_js_paths = ['assets/js/main.js'] npm_packages = [NpmPackage('react')]