Current Situation
Currently, a user can add django_css to the body of a component that is rendered multiple times. This means that the CSS stylesheet will be duplicated for each component that is on the page.
Proposed Actions
Add an only_once = True argument to django_css and django_js. This will prevent CSS/JS duplication if the static file has already been loaded within the current component tree.
To detect whether a static file has been loaded, we should store whether a static_file_path has already been loaded within the ASGI scope. Here's some pseudocode on the concept:
# This should be initialized within the ReactPy WebSocket consumer
scope["reactpy_static_files"] = set()
# This check should occur within the `django_css` and `django_js` components
if static_file_path not in scope["reactpy_static_files"]:
return get_static_file_contents(static_file_path)
Current Situation
Currently, a user can add
django_cssto the body of a component that is rendered multiple times. This means that the CSS stylesheet will be duplicated for each component that is on the page.Proposed Actions
Add an
only_once = Trueargument todjango_cssanddjango_js. This will prevent CSS/JS duplication if the static file has already been loaded within the current component tree.To detect whether a static file has been loaded, we should store whether a
static_file_pathhas already been loaded within the ASGIscope. Here's some pseudocode on the concept: