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

Listen for namespaces changes and load necessary namespaces #592

Merged
merged 1 commit into from
Apr 25, 2021

Conversation

rihardsgrislis
Copy link
Contributor

Hey,

We've wrapped our App in DynamicNamespaces to load the translation files for each page based on some props but when changing pages the translations are not always loaded. If I reload the page the translations appear. I noticed that the useEffect which loads the translations passes currently [] as the second argument but that means to never call this hook again even if namespaces have changed.

From useEffect documentation:

If you want to run an effect and clean it up only once (on mount and unmount), you can pass an empty array ([]) as a second argument. This tells React that your effect doesn’t depend on any values from props or state, so it never needs to re-run. This isn’t handled as a special case — it follows directly from how the dependencies array always works.

src/DynamicNamespaces.tsx Outdated Show resolved Hide resolved
@aralroca aralroca added this to the 1.0.7 milestone Apr 25, 2021
@aralroca
Copy link
Owner

Thanks for your contribution @rihardssceredins !

@aralroca aralroca merged commit 92ff865 into aralroca:canary Apr 25, 2021
@aralroca
Copy link
Owner

@rihardssceredins I pre-published 1.0.7-canary.2 with this change if you want to start using it! Thanks for the contribution!!

@aralroca
Copy link
Owner

@allcontributors please add @rihardssceredins for code

@allcontributors
Copy link
Contributor

@aralroca

I've put up a pull request to add @rihardssceredins! 🎉

@rihardsgrislis rihardsgrislis deleted the use-effect-load-namespaces branch April 28, 2021 07:37
@rihardsgrislis
Copy link
Contributor Author

@aralroca hey, thanks for the pre-published release! 👍🏼
We tested it on our app but sadly it didn't solve the issue entirely (QA reported that it seemed better but I guess he was just lucky). Will have to dig deeper.

aralroca added a commit that referenced this pull request May 21, 2021
* replace quotes only for the special $' pattern specific to .replace() (#529)

* replace quotes only for the special $' pattern specific to .replace() instead of replacing quoutes everywhere

* use .replace() callback to avoid parsing special string patterns

* write tests to verify that templateWithHoc and templateWithLoader correctly replaces special string cases. Update snapshots

* Update package version

* fix(transCore): when no suffix don't match spaces (#534)

* Update package version

* _one works (#541)

* Update package version

* Update README.md (#552)

* Update package version

* Update dependencies (#554)

* Update dependencies

* Update example deps

* Update Trans text after change lang (#566)

* Ignore api.(ts|js...) file (#567)

* Add useMemo to useTranslation (#574)

* Update deps (#582)

* Update version of package.json

* Adding tests (#585)

* Add new property `extensionsRgx` to config (#589)

* Add new property `extensionsRgx` to config

To be able to use custom Next.js page extensions (vercel/next.js#8454 (comment)), a new property `extensionsRgx` is added to the i18n configuration.

# How to use

// i18n.js

```
module.exports = {
  extensionsRgx: /\.(page|api)\.(tsx|ts|js|mjs|jsx)$/,
  ...
}
```

* docs: add `extensionsRgx` configuration property

* Update package.json

* Listen for `namespaces` changes and load necessary namespaces (#592)

* Update package.json version

* Revert "Add useMemo to useTranslation" (#605)

This reverts commit 8abc458.

# Conflicts:
#	package.json

* Remove console.warn because is already solved on Next.js 10.2.1-canary.4 (#609)

Already fixed in [Next.js canary 10.2.1-canary.4](https://github.com/vercel/next.js/releases/tag/v10.2.1-canary.4)

Co-authored-by: AndrewB <[email protected]>
Co-authored-by: slevy85 <[email protected]>
Co-authored-by: Justin <[email protected]>
Co-authored-by: Bernd Artmüller <[email protected]>
Co-authored-by: Rihards Ščeredins <[email protected]>
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