Closed maziar-dandc closed 4 months ago
This is supposed to prevent CSS files from being loaded more than once. Please provide me the way of replicating your problem.
I wasn't able to reproduce it reliably, but this is essentially the output:
4 out of 5 times:
1 out of 5 times: (no css import)
The reason it's unreliable might be because we run multiple django backend servers behind a load balancer, but essentially what happens is due to the mutable default argument, it thinks it's already imported the css file, and doesn't import it again.
mutable default argument essentially provides a python global variable, but what you want here is a per-page-render variable that ensures same css isn't imported on the same page twice.
I have pushed this fix on our staging/production, if it resolves the issue for good, I'll report back.
Yeah this has fixed the problem with phantom missing css problem.
New problem:
html += _get_css_files(VITE_MANIFEST[import_path], attrs, already_processed)
Had to change this as well to get the imports
related css files recursively correctly.
Sample manifest.json
using vite 5+:
I can make these changes a PR if you want, lemme know.
Did you mean #57?
Please check if #58 solves the first problem. This was a weird python behavior I forgot.
Yeah these PRs solve both of the problems, thanks ❤️👍🏻
https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments
https://github.com/protibimbok/django-vite-plugin/blob/691822109688d3e756468d7d5f092787875175b1/django/src/django_vite_plugin/utils.py#L91
Causing css styles to not be imported on the page.