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

<FormattedMessage> unexpectedly preserves whitespace for its props #104

Closed
lencioni opened this issue Apr 16, 2015 · 3 comments
Closed

<FormattedMessage> unexpectedly preserves whitespace for its props #104

lencioni opened this issue Apr 16, 2015 · 3 comments
Labels

Comments

@lencioni
Copy link
Contributor

Normally, if I have this code:

<span>
  Hi
</span>

React will render something like this in the DOM:

<span data-reactid=".5.3.0.0.0.0.1.0.0.2:$11.1.2.0.1.0">Hi</span>

Now, if I pass that same JSX to <FormattedMessage> like this:

<FormattedMessage
  message={this.getIntlMessage('myMessage')}
  thing={
    <span>
      Hi
    </span>
  }
/>

then something like the following is rendered for the thing prop:

<span data-reactid=".5.3.0.0.0.0.1.0.0.2:$11.1.2.0.1.1.1">
              Hi
            </span>

In many scenarios this might only introduce a single space of unexpected whitespace which usually won't be a deal-breaker. However, if you are using this in conjunction with a style like white-space: pre-line; it can really break the UI.

It would be better if the props that are passed in to <FormattedMessage> were rendered with the same rules that React uses.

@ericf
Copy link
Collaborator

ericf commented Apr 16, 2015

It would be better if the props that are passed in to were rendered with the same rules that React uses.

Nothing special is happening here, elements passed as props simply become children. Are you sure this isn't a JSX thing preserving the source's whitespace when passing an element as props to another component?

@lencioni
Copy link
Contributor Author

Are you sure this isn't a JSX thing preserving the source's whitespace when passing an element as props to another component?

Good call, I just tried this out with a different component and it seems to have the same behavior.

@lencioni
Copy link
Contributor Author

I think the problem might be in Babel. babel/babel#1276

@ericf ericf added invalid and removed needs info labels Apr 16, 2015
longlho pushed a commit that referenced this issue Apr 27, 2020
[Doc] Travis badge should be pointing to master
longlho added a commit that referenced this issue Apr 27, 2020
* chore(babel-plugin-react-intl): add more test to enforceDefaultMessage

* fix(intl-utils): fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants