gilbsgilbs / babel-plugin-i18next-extract

Babel plugin that statically extracts i18next and react-i18next translation keys.
https://i18next-extract.netlify.com
MIT License
161 stars 37 forks source link

Race condition in extract #232

Closed iDVB closed 2 years ago

iDVB commented 2 years ago

We are seeing what appears to be a race condition with extract. It does not consistently deliver the common.json locale file if ran more than once.

How to reproduce https://github.com/iDVB/i18next-extract-issue

  1. Setup and run extract

    git clone https://github.com/iDVB/i18next-extract-issue 
    cd i18next-extract-issue
    yarn install
    yarn extract
  2. Inspect i18next-extract-issue/locales/en-US/common.json It should have one of two results:

    {
    "InlineComponent": "InlineComponent",
    "InlineComponent #2": "InlineComponent #2"
    }

    OR

    {
    "MyComponent Trans": "MyComponent Trans"
    }
  3. Continue to rerun yarn extract while watching that same file and you should notice that intermittently it will produce one of the two results above. Back and forth in no apparent order and seems random. This appears to point to some kind of race condition.

Expected behavior

All 3x nodes are extracted to JSON file.

What actually happens

It flips back and forth between producing one of the outcomes or the other.

Your environment

gilbsgilbs commented 2 years ago

Thanks for the repro project. I think the source files are missing in it though, extraction doesn't work (src/**/*.{js,jsx,ts,tsx} does not exist).

However, I see that discardOldKeys is set to true in your config, and there was a fix related to this option in the latest pre-release (0.9.0-rc.1). Would you mind trying with it?

iDVB commented 2 years ago

Sorry, the src files are now added. Going to try the RC version as well.

iDVB commented 2 years ago

@gilbsgilbs Yup! That RC (0.9.0-rc.1) fixed the issue. The output now contains ALL nodes:

{
  "InlineComponent": "InlineComponent",
  "InlineComponent #2": "InlineComponent #2",
  "MyComponent Trans": "MyComponent Trans"
}

Any idea what that version is set to full release?

gilbsgilbs commented 2 years ago

Just deployed it: https://www.npmjs.com/package/babel-plugin-i18next-extract/v/0.9.0