Skip to content

document.currentScript is null on module apps #858

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

Closed
onhate opened this issue Oct 17, 2022 · 1 comment
Closed

document.currentScript is null on module apps #858

onhate opened this issue Oct 17, 2022 · 1 comment

Comments

@onhate
Copy link
Member

onhate commented Oct 17, 2022

Hello, I'm using vite for the development of the new EPO application and I'm facing an issue while using Unity Header component in this line.

const match = (document.currentScript.src || "").match(/(.*\/)/);

2022-10-17T16-21-15

It happens because vite uses "module" to transpile/import the scripts in the browser and for that reason document.currentScript is null

https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript

The Document.currentScript property returns the <script> element whose script is currently being processed and isn't a JavaScript module. (For modules use import.meta instead.)

I did a quick test here and just checking if it's null first works for me because my application is loading resources from / which is the fallback for the method.

  const match = ((document.currentScript && document.currentScript.src) || "").match(/(.*\/)/);

Ideally the application should ignore this piece of logic when passing the logo properties to the component (I see this is only used to resolve the fallback assets for the logo)

@mlsamuelson
Copy link
Member

Looks like a reasonable addition. Issue will be reported to https://asu.edu/webservices. I'm closing this issue since we don't handle our issues in Github. :)

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

2 participants