diff --git a/django_vite/core/asset_loader.py b/django_vite/core/asset_loader.py index 0871104..606b20f 100644 --- a/django_vite/core/asset_loader.py +++ b/django_vite/core/asset_loader.py @@ -1,6 +1,6 @@ import json from pathlib import Path -from typing import Dict, List, Callable, NamedTuple, Optional, Union +from typing import Dict, List, Callable, NamedTuple, Optional, Union, Set from urllib.parse import urljoin import warnings @@ -427,13 +427,13 @@ def _load_css_files_of_asset( class GeneratedCssFilesOutput(NamedTuple): # list of generated CSS tags tags: List[Tag] - # list of already processed CSS tags - already_processed: List[str] + # set of already processed CSS tags + already_processed: Set[str] def _generate_css_files_of_asset( self, path: str, - already_processed: Optional[List[str]] = None, + already_processed: Optional[Set[str]] = None, tag_generator: Callable[[str], Tag] = TagGenerator.stylesheet, ) -> GeneratedCssFilesOutput: """ @@ -449,21 +449,22 @@ def _generate_css_files_of_asset( already_processed -- List of already processed css paths """ if already_processed is None: - already_processed = [] + already_processed = set() tags: List[Tag] = [] manifest_entry = self.manifest.get(path) for import_path in manifest_entry.imports: - new_tags, _ = self._generate_css_files_of_asset( + new_tags, new_already_processed = self._generate_css_files_of_asset( import_path, already_processed, tag_generator ) + already_processed.update(new_already_processed) tags.extend(new_tags) for css_path in manifest_entry.css: if css_path not in already_processed: url = self._get_production_server_url(css_path) tags.append(tag_generator(url)) - already_processed.append(css_path) + already_processed.add(css_path) return self.GeneratedCssFilesOutput(tags, already_processed)