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

Side effects when setting the theme using '@pintora/cli' render function #215

Open
tex0l opened this issue Dec 11, 2023 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@tex0l
Copy link

tex0l commented Dec 11, 2023

When using consecutively the render function from @pintora/cli, parameters set on the pintoraConfig in previous function calls pollute the next calls:

import { render } from '@pintora/cli'
import * as fs from 'fs'

const buildDark = async (code) => {
  const str = await render({
    code: code,
    pintoraConfig: {
      themeConfig: {
        theme: 'dark'
      }
    },
    mimeType: 'image/png',
  })
  fs.writeFileSync('dark.png', str)
}

const buildDefault = async (code) => {
  const buf = await render({
    code: code,
    mimeType: 'image/png',
  })
  fs.writeFileSync('default.png', buf)
}

const code = `
activityDiagram
start
:render functionl called;
if (is mimeType image/svg+xml ?) then
  :renderer svg;
  :render with jsdom;
  :generate string;
else (no)
  :renderer canvas;
  :render with node-canvas;
  :generate image buffer by mimeType;
endif

:return result;

end
`

buildDark(code)

buildDefault(code)

It produces two files dark.png which uses the dark theme, and default.png which should use the default theme but does not: it uses also the dark theme.

However, if the same code is executed without calling buildDark or with buildDark called after buildDefault it works as expected.

@hikerpig hikerpig added the bug Something isn't working label Dec 12, 2023
@hikerpig
Copy link
Owner

hikerpig commented Dec 12, 2023

Thank you for the feedback . @pintora/cli calls @pintora/standalone which holds a global config so it does have side effect .
But I think this need be fixed properly, at least from @pintora/cli. Let me see what can I do.

@hikerpig hikerpig added enhancement New feature or request and removed bug Something isn't working labels Dec 17, 2023
@hikerpig
Copy link
Owner

Eliminating side effect in config requires quite some efforts in current architecture, I'm working on it but it may takes some time.
In the meanwhile you may need to avoid the buggy behavior by passing the whole config object to the render function.

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

No branches or pull requests

2 participants