Automattic / juice

Juice inlines CSS stylesheets into your HTML source.
MIT License
3.1k stars 220 forks source link

Fixed counter-reset not working in combination with inline styles #460

Closed SimonBackx closed 1 year ago

SimonBackx commented 1 year ago

An error is thrown in resetCounter when adding an counter-reset inline style to an element in combination with a different style (e.g., in head).

  1) juice-content/counter-reset:
     Uncaught TypeError: Cannot set properties of undefined (setting 'li')
      at resetCounter (lib/inline.js:167:40)
      at addProps (lib/inline.js:198:15)
      at Element.<anonymous> (lib/inline.js:146:11)
      at LoadedCheerio.each (node_modules/cheerio/lib/api/traversing.js:519:26)
      at handleRule (lib/inline.js:120:9)
      at Array.forEach (<anonymous>)
      at inlineDocument (lib/inline.js:36:9)
      at juiceDocument (lib/inline.js:459:3)
      at module.exports (lib/cheerio.js:61:22)
      at onInline (index.js:63:7)
      at /Users/.../juice/node_modules/web-resource-inliner/src/html.js:281:13

This error is caused by the fact that the addProps method is called when an element doesn't have styleProps (in the if (!el.styleProps) { block), before a default value for counterProps is set. This is fixed by assigning a default value for counterProps before calling addProps.

A test case is also added to reproduce the issue and to prevent future regressions.

naz commented 1 year ago

Hey @jrit , would you be able to release a new version with this change please? 🙏

titanism commented 1 year ago

Bump!

SimonBackx commented 1 year ago

@jrit Sorry to bump this again! Do you mind releasing a new patch version for this? 😊

jrit commented 1 year ago

published!