Skip to content

Locals overwritten when using posthtmlExpressionsOptions #74

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

Closed
steffen-bobek opened this issue Oct 16, 2021 · 0 comments · Fixed by #76
Closed

Locals overwritten when using posthtmlExpressionsOptions #74

steffen-bobek opened this issue Oct 16, 2021 · 0 comments · Fixed by #76

Comments

@steffen-bobek
Copy link

I have a problem since the last release using posthtml-include with parceljs.

My .posthtmlrc:

{
  "plugins": {
    "posthtml-include": {
      "root": "src",
      "posthtmlExpressionsOptions": {
        "strictMode": false
      }
    }
  }
}

I have two HTML files, index.html:

<html>
  <body>
    <include src="partial.html" locals='{ "text": "Hello" }'></include>
    <include src="partial.html" locals='{ "text": "World" }'></include>
  </body>
</html>

and partial.html:

<span>{{ text }}</span>

Running parcel with posthtml-include 1.7.1 generates (as expected):

<html>
  <body>
    <span>Hello</span>
    <span>World</span>
  </body>
</html>

But with posthtml-include 1.7.2 I get:

<html>
  <body>
    <span>Hello</span>
    <span>Hello</span>
  </body>
</html>

The error does only occur if I configure posthtmlExpressionsOptions.

I think the problem is in https://github.com/posthtml/posthtml-include/blob/v1.7.2/lib/index.js line 35 where posthtmlExpressionsOptions.locals are copied over the partial's locals and then stored in posthtmlExpressionsOptions.locals. In the next walk-through posthtmlExpressionsOptions.locals contains the variables from the first run (in my case "Hello") and copies them over the partial's locals (in my case "Hello" over "World").

Maybe it was better to work with a (deep) copy of options.posthtmlExpressionsOptions (in lib/index.js line 23) and leave the original posthtmlExpressionsOptions unchanged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant