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

Preact class is ignored #59

Open
bensaufley opened this issue Nov 15, 2022 · 0 comments
Open

Preact class is ignored #59

bensaufley opened this issue Nov 15, 2022 · 0 comments

Comments

@bensaufley
Copy link

First off, thanks for making this! Please let me know if this should go to the SVGR repo, because it's definitely possible.

I'm using Preact and my config in vite.config.ts (sorry, private repo) looks like this:

    svgr({
      exportAsDefault: true,
      svgrOptions: {
        // Types are out of sync with package & docs
        // https://react-svgr.com/docs/options/#jsx-runtime-import-source
        // @ts-ignore
        jsxRuntimeImport: {
          importSource: 'preact',
          specifiers: ['h'],
        },
      },
    }),

Note: I originally used jsxRuntime: 'classic-preact', but for one reason or another (it's been a bit) it didn't work, so that's how I ended up here. As you can see there seem to be some mismatches between docs and the types, at least—maybe the logic, too.

Passing class rather than className, as is the standard in Preact, means the value is effectively ignored. It's a small thing and I can just use className here, but I thought it was worth pointing out.

Expectation

Given foo.svg:

<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="foo default-class" viewBox="0 0 16 16">
  <!---->
</svg>

The following code in Preact:

import Foo from './foo.svg';

<Foo class="bar" />;

Should render:

<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bar" viewBox="0 0 16 16">
  <!---->
</svg>

But it renders:

<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="foo default-class" viewBox="0 0 16 16">
  <!---->
</svg>

The below produces the expected result:

import Foo from './foo.svg';

<Foo className="bar" />;
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

No branches or pull requests

1 participant