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

Fixed an "Uncaught ReferenceError" inside of the @astrojs/vue package #12116

Merged
merged 7 commits into from
Oct 5, 2024

Conversation

sammibajrami
Copy link
Contributor

Changes

I was getting an error on page transitions after upgrading all astro related packages in my project:
Uncaught ReferenceError: app is not defined

The app reference in question was in the client.js script, and it turned out that it was initiated inside of an if statement that didn't run on transitions.

I am making this pull request in the hope that it'll help.
I'm not very familiar with the Astro codebase so if my solution isn't really a solution then feel free to reject the request or to change it or to point me in the right direction to actually solve it myself :)

Testing

Ran the code, the error was gone and no new one took it's place.

Docs

Shouldn't affect a user’s behavior in any way.

…ipt by assigning the 'appInstance' reference to it so that it is available for the later established 'astro:unmount' event listener
Copy link

changeset-bot bot commented Oct 3, 2024

🦋 Changeset detected

Latest commit: becc89d

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: vue Related to Vue (scope) pkg: integration Related to any renderer integration (scope) labels Oct 3, 2024
@martrapp
Copy link
Member

martrapp commented Oct 4, 2024

@johannesspohr: Could you please take a look, Johannes?

@bluwy
Copy link
Member

bluwy commented Oct 4, 2024

Looks like the same issue is happening for svelte: #12102

@johannesspohr
Copy link
Contributor

Thanks for bringing this up. It looks to me like we should move attaching the event listener inside the block where app is initialized, as binding it once should be enough to clean everything up when the component is unmounted.
I can't try it right now unfortunately.

Copy link
Member

@martrapp martrapp left a comment

Choose a reason for hiding this comment

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

Hi @sammibajrami, the suggested solution would be to revert the file and only move the addEventlistener from line 52 up to line 47 at the end of the if-block. That would restore the logic as it was before the last fix and ensure that app is always defined when referenced.

…nt' event listener to inside of the 'if' statement where the 'app' variable is initialized
Copy link
Member

@martrapp martrapp left a comment

Choose a reason for hiding this comment

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

Looks good to me!
Thanks a lot, @sammibajrami!

@sammibajrami
Copy link
Contributor Author

Not a problem, and thank you too for pointing me in the right direction!

@martrapp martrapp merged commit af8401e into withastro:main Oct 5, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: integration Related to any renderer integration (scope) pkg: vue Related to Vue (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants