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

fix(I18nContext): scope context per react major version #7068

Open
wants to merge 1 commit into
base: v1.29.x
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions packages/base/src/context/I18nContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import type I18nBundle from '@ui5/webcomponents-base/dist/i18nBundle.js';
import { createContext, useContext } from 'react';
import { createContext, useContext, version } from 'react';

export const I18nContext = createContext<{
i18nBundles: Record<string, I18nBundle>;
Expand All @@ -11,7 +11,12 @@ export const I18nContext = createContext<{
export const getI18nContext = (): typeof I18nContext => {
globalThis['@ui5/webcomponents-react'] ??= {};
globalThis['@ui5/webcomponents-react'].I18nContext ??= I18nContext;
return globalThis['@ui5/webcomponents-react'].I18nContext;

const reactMajorVersion = version.substring(0, version.indexOf('.'));
globalThis[`@ui5/webcomponents-react/${reactMajorVersion}`] ??= {};
globalThis[`@ui5/webcomponents-react/${reactMajorVersion}`].I18nContext ??= I18nContext;

return globalThis[`@ui5/webcomponents-react/${reactMajorVersion}`].I18nContext;
};

export const useI18nContext = () => useContext(getI18nContext());
Loading