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

className attribute is always overwritten regardless of what lineProps returns #391

Open
Zo0x opened this issue Apr 19, 2021 · 1 comment · May be fixed by #422
Open

className attribute is always overwritten regardless of what lineProps returns #391

Zo0x opened this issue Apr 19, 2021 · 1 comment · May be fixed by #422

Comments

@Zo0x
Copy link

Zo0x commented Apr 19, 2021

Describe the bug
lineProps is currently unable to set the className because its always overwritten, regardless of what lineProps does.

var properties = typeof lineProps === 'function' ? lineProps(lineNumber) : lineProps;
properties['className'] = className;

https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/src/highlight.js#L108

A super-simple fix would be to simply change those two lines to this:

var properties = {className: className, ...typeof lineProps === 'function' ? lineProps(lineNumber) : lineProps};

This affects both Prism and Highlight.js, as well as countless third-party dependencies that use this behaviour to change props on a per-line basis.

This is currently making this package, as well as those that rely on it, completely unusable for me, is there any sort of roadmap as to when this issue is going to be resolved?

To Reproduce
Steps to reproduce the behavior:

  1. set className using lineProps
  2. value is always overwritten

Expected behavior
Class names set in lineProps shouldn't be blindly overwritten.

d-fischer added a commit to d-fischer/react-syntax-highlighter that referenced this issue Aug 10, 2021
@d-fischer d-fischer linked a pull request Aug 10, 2021 that will close this issue
@shughes-uk
Copy link

React will complain at you but a workaround is possible by passing

lineProps={{class:"class-name"}

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.

2 participants