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

fix: no request sent when disableStringsCache:true #97

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sapjax
Copy link

@sapjax sapjax commented Jan 10, 2025

In the origin code, if disableStringsCache is set to true, the getFileTranslations will never be called.

src/index.ts Outdated
if (!!this.stringsCache[filePath]) {
content = await this.stringsCache[filePath];
} else {
content = await this.getFileTranslations(filePath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache stores promises, that's why we have await 2 lines above when extracting it from cache. This is needed to prevent "double" loading. Please update it to:

let content;
if (this.disableStringsCache) {
  content = await this.getFileTranslations(filePath);
} else {
  if (!this.stringsCache[filePath]) {
     this.stringsCache[filePath] = this.getFileTranslations(filePath);
  }
  content = await this.stringsCache[filePath];
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as your comment.
But I don't understand why we need to cache promises instead resolved data, what is the "double" loading case.
The request is already sent, just when to resolve it from promise, should be no difference indeed.

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 this pull request may close these issues.

2 participants