-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from thijskramer/initialize-loader-instance-di…
…fferently Create singleton instance on app ready
- Loading branch information
Showing
2 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from django.apps import AppConfig | ||
from django.core.checks import Warning, register | ||
|
||
from .templatetags.django_vite import DjangoViteAssetLoader | ||
|
||
|
||
class DjangoViteAppConfig(AppConfig): | ||
name = "django_vite" | ||
verbose_name = "Django Vite" | ||
|
||
def ready(self) -> None: | ||
try: | ||
# Create Loader instance at startup to prevent threading problems. | ||
DjangoViteAssetLoader.instance() | ||
except RuntimeError: | ||
# Just continue, the system check below outputs a warning. | ||
pass | ||
|
||
|
||
@register | ||
def check_loader_instance(**kwargs): | ||
"""Raise a warning during startup when instance retrieval fails.""" | ||
|
||
try: | ||
# Make Loader instance at startup to prevent threading problems | ||
DjangoViteAssetLoader.instance() | ||
return [] | ||
except RuntimeError as exception: | ||
return [ | ||
Warning( | ||
exception, | ||
id="DJANGO_VITE", | ||
hint=( | ||
"Make sure you have generated a manifest file, " | ||
"and that the DJANGO_VITE_MANIFEST_PATH points " | ||
"to the correct location." | ||
), | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters