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.

All translations disappear after any component change its state (preact X)

See original GitHub issue

Hello, I have problems with the latest version of preact:

        "preact": "^10.0.4",
        "preact-i18n": "^2.0.0-preactx.2",
        "preact-router": "^3.1.0",

App.tsx

            // @ts-ignore
            <IntlProvider definition={definition}>
                <Router>
                    <Login path="/login"/>
                    <RedirectToLogin path="/"/>
                    <CommonLayout default/>
                </Router>
            </IntlProvider>
        );

Dom event inside login component:

    onFocusInput(name) {
        const {fieldsMarkedAsInvalid} = this.state;
        fieldsMarkedAsInvalid[name] = false;
        this.setState({fieldsMarkedAsInvalid});
    }

After state is updated, all translations disappear. The same thing occures in any component. Downgrade helped me.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
pl12133commented, Apr 22, 2020

I’ve managed to reproduce this now, it seems that loading the dictionary asynchronously causes an issue. When the IntlProvider has props of definition={undefined} on it’s first render, the stale value will eventually overwrite the new value after a child component calls setState.

Reproduction: https://jsfiddle.net/k8e3fm0n/

Workaround: Add a key={definition} prop to your IntlProvider.

Internally, the child component ends up with a condition of component.context !== component._globalContext which may imply an issue in the diff algorithm for Preact but I’m still investigating.

I’m not sure if there is anything to be done here so I’ll follow up in either preactjs/preact or synacor/preact-context-provider.

0reactions
pl12133commented, Jun 9, 2020

Fixed by a451350 and released in 2.1.1-preactx.

Reproduction fixed: https://jsfiddle.net/xyL04bzm/1/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Differences to React - Preact
What are the differences between Preact and React. This document describes them in detail.
Read more >
Introducing Signals | Preact: Fast 3kb React alternative with ...
Accessing a signal's value property from within a component automatically updates that component when the value of that signal changes.
Read more >
What's new in Preact X
Whereas getChildContext is fine when you're absolutely sure to never change a value, it falls apart as soon as a component in-between the...
Read more >
Testing with Preact Testing Library
Commonly tests check for attributes being present like an input value or that an element appeared/disappeared. To do this, we need to be...
Read more >
State | Preact: Fast 3kb React alternative with the same ES6 ...
When a component updates its state, Preact re-renders that component using the updated state value. For function components, this means Preact will re-invoke ......
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