formatjs / formatjs-old

The monorepo home to all of the FormatJS related libraries.
https://formatjs.io/
156 stars 53 forks source link

babel-plugin-react-intl doesn't update messages file if the corresponding module no longer contains any "message descriptors" #553

Closed ervasive closed 4 years ago

ervasive commented 4 years ago

Which package? babel-plugin-react-intl

Describe the bug Let's say we have the following module (React component):

import React from "react"
import { FormattedMessage } from "react-intl"

export default () => (
  <FormattedMessage
    id="test"
    defaultMessage="Test message"
    description="sample desc"
  />
)

When we update the FormattedMessage props, babel-plugin-react-intl updates (re-extracts) its values to a messages file (as intended):

[
  {
    "id": "test",
    "description": "sample desc",
    "defaultMessage": "Test message"
  }
]

But if we update the module to the state when it doesn't have any "descriptors" in it, the messages file won't be updated and will contain stale values (instead of being empty):

import React from "react"
import { FormattedMessage } from "react-intl"

export default () => (
  <p>No more FormattedMessage in this component</p>
)
[
  {
    "id": "test",
    "description": "sample desc",
    "defaultMessage": "Test message"
  }
]

To Reproduce I have prepared a codesandbox example running gatsby project.

Steps to reproduce the behavior:

  1. Go to the codesandbox demo project
  2. Open src/pages/index.js
  3. Update FormattedMessage props
  4. Wait for gatsby to rebuild the dev bundle
  5. Check extracted messages in messages/src/pages/index.js (it should reflect the updated values)
  6. Remove the FormattedMessage, so the module does not contain any
  7. Wait for gatsby to rebuild the dev bundle
  8. Check the messages file

Expected behavior The messages file should be empty or contain an empty array

longlho commented 4 years ago

Thanks for reporting! We'll take a look asap.

paulincai commented 4 years ago

Ok, @longlho after updating to 6.1.0 I ended up with 408 extra files which I don't need. What I did was to update the library and start my project in development.

I don't this this was the intended behavior. There are files created for each and every js file I have in my entire project structure, even for files that are just libraries, utilities etc...

Screen Shot 2020-03-19 at 00 21 45

longlho commented 4 years ago

@paulincai should be fixed in latest version

ervasive commented 4 years ago

I've updated the dependency in the codesandbox example to the latest version and unfortunately, it still keeps non-existent (stale) "descriptors" for me in the messages file with v6.2.0 🤷

ervasive commented 4 years ago

NVM, just noticed the new option Thank you for fixing the issue