withastro / compiler

The Astro compiler. Written in Go. Distributed as WASM.
Other
496 stars 59 forks source link

🐛 BUG: panic: html: bad parser state: originalIM was set twice #361

Closed patrickdung closed 2 years ago

patrickdung commented 2 years ago

What version of @astrojs/compiler are you using?

0.14.1

What package manager are you using?

npm

What operating system are you using?

Linux

Describe the Bug

On astro 1.0.0 beta 8, please refer to the code below. If I remove <meta property="test2" content="test2"/> and use <htmlhello> it is ok. If I enable the block <meta property="test2" content="test2"/>, the parse crashed. I tried to create a minimal repository to replicate the problem but that repo runs fine. It occurred on the blog with lots of components and layout, unfortunately I may not want to expose the repo at the moment.

panic: html: bad parser state: originalIM was set twice

goroutine 9 [running]:
github.com/withastro/compiler/internal.(*parser).setOriginalIM(...)
        github.com/withastro/compiler/internal/parser.go:531
github.com/withastro/compiler/internal.inHeadIM(0x47a480)
        github.com/withastro/compiler/internal/parser.go:910 +0x227
github.com/withastro/compiler/internal.(*parser).parseCurrentToken(0x47a480)
        github.com/withastro/compiler/internal/parser.go:2782 +0x13
github.com/withastro/compiler/internal.(*parser).parse(0x47a480)
        github.com/withastro/compiler/internal/parser.go:2809 +0x3
github.com/withastro/compiler/internal.ParseWithOptions({0x6f980, 0x430220}, {0x0, 0x0, 0x0})
        github.com/withastro/compiler/internal/parser.go:2869 +0x18
github.com/withastro/compiler/internal.Parse(...)
        github.com/withastro/compiler/internal/parser.go:2826
main.Transform.func1.1.1({0x4f1200, 0x876}, 0x4482d0, {{}, 0x7ff800040000003c, 0x411420})
        ./astro-wasm.go:186 +0xb
created by main.Transform.func1.1
        ./astro-wasm.go:183 +0x3
exit code: 2
Error: Uh oh, the Astro compiler encountered an unrecoverable error!

    Please open
    a GitHub issue using the link below:
    https://github.com/withastro/astro/issues/new?labels=compiler&title=%F0%9F%90%9B+BUG%3A+%60%40astrojs%2Fcompiler%60+panic&body=%23%23%23+Describe+the+Bug%0A++++%0A++++%60%40astrojs%2Fcompiler%60+encountered+an+unrecoverable+error+when+compiling+the+following+file.%0A++++%0A++++**src%2Flayouts%2FBaseLayout.astro**%0A++++%60%60%60astro%0A++++---%0A%2F%2F+1st+method%0A%2F%2Fimport+%7B+NAV_ITEMS+%7D+from+%27..%2Fconfig.ts%27%0A%2F%2F+2nd+method%0A%2F%2Fimport+%7B+NAV_ITEMS+as+navItems+%7D+from+%27..%2Fconfig.ts%27%0A%0Aimport+BaseHead+from+%27%24components%2FBaseHead.astro%27%3B%0Aimport+Nav+from+%27%24components%2FNav.astro%27%0Aimport+Header+from+%27%24components%2FHeader.astro%27%0Aimport+Footer+from+%27%24components%2FFooter.astro%27%3B%0Aimport+CommonStyle+from+%27%24components%2FCommonStyle.astro%27%3B%0A%2F%2Fimport+CommonSettings+from+%27%24components%2FCommonSettings.astro%27%3B%0Aimport+%27%24styles%2Fmeilisearch.css%27%0A%0Aconst+%7B+title%2C+description%2C+cover_image%2C%0A++canonicalURL%2CarticlePublishedISO%2C+articleModifiedISO+%7D+%3D+Astro.props%3B%0A%0A%2F%2F+1st+method%0A%2F%2Fconsole.log+%28%7BNAV_ITEMS%7D%29%0A%2F%2Fconsole.log+%28%7BNAV_ITEMS%7D.NAV_ITEMS.home.path%2C+%7BNAV_ITEMS%7D.NAV_ITEMS.home.title%29%0A%2F%2F+2nd+method%0A%2F%2Fconsole.log+%28navItems.home.path%2C+navItems.home.title%29%0A%2F*%0Afor+%28var+key+of+Object.keys%28navItems%29%29+%7B%0A++%09console.log%28%22Nav+item+%23%22%2C+navItems%5Bkey%5D.path%2C+navItems%5Bkey%5D.title%29%0A%7D%0A*%2F%0A---%0A%0A%3Chtml+lang%3D%22en%22%3E%0A++%3Chead+prefix%3D%22og%3A+https%3A%2F%2Fogp.me%2Fns%23+article%3A+https%3A%2F%2Fogp.me%2Fns%2Farticle%23%22%3E%0A++++%3Cslot+name%3D%22baseHeadExtension%22%3E%0A++++++%3C%21--%3Chtmlhello%3E%3C%2Fhtmlhello%3E--%3E%0A++++++%3Cmeta+property%3D%22test2%22+content%3D%22test2%22%2F%3E%0A++++%3C%2Fslot%3E%0A++++%3CCommonStyle%2F%3E%0A++++%3CBaseHead+title%3D%7Btitle%7D+description%3D%7Bdescription%7D%0A++++++cover_image%3D%7Bcover_image%7D+canonicalURL%3D%7BcanonicalURL%7D%3E%0A++%09%3C%2FBaseHead%3E%0A++++%7BarticlePublishedISO+%26%26%0A++++++%3Cmeta+property%3D%22article%3Apublished_time%22+content%3D%60%24%7BarticlePublishedISO%7D%60%3E%0A++++%7D%0A++++%7BarticleModifiedISO+%26%26+%0A++++++%3Cmeta+property%3D%22article%3Amodified_time%22+content%3D%60%24%7BarticlePublishedISO%7D%60%3E%0A++++%7D%0A++%3C%2Fhead%3E%0A++%3Cbody+class%3D%22dark+antialiased+min-h-screen+scroll-smooth%22%3E%0A++++%3C%21--+Also+check+the+setting+in+ArticleLayout.astro+--%3E%0A++++%3C%21--%3Cdiv+class%3D%22transition-colors+mx-auto+max-w-4xl+px-4+md%3Apx-0%22%3E--%3E%0A++++%3C%21--%3Cdiv+class%3D%22transition-colors+mx-auto+max-w-5xl+px-4+md%3Apx-0%22%3E--%3E%0A++++%3Cdiv+class%3D%22transition-colors+mx-auto+max-w-6xl+px-4+md%3Apx-0%22%3E%0A++++%3C%21--%3Cdiv+class%3D%22transition-colors+mx-auto+max-w-screen-md+px-4+md%3Apx-0%22%3E--%3E%0A++++++%3CHeader%2F%3E%0A++++++%3CNav%2F%3E%0A++++++%3Cmain+class%3D%22js-post-content+px-2%22%3E%0A++++++++%3Cslot%3E%0A++++++++++%3Cp%3EMain+page+content+goes+here.%3C%2Fp%3E%0A++++++++%3C%2Fslot%3E%0A++++++%3C%2Fmain%3E%0A++++++%3CFooter%2F%3E%0A++++%3C%2Fdiv%3E%0A++++%3C%21--%3CCommonSettings%2F%3E--%3E%0A++%3C%2Fbody%3E%0A%3C%2Fhtml%3E%0A%0A++++%60%60%60%0A++++
import BaseHead from '$components/BaseHead.astro';

---

<html lang="en">
  <head prefix="og: https://ogp.me/ns# article: https://ogp.me/ns/article#">
    <slot name="baseHeadExtension">
      <!--<htmlhello></htmlhello>-->
      <meta property="test2" content="test2"/>
    </slot>
    <CommonStyle/>
    <BaseHead title={title} description={description}
      cover_image={cover_image} canonicalURL={canonicalURL}>
    </BaseHead>
    {articlePublishedISO &&
      <meta property="article:published_time" content=`${articlePublishedISO}`>
    }
    {articleModifiedISO &&
      <meta property="article:modified_time" content=`${articlePublishedISO}`>
    }
  </head>
...
---

Link to Minimal Reproducible Example

TBD

natemoo-re commented 2 years ago

Thanks for opening an issue! I think I know where this is happening, I'll try to take a look ASAP.