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

[BREAKING CHANGE] feat: SSR, AppRoot: get rid of classes mutation on html elements #7739

Merged
merged 91 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
bb23335
Move most of common.css styles to AppRoot
andrey-medvedev-vk Oct 4, 2024
bf3bcb5
Create PortalRoot on demand
andrey-medvedev-vk Oct 8, 2024
361174f
Use transformForPositionFixedElements only on AppRoot
andrey-medvedev-vk Oct 9, 2024
a074b94
Don't render PortalRoot when usePortal is passed
andrey-medvedev-vk Oct 10, 2024
e3f6422
Remove useIsClient from AppRootPortal
andrey-medvedev-vk Oct 11, 2024
17a1a3d
Use AppRootPortal directly in the ModalRoot/PopoutRoot/ActionSheet
andrey-medvedev-vk Oct 11, 2024
8c2d80f
Always render ModalRoot through portal after content
andrey-medvedev-vk Oct 11, 2024
6107c26
Create ModalPopoutPortal to keep previous logic of SplitLayout
andrey-medvedev-vk Oct 11, 2024
0734f47
Use ModalPopoutPortal in Alert and ActionSheet
andrey-medvedev-vk Oct 11, 2024
a952164
Render popouts and modals in portal
andrey-medvedev-vk Oct 11, 2024
76451ae
Apply required changes to VKUI examples
andrey-medvedev-vk Oct 11, 2024
59bf3a4
Avoid object assign with spread if possible
andrey-medvedev-vk Oct 30, 2024
042e6a9
Better wording explanation of AppRootStyleContainer
andrey-medvedev-vk Oct 30, 2024
f3b392d
Remove modal/popout from SplitLayout
andrey-medvedev-vk Oct 30, 2024
654adaf
Mark ModalPopoutPortal private
andrey-medvedev-vk Oct 30, 2024
6f73d77
Use SplitLayout value in usePortal
andrey-medvedev-vk Oct 30, 2024
f797b5c
Just use SplitLayout host ref as mount point for modals/popouts
andrey-medvedev-vk Oct 30, 2024
cc3e6fc
Improve comment about AppRootPortal unmount
andrey-medvedev-vk Oct 30, 2024
31b11c4
Trying to avoid extra divs whenever possible
andrey-medvedev-vk Oct 30, 2024
9315844
Use more explicit name for disablePortal logic
andrey-medvedev-vk Oct 31, 2024
767df41
Correct playwright index.html classes
andrey-medvedev-vk Oct 31, 2024
f9bd67f
Let ModalCard render without portal in e2e
andrey-medvedev-vk Oct 31, 2024
c6c8e74
Revert "Remove modal/popout from SplitLayout"
andrey-medvedev-vk Nov 1, 2024
259e783
Keep render modal/popout if they are passed
andrey-medvedev-vk Nov 1, 2024
3b4813c
Allow to control usePortal in ModalRootDesktop
andrey-medvedev-vk Nov 1, 2024
3454164
Setup classes on html for styleguide
andrey-medvedev-vk Nov 6, 2024
3101f29
Properly apply playwright stable font setup
andrey-medvedev-vk Nov 7, 2024
a82a673
Fix Textarea e2e
andrey-medvedev-vk Nov 7, 2024
7373fbe
Automatically apply tokens to html element
andrey-medvedev-vk Nov 15, 2024
2b7d633
Add ui mode for playwright
andrey-medvedev-vk Nov 18, 2024
8add10f
Update Snackar playground
andrey-medvedev-vk Nov 18, 2024
2935130
Return AppRoot wrapper to e2e playground of Snackbar
andrey-medvedev-vk Nov 19, 2024
ad47d71
Add TODO for background
andrey-medvedev-vk Nov 19, 2024
d153050
Fix generate_env -u option
andrey-medvedev-vk Nov 19, 2024
58fb1db
Update Snackbar screenshots on android
andrey-medvedev-vk Nov 19, 2024
c4f439a
Update Textarea snapshots
andrey-medvedev-vk Nov 19, 2024
61f0c91
Fix Slider screenshot tests
andrey-medvedev-vk Nov 19, 2024
c358493
Update Slider screenshots
andrey-medvedev-vk Nov 19, 2024
1354d72
Use alternative AppWrapper for e2e Search component
andrey-medvedev-vk Nov 19, 2024
b09838b
Update Snackbar screenshots
andrey-medvedev-vk Nov 19, 2024
eaf6b53
Fix horizontal scroll e2e setup
andrey-medvedev-vk Nov 19, 2024
2f83e85
Fix AppRoot unit tests
andrey-medvedev-vk Nov 20, 2024
b9ab1aa
Fix AppRootPortal tests
andrey-medvedev-vk Nov 20, 2024
07d5a3d
Fix background of ModalRootDesktop
andrey-medvedev-vk Nov 20, 2024
6bde86e
Fix AppRoot test due to changes in AppRootPortal interface
andrey-medvedev-vk Nov 20, 2024
c6805fb
Disable portal for Alert e2e
andrey-medvedev-vk Nov 20, 2024
0fa459e
Disable portal in ActionSheet/ModalCard
andrey-medvedev-vk Nov 20, 2024
16b86e1
Remove AppRootDefault from e2e
andrey-medvedev-vk Nov 21, 2024
aea525f
Update wording
andrey-medvedev-vk Nov 21, 2024
bb17831
Add usePortal for Alert
andrey-medvedev-vk Nov 21, 2024
cca80a4
Add usePortal to ScreenSpinner
andrey-medvedev-vk Nov 21, 2024
ad38503
Revert "Setup classes on html for styleguide"
andrey-medvedev-vk Nov 21, 2024
c0242d5
Remove from Frame.js additional code
andrey-medvedev-vk Nov 21, 2024
9585bf6
Remove portalRoot creation in body
andrey-medvedev-vk Nov 22, 2024
a9e2de9
Remove portalRoot cleanup from AppRootPortal
andrey-medvedev-vk Nov 22, 2024
03959e7
Remove ModalPopoutPortalRoot
andrey-medvedev-vk Nov 24, 2024
6d8e8ea
Run CustomSelect test without portal
andrey-medvedev-vk Nov 25, 2024
80e7eb6
Format Frame.js
andrey-medvedev-vk Nov 25, 2024
2c22e00
Fix CustomSelect test
andrey-medvedev-vk Nov 25, 2024
6d76157
CHORE: Update screenshots
actions-user Nov 25, 2024
0cbfefe
Remove usage of useObjectMemo
andrey-medvedev-vk Nov 25, 2024
17e5d90
Specify background explicitly
andrey-medvedev-vk Nov 25, 2024
122bef0
Remove debug from CustomSelect tests
andrey-medvedev-vk Nov 25, 2024
fdba676
CHORE: Update screenshots
actions-user Nov 25, 2024
a0b824d
Remove extra class from playwright
andrey-medvedev-vk Nov 26, 2024
6c5a8c1
Move geometry styles back to AppRoot
andrey-medvedev-vk Nov 26, 2024
4ceb46f
Open ports in UI mode only for localhost
andrey-medvedev-vk Nov 26, 2024
dd93d0f
Pass component styles direct to baseStyle
andrey-medvedev-vk Nov 26, 2024
3f1df0e
Pass host styles to AppRoot
andrey-medvedev-vk Nov 26, 2024
5558fc5
Remove AppRoot background setup based on sizeX
andrey-medvedev-vk Nov 26, 2024
c50c7fc
Fix typo in doc
andrey-medvedev-vk Nov 26, 2024
c6b840a
Add dots to doc
andrey-medvedev-vk Nov 26, 2024
72c6569
Add to html plain/card classes
andrey-medvedev-vk Nov 26, 2024
5beab09
Fix ActionSheet transparent overlay in menu mode
andrey-medvedev-vk Nov 26, 2024
452f9d6
Fix ActionSheet tests
andrey-medvedev-vk Nov 27, 2024
9555ea1
Remove decorators from Epic e2e test
andrey-medvedev-vk Nov 27, 2024
282e628
Use AppDefaultWrapper for HorizontalScroll
andrey-medvedev-vk Nov 27, 2024
32d42e8
Move host styles back to root of ModalRoot
andrey-medvedev-vk Nov 27, 2024
1289660
CHORE: Update screenshots
actions-user Nov 27, 2024
1986404
Check that screenshots are passing
andrey-medvedev-vk Nov 27, 2024
3f7e0f8
Simplify Slider e2e test and use Playwright default colors
andrey-medvedev-vk Nov 27, 2024
6328355
Disable only border in disableDecorators
andrey-medvedev-vk Nov 27, 2024
65d9eeb
CHORE: Update screenshots
actions-user Nov 27, 2024
2d1bfc6
Use AppRootWrapper for Snackbar
andrey-medvedev-vk Nov 27, 2024
6042c75
Pass layout prop to sync classes hook
andrey-medvedev-vk Nov 27, 2024
a51a298
Rename AppDefaultWrapper props
andrey-medvedev-vk Nov 27, 2024
d3344c3
Reduce animation in PanelHeaderContext e2e
andrey-medvedev-vk Nov 27, 2024
0ed145d
Fix typo in AppRoot doc.
andrey-medvedev-vk Nov 27, 2024
57d6a1d
Move memo of safeAreaInsets to helper hook
andrey-medvedev-vk Nov 28, 2024
4fd6ae5
Fix typo
andrey-medvedev-vk Nov 28, 2024
fad1174
Fix contextCallback check in tests
andrey-medvedev-vk Nov 28, 2024
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
6 changes: 5 additions & 1 deletion packages/vkui/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ services:
package_vkui:
image: ${IMAGE}
ipc: host
extra_hosts:
- host.docker.internal:host-gateway # allows network calls between docker container and the host. See https://forums.docker.com/t/how-to-reach-localhost-on-host-from-docker-container/113321
user: root
working_dir: /repo/packages/vkui
command: sh -c "
corepack enable &&
YARN_ENABLE_SCRIPTS=false yarn install --immutable &&
yarn run test:e2e:ci ${UPDATE_SNAPSHOTS_FLAG:-}
yarn run ${RUN_SCRIPT_COMMAND:-test:e2e:ci} ${UPDATE_SNAPSHOTS_FLAG:-}
andrey-medvedev-vk marked this conversation as resolved.
Show resolved Hide resolved
"
volumes:
- ../../:/repo
Expand All @@ -25,6 +27,8 @@ services:
- /repo/.cache
- /repo/.swc
- /repo/packages/vkui/.swc
ports:
- 127.0.0.1:4300:4300

volumes:
yarn_cache:
Expand Down
2 changes: 2 additions & 0 deletions packages/vkui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
"test:e2e": "../../scripts/generate_env_docker.sh && docker compose --env-file=./.env.docker up --abort-on-container-exit",
"test:e2e-update": "../../scripts/generate_env_docker.sh -u && docker compose --env-file=./.env.docker up --abort-on-container-exit",
"test:e2e:ci": "yarn run -T cross-env NODE_OPTIONS='--no-warnings' playwright test --config playwright-ct.config.mjs",
"test:e2e:ci:ui": "yarn run -T cross-env NODE_OPTIONS='--no-warnings' playwright test --ui --ui-port=4300 --ui-host=0.0.0.0 --config playwright-ct.config.mjs",
"test:e2e:ui": "../../scripts/generate_env_docker.sh -r test:e2e:ci:ui && docker compose --env-file=./.env.docker up --abort-on-container-exit",
andrey-medvedev-vk marked this conversation as resolved.
Show resolved Hide resolved
"test:e2e-update:ci": "yarn run test:e2e:ci --update-snapshots",
"lint:generated-files": "yarn run -T tsc scripts/generateCSSCustomMedias.mjs --checkJs --module ESNext --moduleResolution node --resolveJsonModule --allowSyntheticDefaultImports --jsx react-jsx --noEmit && yarn run generate:css-custom-medias && git diff --exit-code src/styles/customMedias.generated.css",
"storybook": "bash -c 'source .env && yarn run -T cross-env SANDBOX=\\.storybook storybook dev -p ${STORYBOOK_DEV_PORT:=6006}'",
Expand Down
2 changes: 1 addition & 1 deletion packages/vkui/playwright/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}

/* Зашиваем конкретный шрифт, чтобы от платформы к платформе шрифт сильно не отличался. */
.vkui__root {
.vkuiTestAppRoot {
--vkui--font_family_base: 'Roboto' !important;
--vkui--font_family_accent: 'Roboto' !important;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Icon28SettingsOutline } from '@vkontakte/icons';
import { noop } from '@vkontakte/vkjs';
import {
AppDefaultWrapper,
type AppWrapperProps,
type AppDefaultWrapperProps,
ComponentPlayground,
type ComponentPlaygroundProps,
TEST_CLASS_NAMES,
Expand All @@ -12,8 +12,8 @@ import { usePlatform } from '../../hooks/usePlatform';
import { ActionSheetItem } from '../ActionSheetItem/ActionSheetItem';
import { ActionSheet, type ActionSheetProps } from './ActionSheet';

const AppWrapper = ({ children, ...restProps }: AppWrapperProps) => (
<AppDefaultWrapper scroll="contain" {...restProps}>
const AppWrapper = ({ children, ...restProps }: AppDefaultWrapperProps) => (
<AppDefaultWrapper disablePortal scroll="contain" {...restProps}>
{children}
</AppDefaultWrapper>
);
Expand All @@ -29,10 +29,15 @@ const ActionSheetWrapper = (props: ActionSheetProps) => {
</button>
<ActionSheet
{...props}
style={{
// Перебиваем "absolute", чтобы не задавать фиксированную высоту для тестов под iOS и Android
position: 'relative',
}}
style={
platform === 'vkcom'
? undefined
: {
// Перебиваем "absolute", чтобы не задавать фиксированную
// высоту для тестов под iOS и Android
position: 'relative',
}
}
toggleRef={toggleRef}
onClose={noop}
/>
Expand Down
28 changes: 14 additions & 14 deletions packages/vkui/src/components/ActionSheet/ActionSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { noop } from '@vkontakte/vkjs';
import { useAdaptivityWithJSMediaQueries } from '../../hooks/useAdaptivityWithJSMediaQueries';
import { usePlatform } from '../../hooks/usePlatform';
import { useCSSKeyframesAnimationController } from '../../lib/animation';
import { AppRootPortal } from '../AppRoot/AppRootPortal';
import { useScrollLock } from '../AppRoot/ScrollContext';
import { PopoutWrapper } from '../PopoutWrapper/PopoutWrapper';
import { Footnote } from '../Typography/Footnote/Footnote';
Expand Down Expand Up @@ -137,20 +138,19 @@ export const ActionSheet = ({
</ActionSheetContext.Provider>
);

if (mode === 'menu') {
return actionSheet;
}

return (
<PopoutWrapper
closing={Boolean(closingBy)}
alignY="bottom"
className={className}
style={style}
onClick={onCloseWithOther}
fixed
>
{actionSheet}
</PopoutWrapper>
<AppRootPortal>
<PopoutWrapper
noBackground={mode === 'menu'}
closing={Boolean(closingBy)}
alignY="bottom"
className={className}
style={style}
onClick={onCloseWithOther}
fixed
>
{actionSheet}
</PopoutWrapper>
</AppRootPortal>
);
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions packages/vkui/src/components/Alert/Alert.e2e-playground.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
AppDefaultWrapper,
type AppWrapperProps,
type AppDefaultWrapperProps,
ComponentPlayground,
type ComponentPlaygroundProps,
} from '@vkui-e2e/playground-helpers';
import { Alert, type AlertActionInterface, type AlertProps } from './Alert';

const AppWrapper = ({ children, ...restProps }: AppWrapperProps) => (
<AppDefaultWrapper scroll="contain" {...restProps}>
const AppWrapper = ({ children, ...restProps }: AppDefaultWrapperProps) => (
<AppDefaultWrapper scroll="contain" disablePortal {...restProps}>
{children}
</AppDefaultWrapper>
);
Expand Down
124 changes: 65 additions & 59 deletions packages/vkui/src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import type {
HasDataAttribute,
HasRootRef,
} from '../../types';
import type { AppRootPortalProps } from '../AppRoot/AppRootPortal';
import { AppRootPortal } from '../AppRoot/AppRootPortal';
import { useScrollLock } from '../AppRoot/ScrollContext';
import type { ButtonProps } from '../Button/Button';
import { FocusTrap } from '../FocusTrap/FocusTrap';
Expand Down Expand Up @@ -68,6 +70,7 @@ export interface AlertProps
* `data-testid` для кнопки закрытия
*/
dismissButtonTestId?: string;
usePortal?: AppRootPortalProps['usePortal'];
}

/**
Expand All @@ -88,6 +91,7 @@ export const Alert = ({
dismissButtonMode = 'outside',
dismissButtonTestId,
getRootRef,
usePortal,
...restProps
}: AlertProps): React.ReactNode => {
const generatedId = React.useId();
Expand Down Expand Up @@ -136,69 +140,71 @@ export const Alert = ({
useScrollLock();

return (
<PopoutWrapper
className={className}
closing={closing}
style={style}
onClick={close}
getRootRef={getRootRef}
>
<FocusTrap
{...restProps}
{...animationHandlers}
getRootRef={elementRef}
onClick={stopPropagation}
onClose={close}
autoFocus={animationState === 'entered'}
className={classNames(
styles.host,
platform === 'ios' && styles.ios,
platform === 'vkcom' && styles.vkcom,
closing ? styles.closing : styles.opening,
isDesktop && styles.desktop,
)}
role="alertdialog"
aria-modal
aria-labelledby={titleId}
aria-describedby={descriptionId}
<AppRootPortal usePortal={usePortal}>
andrey-medvedev-vk marked this conversation as resolved.
Show resolved Hide resolved
<PopoutWrapper
className={className}
closing={closing}
style={style}
onClick={close}
getRootRef={getRootRef}
>
<div
<FocusTrap
{...restProps}
{...animationHandlers}
getRootRef={elementRef}
onClick={stopPropagation}
onClose={close}
autoFocus={animationState === 'entered'}
className={classNames(
styles.content,
dismissButtonMode === 'inside' && styles.contentWithButton,
styles.host,
platform === 'ios' && styles.ios,
platform === 'vkcom' && styles.vkcom,
closing ? styles.closing : styles.opening,
isDesktop && styles.desktop,
)}
role="alertdialog"
aria-modal
aria-labelledby={titleId}
aria-describedby={descriptionId}
>
{hasReactNode(title) && <AlertTitle id={titleId}>{title}</AlertTitle>}
{hasReactNode(description) && (
<AlertDescription id={descriptionId}>{description}</AlertDescription>
<div
className={classNames(
styles.content,
dismissButtonMode === 'inside' && styles.contentWithButton,
)}
>
{hasReactNode(title) && <AlertTitle id={titleId}>{title}</AlertTitle>}
{hasReactNode(description) && (
<AlertDescription id={descriptionId}>{description}</AlertDescription>
)}
{children}
{isDismissButtonVisible && dismissButtonMode === 'inside' && (
<IconButton
label={dismissLabel}
className={classNames(styles.dismiss, 'vkuiInternalAlert__dismiss')}
onClick={close}
hoverMode="opacity"
activeMode="opacity"
data-testid={dismissButtonTestId}
>
<Icon20Cancel />
</IconButton>
)}
</div>
<AlertActions
actions={actions}
actionsAlign={actionsAlign}
actionsLayout={actionsLayout}
renderAction={renderAction}
onItemClick={onItemClick}
/>
{isDismissButtonVisible && dismissButtonMode === 'outside' && (
<ModalDismissButton onClick={close} data-testid={dismissButtonTestId}>
{dismissLabel}
</ModalDismissButton>
)}
{children}
{isDismissButtonVisible && dismissButtonMode === 'inside' && (
<IconButton
label={dismissLabel}
className={classNames(styles.dismiss, 'vkuiInternalAlert__dismiss')}
onClick={close}
hoverMode="opacity"
activeMode="opacity"
data-testid={dismissButtonTestId}
>
<Icon20Cancel />
</IconButton>
)}
</div>
<AlertActions
actions={actions}
actionsAlign={actionsAlign}
actionsLayout={actionsLayout}
renderAction={renderAction}
onItemClick={onItemClick}
/>
{isDismissButtonVisible && dismissButtonMode === 'outside' && (
<ModalDismissButton onClick={close} data-testid={dismissButtonTestId}>
{dismissLabel}
</ModalDismissButton>
)}
</FocusTrap>
</PopoutWrapper>
</FocusTrap>
</PopoutWrapper>
</AppRootPortal>
);
};
33 changes: 11 additions & 22 deletions packages/vkui/src/components/AppRoot/AppRoot.module.css
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
.host {
block-size: 100%;
/* чтобы можно было ограничить размеры приложения
* извне с помощью max-height, max-width */
max-inline-size: inherit;
max-block-size: inherit;
inline-size: 100%;
block-size: 100%;
}

.userSelectNone {
user-select: none;
}

/**
* Хак для webkit-based браузеров, потому что на версиях iOS <= 14.* исчезает возможность
* редактировать contenteditable элементы, если выше по дереву задан user-select: none;
*/
.userSelectNone [contenteditable] {
user-select: text;
.layoutCard {
background: var(--vkui--color_background);
}

@media (--pointer-has-not) {
.pointerNone {
user-select: none;
}

.pointerNone [contenteditable] {
user-select: text;
}
.layoutPlain {
background: var(--vkui--color_background_content);
}

/* stylelint-disable-next-line selector-pseudo-class-disallowed-list */
:global(.vkui__root--embedded) .host {
overflow: auto;
.transformForPositionFixedElements {
transform: translate3d(0, 0, 0);
}
andrey-medvedev-vk marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading