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

Astro language server crashes with conditional <script> tag #636

Closed
1 task
xriter opened this issue Aug 23, 2023 · 4 comments
Closed
1 task

Astro language server crashes with conditional <script> tag #636

xriter opened this issue Aug 23, 2023 · 4 comments
Labels
needs response Need a response from the original author

Comments

@xriter
Copy link

xriter commented Aug 23, 2023

What version of astro are you using?

2.10.13

Are you using an SSR adapter? If so, which one?

What package manager are you using?

npm

What operating system are you using?

Mac

What browser are you using?

Safari

Describe the Bug

I am running into a problem where the Astro language server (using the Astro plugin in VS Code) crashes with code like in the following example:

// bugs.astro
---
  const name = 'Astronaut';
---

<h1>Title</h1>

{
    true && (
        <script
            is:inline
            define:vars={{
                contentName: name
            }}
        >
		fbq(
        "track",
        "AddToCart",
        {
            content_name: contentName,
        }
    );
            
        </script>
    )
}

In this example I want to add this script to the page whenever some conditions (now simplified into true && ...) are true.

Prettier starts giving errors like:

["ERROR" - 00:45:51] Error formatting document.
["ERROR" - 00:45:51] Unexpected token, expected "}" (10:16)

and I received a popup that the Astro language server crashed continuously, so the plugin was disabled.

However, when you take the script out of the conditional rendering block (like the example below), it gets formatted fine, and works correctly.

// worksfine.astro
---
  const name = 'Astronaut';
---

<h1>Title</h1>

<script
    is:inline
    define:vars={{
        contentName: name,
    }}
>
    fbq("track", "AddToCart", {
        content_name: contentName,
    });
</script>

Where does this problem come from and how can it be solved?
It looks like it has something to do with the { in the fbq function. As if there are now too many {'s for the language server to handle.

What's the expected result?

The first example to be formatted correctly by Prettier, and not crash the Astro language server.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-z8gtaw?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@Princesseuh Princesseuh transferred this issue from withastro/astro Aug 24, 2023
@Princesseuh
Copy link
Member

Princesseuh commented Aug 24, 2023

I cannot reproduce a crash with the snippet you shared, do you have another example? It not formatting is a known issue: withastro/prettier-plugin-astro#337

@Princesseuh Princesseuh added the needs response Need a response from the original author label Aug 24, 2023
@marsicdev
Copy link

I had a similar issue when the copilot provided incomplete tags

For example:

---
import Layout from "../layouts/Layout.astro"
---

<Layout title="Contact">
    <h1>Contact</h1>
    <p>Get in touch with me via <a href="https://twitter.com" target="_blank" rel="noopener noreferrer">Twitter</a> or <a href="
    
</Layout>

At this point, copilit had not finished the code completion but the Astro server crashed 5 times:

Connection to server got closed. Server will restart.
true
panic: runtime error: slice bounds out of range [:252] with length 251

@Princesseuh
Copy link
Member

I had a similar issue when the copilot provided incomplete tags

For example:

---
import Layout from "../layouts/Layout.astro"
---

<Layout title="Contact">
    <h1>Contact</h1>
    <p>Get in touch with me via <a href="https://twitter.com" target="_blank" rel="noopener noreferrer">Twitter</a> or <a href="
    
</Layout>

At this point, copilit had not finished the code completion but the Astro server crashed 5 times:

Connection to server got closed. Server will restart.
true
panic: runtime error: slice bounds out of range [:252] with length 251

That one is #623

@Princesseuh
Copy link
Member

Closing due to inactivity, please open a new issue if this still happens. I still cannot reproduce personally!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs response Need a response from the original author
Projects
None yet
Development

No branches or pull requests

3 participants