All translations disappear after any component change its state (preact X)
See original GitHub issueHello, 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:
- Created 4 years ago
- Comments:7 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve managed to reproduce this now, it seems that loading the dictionary asynchronously causes an issue. When the
IntlProvider
has props ofdefinition={undefined}
on it’s first render, the stale value will eventually overwrite the new value after a child component callssetState
.Reproduction: https://jsfiddle.net/k8e3fm0n/
Workaround: Add a
key={definition}
prop to yourIntlProvider
.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.
Fixed by a451350 and released in
2.1.1-preactx
.Reproduction fixed: https://jsfiddle.net/xyL04bzm/1/