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

ExternalScriptsHandle does not attach custom attributes to link #309

Open
IgnisDa opened this issue Feb 20, 2024 · 6 comments
Open

ExternalScriptsHandle does not attach custom attributes to link #309

IgnisDa opened this issue Feb 20, 2024 · 6 comments

Comments

@IgnisDa
Copy link

IgnisDa commented Feb 20, 2024

Describe the bug

Here is my handle function:

export const handle: ExternalScriptsHandle<SerializeFrom<typeof loader>> = {
	scripts(_params) {
		return [{
			src: "https://us.umami.is/script.js",
			defer: true,
			"website-id": "abcd",
			"data-domains": undefined
	        }];
	},
};

However, this is rendered as:

<script src="https://us.umami.is/script.js" defer="" async=""></script>

Your Example Website or App

https://github.com/IgnisDa/ryot/blob/8204c2f5bc9de32e4181cf60a117db184b9eba88/apps/frontend/app/routes/_dashboard.tsx#L148

Steps to Reproduce the Bug or Issue

  • Use the above handler function anywhere.

Expected behavior

I expect it to be rendered as:

<script src="https://us.umami.is/script.js" defer="" async="" data-website-id="abcd"></script>

Screenshots or Videos

No response

Platform

Additional context

No response

@IgnisDa
Copy link
Author

IgnisDa commented Feb 20, 2024

I think this can be fixed by attaching rest props for this:

<script
src={src}
defer={defer}
async={async}
type={type}
noModule={noModule}
nonce={nonce}
crossOrigin={crossOrigin}
integrity={integrity}
referrerPolicy={referrerPolicy}
/>

@gar1t
Copy link

gar1t commented Apr 19, 2024

Just a bump to this - not supporting data-xxx breaks this abstraction.

As a point of design feedback, I would not use rest/spread to support but an explicit property that simply passes through whatever is provided. E.g. extraAttrs or something like that. This is not a mainstream case, but it's a critical one.

@wouterds
Copy link

wouterds commented May 10, 2024

Would be nice, e.g. the Cloudflare beacon uses this custom data-cf-beacon attribute. You can have it automagically insert but then the console is full of hydration mismatch errors.

Edit: was just adding tracking and came across this, data attributes seem to be frequently used on third party scripts.
Screenshot 2024-05-10 at 16 38 35

@Rocinante89
Copy link

Agreed with @gar1t on this one. Came across this issue integrating Cloudflare beacon.

@theosenoussaoui
Copy link

Would love to the possibility of passing custom attributes as well !

@theocerutti
Copy link

same!

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

No branches or pull requests

6 participants