Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make attributes set by the user propagate to all assets #142

Merged
merged 4 commits into from
Sep 16, 2024

Conversation

kierangillblueberry
Copy link
Contributor

@kierangillblueberry kierangillblueberry commented Aug 1, 2024

Closes: #140

This is a followup to #131 and #128.

Django-vite now supports kebab cased attributes:

{% vite_asset '<path to your asset>' foo="bar" data_my_custom_attribute="world" %}

However, these attributes are not propagated to all tags that are generated by vite_asset.

My organization relies on Turbo's data-turbo-track="reload" attribute. When a new HTML file is fetched from the server, Turbo will know that it should perform a reload if there's a Js/CSS/etc file with a URL that it hasn't previously loaded.

This attribute needs to be set on every asset that we load in using {% vite_asset 'app/main.ts' ... %}.

This PR propagates user-defined attributes to all tags generated by vite_asset.

Before

{% vite_asset "src/entry.ts" data_item_track="reload" data_other="3" %}
...
<link rel="stylesheet" href="assets/entry-74d0d5dd.css" />
<script type="module" crossorigin="" data-item-track="reload" data-other="3" src="assets/entry-29e38a60.js"></script>

After

{% vite_asset "src/entry.ts" data_item_track="reload" data_other="3" %}
...
<link data-item-track="reload" data-other="3" rel="stylesheet" href="assets/entry-74d0d5dd.css" />
<script type="module" crossorigin="" data-item-track="reload" data-other="3" src="assets/entry-29e38a60.js"></script>

@kierangillblueberry
Copy link
Contributor Author

Hey @MrBin99, I'm bumping this PR in case it got lost. We've experienced this issue a few more times since this PR was submitted. I'd appreciate your feedback!

@MrBin99
Copy link
Owner

MrBin99 commented Sep 13, 2024

Hi,
This looks good to me, @Niicck, what do you think ?

@MrBin99 MrBin99 requested a review from Niicck September 13, 2024 19:26
@Niicck
Copy link
Collaborator

Niicck commented Sep 14, 2024

Looks good to me! I added a PR that should clean up the new merge conflicts. kierangillblueberry#1

Once that gets updated, this PR should be good to merge

Fix merge conflicts on propagate-vite-asset-attrs
@Niicck Niicck merged commit 9bbd7a2 into MrBin99:master Sep 16, 2024
6 checks passed
@kierangillblueberry
Copy link
Contributor Author

Thank you all! We appreciate your support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Additional attributes on <link rel="stylesheet"> tag
3 participants