Skip to content

Handle Detail issues#434

Open
rvlb wants to merge 8 commits intomasterfrom
detail-bugs
Open

Handle Detail issues#434
rvlb wants to merge 8 commits intomasterfrom
detail-bugs

Conversation

@rvlb
Copy link
Copy Markdown
Contributor

@rvlb rvlb commented May 7, 2026

Closes #426

  • Updates setup structure and changes how README.md file is parsed in there.

Closes #429

  • Fix possible race condition when re-compiling assets (hard to reproduce on development only)

Closes #430

  • Ensure we don't hit a scenario where we cache incorrect formed stats files (hard to reproduce on development only)

Closes #431

  • Brings parity between render_bundle and get_files when it uses skip_common_chunks (get_files had that property, but in the end it wasn't updating the used files in the request)
  • Updates tests to ensure we don't access TemplateView.rendered_content multiple times per-request, as this was impacting the request used urls property

Closes #432

  • Ensure integrity and csp nonce are used for preloaded js urls (this was missing from when it was introduced as a feature last year).

Comment thread webpack_loader/loaders.py
)

return self.map_chunk_files_to_url(filtered_chunks)
return self.map_chunk_files_to_url(filtered_chunks, assets=assets)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of this changes is to pass down the assets instance that was obtained on line 199 in this method, instead of always relying on re-fetching the assets inside map_chunk_files_to_url, as there could be a chance that the stats file is recompiled between those calls and the data becomes inconsistent.

It's a hard-to-reproduce situation at the end of the day and that would only affect development, if it ever shows up.

Comment thread webpack_loader/loaders.py
assets = self._assets.get(self.name)
if not assets or assets.get("status") == "compile":
assets = self.load_assets()
if assets.get("status") != "compile":
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that we can only cache assets that aren't compiling after the polling in the previous line.

@rvlb rvlb marked this pull request as ready for review May 8, 2026 14:51
@@ -82,8 +82,10 @@ def get_files(
return result

used_urls = getattr(request, '_webpack_loader_used_urls', None)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used_urls was read-only before this change, which led to some non-deterministic results depending on which templatetags where used before it (regression tests added to test the interaction between get_files and render_bundle).

@rvlb rvlb requested a review from fjsj May 8, 2026 14:55
Comment thread .gitignore Outdated
Comment thread setup.py Outdated
"webpack_loader/templatetags",
"webpack_loader/contrib",
"webpack_loader.templatetags",
"webpack_loader.contrib",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change. Should this really be changed? Check what's the proper syntax.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked around and it seems that the most recommended approach is to delegate this to setuptools.find_packages https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#packages.

That function itself returns the package using the dot notation instead of the slashes.

Comment thread tests/app/tests/test_webpack.py
Comment thread tests/app/tests/test_webpack.py
tag_dict = get_as_url_to_tag_dict('resources', extension='js', attrs='', request=request_with_nonce)
self.assertNotIn('nonce=', tag_dict['/static/django_webpack_loader_bundles/resources.js'])

def test_get_url_to_tag_dict_js_preload_includes_integrity_and_nonce(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we always include integrity and nonce? Any downsides when they are included? Any issues when they're empty or they are really always filled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They aren't always filled, if the corresponding setting for each of them was turned off the helper function would return an empty string to be added to the formatted output.

I've refactored that behavior to improve readability in this flow here a978459. With that we got rid of the {0},{1},{2}, etc formats that were starting to get a bit out of control in favor of having those parameters being conditionally added to a list and then remove the null-ish values.

I think this will also make it easier for a developer reading the code to check that those values might be empty.

@rvlb rvlb requested a review from fjsj May 8, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment