question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incompatible with hot module reload?

See original GitHub issue

First of all, thank you for this work, 😄 it really looks a lot easier to use than react-intl which I find a little overkill for a simple app.

I have a translated view that goes like this:

import React from 'react';
import { translate } from 'react-i18next/lib';

const LoginForm = React.createClass({
    render() {
        const t = this.props.t;
        console.log(t); // <-- we should have the translation fn here
        return (
            <div>
                <h3>{ t('Sign in')}</h3>
                {/*...*/}
            </div>
        );
    }
});

export default translate(['login'])(LoginForm);

On first load and manual reload it works as advertised, displaying the translated message. The console.log(t) call returns something like function fixedT(key, options) {...}, but when I modify something on the component and thus triggering the hot reload module (Webpack), I get undefined and an Uncaught TypeError: t is not a function.

Is there any way to make react-i18next compatible with HMR?

Thanks!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:34 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
jamuhlcommented, Sep 27, 2017

@gnapse you mean if you change something in the translation files you want the hmr to reload your page…not sure if that is possible…as those files are not part of the bundle.

I think the initial issue was a reload based on a change in the component…not translation files.

Personally we moved our translation to the service tier locize.com - so we do no manipulations of translations anymore inside the project repository.

Rather sure there is a way to trigger hmr doing some configurations to watch for the public folder too…but personally i prefer doing create-react-app init - so i might have less knowledge about webpack config…eventual this is a good question for stackoverflow?

1reaction
hollanderbartcommented, Apr 9, 2016

I got it working. Finally. Via this post: https://github.com/i18next/react-i18next/issues/3, I was mentioned this post: https://github.com/ghengeveld/redux/blob/a68768ff8d6a4fbe7b8f6a06a8cf9b99a54aefb0/docs/recipes/WritingTests.md#testing-decorated-react-components

Basically, because in order to test the undecorated component and not the decorated translate component, I had to export the component using: export class ComponentName extends Component { ... } next to the export default translate('common')(ComponentName) at the bottom. Because I export the undecorated component next to the decorated component, I can import the undecorated component in my unit test using import { FilterRow } from '../components/filterRow'; instead of import FilterRow from '../components/filterRow';

Read more comments on GitHub >

github_iconTop Results From Across the Web

process is not defined on hot reload - Stack Overflow
I have a react app made with create react app, and hot reloading kills the page entirely with the error:
Read more >
Hot Module Replacement - webpack
If Hot Module Replacement has been enabled via the HotModuleReplacementPlugin , its interface will be exposed under the module.hot property as well as ......
Read more >
Hot reload fails: "This is likely a stale module that must be ...
(API version -1), but it was incompatible with the current engine API version (0). This is likely a stale module that…
Read more >
Troubleshooting XAML Hot Reload - Visual Studio (Windows)
Stop the debugging session, make the change, and then restart the debugging session. If you find an unsupported scenario that you'd like to...
Read more >
React Hot Loader | Best of JS
Parcel supports Hot Module Reloading out of the box, just follow step 1 and 2 of ... webpack ExtractTextPlugin is not compatible with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found