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

Broken error on improperly nested <li> tag #7720

Closed
1 task
Ducklett opened this issue Jul 19, 2023 · 1 comment
Closed
1 task

Broken error on improperly nested <li> tag #7720

Ducklett opened this issue Jul 19, 2023 · 1 comment
Labels
needs triage Issue needs to be triaged

Comments

@Ducklett
Copy link

What version of astro are you using?

2.8.5

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

None

What package manager are you using?

npm

What operating system are you using?

Windows

What browser are you using?

Chrome

Describe the Bug

I was trying to create a nested header layout when I ran into a vague Unexpected "}" error. Turns out the compiler freaks out when you improperly nest a <li> tag for whatever reason.

Note how in the example below I wrapped the nested <li> in a <div>, it works fine when I replace <div> with <ul>.

Repro:

---
const routes = [
  { path: "/", name: "Home" },
  {
    path: "/projects",
    name: "Projects",
    items: [ 'a', 'b', 'c' ],
  },
];
---

<ul>
	{routes.map(route => (<li>
		{route.name}
		<div>{route.items && route.items.map(item => (<li>{item}</li>) )}</div>
	</li>))}
</ul>

The error and stack trace:

Unexpected "}"

Error: Transform failed with 1 error:
C:/Users/___/hello-astro/src/components/stock/What.astro:38:49: ERROR: Unexpected "}"
    at failureErrorWithLog (C:\Users\___\hello-astro\node_modules\vite\node_modules\esbuild\lib\main.js:1646:15)
    at C:\Users\____\hello-astro\node_modules\vite\node_modules\esbuild\lib\main.js:847:29
    at responseCallbacks.<computed> (C:\Users\____\hello-astro\node_modules\vite\node_modules\esbuild\lib\main.js:703:9)
    at handleIncomingPacket (C:\Users\____\hello-astro\node_modules\vite\node_modules\esbuild\lib\main.js:762:9)
    at Socket.readFromStdout (C:\Users\____\hello-astro\node_modules\vite\node_modules\esbuild\lib\main.js:679:7)
    at Socket.emit (node:events:514:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

What's the expected result?

If astro cannot handle improperly nested <li> tags I would expect a nice error telling me this, something like Error: <li> cannot be a child of <div>, you must wrap it in <ul> or <ol>.

The current error of Unexpected "}" is completely irrelevant to the actual problem.

Link to Minimal Reproducible Example

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

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 Jul 19, 2023
@natemoo-re
Copy link
Member

Yes, this is a problem and we need to fix the irrelevant error message.

We are tracking this in our compiler. withastro/compiler#811

@natemoo-re natemoo-re closed this as not planned Won't fix, can't repro, duplicate, stale Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants