Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-bats-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scaleway/use-i18n": patch
---

Remove usage of unstable_batch_update from react-dom as it's default behavior of react now
26 changes: 9 additions & 17 deletions packages/use-i18n/src/usei18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
useMemo,
useState,
} from 'react'
import ReactDOM from 'react-dom'
import dateFormat, { type FormatDateOptions } from './formatDate'
import unitFormat, { type FormatUnitOptions } from './formatUnit'
import formatters, { type IntlListFormatOptions } from './formatters'
Expand Down Expand Up @@ -292,22 +291,15 @@ const I18nContextProvider = ({
...result[currentLocale]?.default,
}

// avoid a lot of render when async update
// This is handled automatically in react 18, but we leave it here for compat
// https://github.com/reactwg/react-18/discussions/21#discussioncomment-801703
ReactDOM.unstable_batchedUpdates(() => {
setTranslations(prevState => ({
...prevState,
...{
[currentLocale]: {
...prevState[currentLocale],
...trad,
},
},
}))

setNamespaces(prevState => [...new Set([...prevState, namespace])])
})
setTranslations(prevState => ({
...prevState,
[currentLocale]: {
...prevState[currentLocale],
...trad,
},
}))

setNamespaces(prevState => [...new Set([...prevState, namespace])])

return namespace
},
Expand Down