Skip to content

Commit f3fca69

Browse files
authored
Merge pull request #642 from Telegram-Mini-Apps/639-bug-viewportbindcssvars-adds-0px-variables
fix(sdk): fix problems related to signals' tuples and batched updates
2 parents 2f762a3 + 7825425 commit f3fca69

File tree

16 files changed

+40
-39
lines changed

16 files changed

+40
-39
lines changed

.changeset/moody-jokes-rule.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@telegram-apps/sdk": patch
3+
---
4+
5+
Fix problems related to signals' tuples and batched updates

packages/sdk/src/scopes/components/back-button/back-button.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const [_isMounted, isMounted] = createSignalsTuple(false);
2929
*/
3030
export const isSupported = createIsSupported(SETUP_METHOD_NAME);
3131

32-
const wrapComplete = createWrapComplete(COMPONENT_NAME, isMounted, SETUP_METHOD_NAME);
32+
const wrapComplete = createWrapComplete(COMPONENT_NAME, _isMounted, SETUP_METHOD_NAME);
3333
const wrapSupported = createWrapSupported(COMPONENT_NAME, SETUP_METHOD_NAME);
3434

3535
/**
@@ -62,14 +62,14 @@ export const hide = wrapComplete('hide', (): void => {
6262
* }
6363
*/
6464
export const mount = wrapSupported('mount', (): void => {
65-
if (!isMounted()) {
65+
if (!_isMounted()) {
6666
setVisibility(isPageReload() && getStorageValue<StorageValue>(COMPONENT_NAME) || false);
6767
_isMounted.set(true);
6868
}
6969
});
7070

7171
function setVisibility(value: boolean): void {
72-
if (value !== isVisible()) {
72+
if (value !== _isVisible()) {
7373
postEvent(SETUP_METHOD_NAME, { is_visible: value });
7474
setStorageValue<StorageValue>(COMPONENT_NAME, value);
7575
_isVisible.set(value);

packages/sdk/src/scopes/components/biometry/signals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ export const [_state, state] = createSignalsTuple<State>({
1717
/**
1818
* Signal indicating biometry is available.
1919
*/
20-
export const isAvailable = createComputed(() => state().available);
20+
export const isAvailable = createComputed(() => _state().available);

packages/sdk/src/scopes/components/closing-behavior/closing-behavior.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const enableConfirmation = wrapMounted('enableConfirmation', (): void =>
6262
* }
6363
*/
6464
export const mount = wrapBasic('mount', (): void => {
65-
if (!isMounted()) {
65+
if (!_isMounted()) {
6666
setClosingConfirmation(
6767
isPageReload() && getStorageValue<StorageValue>(COMPONENT_NAME) || false,
6868
);
@@ -71,7 +71,7 @@ export const mount = wrapBasic('mount', (): void => {
7171
});
7272

7373
function setClosingConfirmation(value: boolean): void {
74-
if (value !== isConfirmationEnabled()) {
74+
if (value !== _isConfirmationEnabled()) {
7575
postEvent('web_app_setup_closing_behavior', { need_confirmation: value });
7676
setStorageValue<StorageValue>(COMPONENT_NAME, value);
7777
_isConfirmationEnabled.set(value);

packages/sdk/src/scopes/components/init-data/init-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const [_state, state] =
1212

1313
function fromState<K extends keyof InitData>(key: K): Computed<InitData[K] | undefined> {
1414
return createComputed(() => {
15-
const s = state();
15+
const s = _state();
1616
return s ? s[key] : undefined;
1717
});
1818
}

packages/sdk/src/scopes/components/main-button/methods.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const wrapMounted = createWrapMounted(COMPONENT_NAME, isMounted);
3333
* }
3434
*/
3535
export const mount = wrapBasic('mount', (): void => {
36-
if (!isMounted()) {
36+
if (!_isMounted()) {
3737
const prev = isPageReload() && getStorageValue<StorageValue>(COMPONENT_NAME);
3838
prev && internalState.set(prev);
3939
_isMounted.set(true);

packages/sdk/src/scopes/components/mini-app/signals.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const [_backgroundColor, backgroundColor] =
3636
* This value requires the Theme Params component to be mounted to extract a valid RGB value
3737
* of the color key.
3838
*/
39-
export const backgroundColorRGB = rgbBasedOn(backgroundColor);
39+
export const backgroundColorRGB = rgbBasedOn(_backgroundColor);
4040

4141

4242
/**
@@ -52,7 +52,7 @@ export const [_bottomBarColor, bottomBarColor] =
5252
* of the color key.
5353
*/
5454
export const bottomBarColorRGB = createComputed<RGB | undefined>(() => {
55-
const color = bottomBarColor();
55+
const color = _bottomBarColor();
5656
return isRGB(color)
5757
? color
5858
: color === 'bottom_bar_bg_color'
@@ -75,7 +75,7 @@ export const [_headerColor, headerColor] = createSignalsTuple<HeaderColor>('bg_c
7575
* This value requires the Theme Params component to be mounted to extract a valid RGB value
7676
* of the color key.
7777
*/
78-
export const headerColorRGB = rgbBasedOn(headerColor);
78+
export const headerColorRGB = rgbBasedOn(_headerColor);
7979

8080
/**
8181
* True if CSS variables are currently bound.
@@ -99,8 +99,8 @@ export const [_isActive, isActive] = createSignalsTuple(true);
9999
* Complete component state.
100100
*/
101101
export const state = createComputed<State>(() => ({
102-
backgroundColor: backgroundColor(),
103-
bottomBarColor: bottomBarColor(),
104-
headerColor: headerColor(),
105-
isActive: isActive(),
102+
backgroundColor: _backgroundColor(),
103+
bottomBarColor: _bottomBarColor(),
104+
headerColor: _headerColor(),
105+
isActive: _isActive(),
106106
}));

packages/sdk/src/scopes/components/secondary-button/methods.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { createWrapSupported } from '@/scopes/wrappers/createWrapSupported.js';
1313

1414
import { internalState, isMounted, _isMounted, state } from './signals.js';
1515
import type { State } from './types.js';
16+
import { removeUndefined } from '@/utils/removeUndefined.js';
1617

1718
type StorageValue = State;
1819

@@ -39,7 +40,7 @@ export const isSupported = createIsSupported(SETUP_METHOD_NAME);
3940
* }
4041
*/
4142
export const mount = wrapSupported('mount', (): void => {
42-
if (!isMounted()) {
43+
if (!_isMounted()) {
4344
const prev = isPageReload() && getStorageValue<StorageValue>(COMPONENT_NAME);
4445
prev && internalState.set(prev);
4546
_isMounted.set(true);
@@ -108,12 +109,7 @@ export const offClick = wrapSupported(
108109
export const setParams = wrapComplete(
109110
'setParams',
110111
(updates: Partial<State>): void => {
111-
internalState.set({
112-
...internalState(),
113-
...Object.fromEntries(
114-
Object.entries(updates).filter(([, v]) => v !== undefined),
115-
),
116-
});
112+
internalState.set({ ...internalState(), ...removeUndefined(updates) });
117113
setStorageValue<StorageValue>(COMPONENT_NAME, internalState());
118114

119115
// We should not commit changes until the payload is correct. Some version of Telegram will

packages/sdk/src/scopes/components/settings-button/settings-button.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const [_isMounted, isMounted] = createSignalsTuple(false);
3232
export const isSupported = createIsSupported(SETUP_METHOD_NAME);
3333

3434
const wrapSupported = createWrapSupported(COMPONENT_NAME, SETUP_METHOD_NAME);
35-
const wrapComplete = createWrapComplete(COMPONENT_NAME, isMounted, SETUP_METHOD_NAME);
35+
const wrapComplete = createWrapComplete(COMPONENT_NAME, _isMounted, SETUP_METHOD_NAME);
3636

3737
/**
3838
* Hides the Settings Button.
@@ -62,14 +62,14 @@ export const hide = wrapComplete('hide', (): void => {
6262
* }
6363
*/
6464
export const mount = wrapSupported('mount', (): void => {
65-
if (!isMounted()) {
65+
if (!_isMounted()) {
6666
setVisibility(isPageReload() && getStorageValue<StorageValue>(COMPONENT_NAME) || false);
6767
_isMounted.set(true);
6868
}
6969
});
7070

7171
function setVisibility(value: boolean): void {
72-
if (value !== isVisible()) {
72+
if (value !== _isVisible()) {
7373
postEvent(SETUP_METHOD_NAME, { is_visible: value });
7474
setStorageValue<StorageValue>(COMPONENT_NAME, value);
7575
_isVisible.set(value);

packages/sdk/src/scopes/components/swipe-behavior/swipe-behavior.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const isSupported = createIsSupported(SETUP_METHOD_NAME);
3030
export const [_isVerticalEnabled, isVerticalEnabled] = createSignalsTuple(true);
3131

3232
const wrapSupported = createWrapSupported(COMPONENT_NAME, SETUP_METHOD_NAME);
33-
const wrapComplete = createWrapComplete(COMPONENT_NAME, isMounted, SETUP_METHOD_NAME);
33+
const wrapComplete = createWrapComplete(COMPONENT_NAME, _isMounted, SETUP_METHOD_NAME);
3434

3535
/**
3636
* Disables vertical swipes.
@@ -76,7 +76,7 @@ export const enableVertical = wrapComplete('enableVertical', (): void => {
7676
* }
7777
*/
7878
export const mount = wrapSupported('mount', (): void => {
79-
if (!isMounted()) {
79+
if (!_isMounted()) {
8080
setVerticalEnabled(
8181
isPageReload() && getStorageValue<StorageValue>(COMPONENT_NAME) || false,
8282
true,
@@ -86,7 +86,7 @@ export const mount = wrapSupported('mount', (): void => {
8686
});
8787

8888
function setVerticalEnabled(value: boolean, force?: boolean): void {
89-
if (value !== isVerticalEnabled() || force) {
89+
if (value !== _isVerticalEnabled() || force) {
9090
postEvent(SETUP_METHOD_NAME, { allow_vertical_swipe: value });
9191
setStorageValue<StorageValue>(COMPONENT_NAME, value);
9292
_isVerticalEnabled.set(value);

0 commit comments

Comments
 (0)