Skip to content

fix(component-core): document.currentScript is null on module apps #859

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

Merged
merged 2 commits into from
Oct 18, 2022
Merged

fix(component-core): document.currentScript is null on module apps #859

merged 2 commits into from
Oct 18, 2022

Conversation

onhate
Copy link
Member

@onhate 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)

Copy link
Member

@mlsamuelson mlsamuelson left a comment

Choose a reason for hiding this comment

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

@onhate This looks good and tests out. One thing needed for this to trigger a release of the components-core package by our semantic-release configuration when it is merged is for there to be a commit to components-core following the Conventional Commits standard. Normally it would be the commit with your code, but since you'll be doing this after the fact, I suggest making a small edit in the components-core README.md (such as adding or removing a line break). And for the commit message, this would work: fix(component-core): commit to trigger release

Let me know if what I'm asking for is not clear.

If you're interested, you can find more details about our Conventional Commits and semantic-release setup at: https://github.com/ASU/asu-unity-stack#-git-commit-guidelines

When that commit is in place, ping me and I'll give it one last look and we should be good.

@onhate
Copy link
Member Author

onhate commented Oct 18, 2022

thanks @mlsamuelson for the guidance, it should be ok now, right?

@onhate onhate requested review from mlsamuelson and removed request for davidornelas11 October 18, 2022 12:22
@onhate onhate changed the title document.currentScript is null on module apps fix(component-core): document.currentScript is null on module apps Oct 18, 2022
@mlsamuelson mlsamuelson merged commit 24e84fe into ASU:dev Oct 18, 2022
@mlsamuelson
Copy link
Member

@onhate Looks good! I goofed and said "component-core" instead of "components-core" (plural) but I'll fix it on this side so a build gets triggered. My bad.

Approved and merged. Thank you!

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.

2 participants