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

In page frontmatter, an env var condition followed by an import leaves an unterminated string #1009

Open
1 task done
olets opened this issue Jun 16, 2024 · 4 comments
Open
1 task done
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@olets
Copy link

olets commented Jun 16, 2024

Astro Info

My real local example:

Astro                    v4.10.2
Node                     v20.14.0
System                   macOS (arm64)
Package Manager          bun
Output                   server
Adapter                  none
Integrations             none

Minimal reproduction:

Astro                    v4.10.2
Node                     v18.20.3
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

In page frontmatter, an env var condition followed by an import leaves an unterminated string, which breaks the rest of the page.

Checking the participation box because I'm willing, but it doesn't feel like my wheelhouse.

What's the expected result?

Env var use in frontmatter is not more restricted than the use of other values.

Link to Minimal Reproducible Example

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

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jun 16, 2024
@Trombach
Copy link

Trombach commented Jun 16, 2024

Interesting 🤔 If you add a semicolon after the if statement it starts to work again if (import.meta.env.VITE_DEV) {};

@olets
Copy link
Author

olets commented Jun 17, 2024

Hm that doesn't work for me.

Wonder if what you saw is this other unexpected behavior I noticed in the stackblitz but not in my app: if you fix the problem by for example commenting out the if line, and then reintroduce it for example by uncommenting it, the fix sticks — the app continues to build. That does not happen for me in my real app. If I comment out the import, start my app, and uncomment the import, the dev process breaks.

@bluwy
Copy link
Member

bluwy commented Jun 17, 2024

Seems like a compiler issue, you can paste the frontmatter code in https://live-astro-compiler.vercel.app to observe the invalid output.

const $$stdin = $$createComponent(($$result, $$props, $$slots) => {

// good
// if (true) {}

// good
// console.log(import.meta.env.VITE_DEV)

// bad
if (import.meta.env.DEV) {}

/**
 * necessary for bug
 *
'     // <----- the problem


return $$render``;
}, '<stdin>', undefined);
export default $$stdin;

Editing the DEV keyword to DEVVVV or something long/short reveals it's some sort of slicing issue.

@bluwy bluwy transferred this issue from withastro/astro Jun 17, 2024
@bluwy bluwy added - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs triage Issue needs to be triaged labels Jun 17, 2024
@Trombach
Copy link

Trombach commented Jun 17, 2024

@olets Actually, I think I had removed the comment. There was still an error, but a different one. I think the "fix" was only coincidental

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

4 participants
@olets @Trombach @bluwy and others