gilbsgilbs / babel-plugin-i18next-extract

Babel plugin that statically extracts i18next and react-i18next translation keys.

Home Page:https://i18next-extract.netlify.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Race condition in extract

iDVB opened this issue · comments

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
  1. 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"
}
  1. 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

  • OS (e.g. ArchLinux): 12.0.1
  • Plugin version (e.g. 0.3.0): 0.8.3
  • Node version (e.g. 12.13.0): v16.13.1

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?

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

@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?