posthtml / posthtml-modules

Modules Plugin
MIT License
84 stars 11 forks source link

Content gets not rendered #86

Closed may17 closed 2 years ago

may17 commented 2 years ago

Hi seems like that the content gets not rendered correctly? Maybe i did something wrong?

This is my module

<a href="{{ url }}" class="mt-3 text-sm text-indigo-500">
  <content></content>
</a>

I use my module like this:

<module href="/doclink.html" locals='{"url": "https://tooanywebpage.org/"}'>Foobar</module>

The rendered result will be

<a href="https://tooanywebpage.org/" class="mt-3 text-sm text-indigo-500">
  <content></content>
</a>
gavmck commented 2 years ago

Same issue here, looks like the matcher returns { tag: 'content', attrs: {} }, which fails, but { tag: 'content' } seems to work. Spent a couple of hours digging, but not sure where the exact failure point is.

cossssmin commented 2 years ago

Hmm I think the recently-released posthtml-match-helper (1.0.2) might be what's causing it. Just tested with 1.0.1 and it all works as expected.

@phloe can you please check and let us know, I can also confirm I'm getting <content></content> output as-is with the latest posthtml-match-helper that posthtml-modules depends on.

cossssmin commented 2 years ago

So this is where we try to replace the <content> tag with what you pass into the module:

https://github.com/posthtml/posthtml-modules/blob/c608fbf719950d4138b941f6e8e656b47aebb198/index.js#L82

Given that this code above it works to match the tag:

https://github.com/posthtml/posthtml-modules/blob/c608fbf719950d4138b941f6e8e656b47aebb198/index.js#L71

... I wonder if that missing attribute is what's causing it.

cossssmin commented 2 years ago

Created #87 to get started with fixing this, though I'm not really sure how to go about it 🤔

I've updated the dependencies just in case, so we're working with current versions and are not running into any old bugs that may have been fixed. @Scrum if you could also have a look, please.

gavmck commented 2 years ago

Locally, I've installed posthtml-matcher-helper@1.0.1 to bypass the issue whilst you're looking at it.

cossssmin commented 2 years ago

Yeah, that works as a workaround 👍

We'll need to get this fixed though as it's currently breaking for everyone and they might have no clue where it's coming from since there are no errors or anything...

phloe commented 2 years ago

The error is in posthtml-match-helper? Yikes.

The 1.0.2 bump was only supposed to have added TypeScript types...

cossssmin commented 2 years ago

Yeah, can't understand what's causing it but 1.0.1 does work fine 🤔

phloe commented 2 years ago

I hope it's fixed now with posthtml-match-helper@1.0.3

New bug was attrs was always added to the match object:

match('content') // -> { tag: 'content', attrs: {} }

used to be

match('content') // -> { tag: 'content' }

failing to match tags with no attributes - but matching if they had any.

Also - empty attributes never worked (not a new bug - but fixed in 1.0.3):

match('content[]')
cossssmin commented 2 years ago

Thanks Rasmus, appreciate the fast response! Bumped it in #87 and tests are passing again 👍

Would you maybe consider adding some tests to posthtml-match-helper so we minimize the risk of such issues? 🙏

phloe commented 2 years ago

YES! 😅

cossssmin commented 2 years ago

@may17 and @gavmck can you please confirm that 1.0.3 now works for you as well? Thanks!

gavmck commented 2 years ago

@cossssmin Works for me on 1.0.3 ✅

may17 commented 2 years ago

Sorry for the delayed response. Works as expected now! Thx a lot.