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
29 changes: 21 additions & 8 deletions pages/sync-scrolls.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,29 @@ export default function App() {
return (
<>
<h1>Syncing horizontal scrolls</h1>
<div
onScroll={() => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This onScroll is not reached in React 18 + strict-mode. The nested onScroll do get triggered, so I moved the related code to those handlers instead.

n++;
numberOfCallsRef.current?.setAttribute('data-call-number', n.toString());
}}
>
<div id="element1" ref={ref1} style={{ inlineSize: '400px', overflow: 'scroll' }} onScroll={handleScroll}>
<div>
<div
id="element1"
ref={ref1}
style={{ inlineSize: '400px', overflow: 'scroll' }}
onScroll={e => {
n++;
numberOfCallsRef.current?.setAttribute('data-call-number', n.toString());
handleScroll(e);
}}
>
<div style={{ inlineSize: '800px', blockSize: '100px', backgroundColor: 'lightpink' }} />
</div>
<div id="element2" ref={ref2} style={{ width: '400px', overflow: 'scroll' }} onScroll={handleScroll}>
<div
id="element2"
ref={ref2}
style={{ width: '400px', overflow: 'scroll' }}
onScroll={e => {
n++;
numberOfCallsRef.current?.setAttribute('data-call-number', n.toString());
handleScroll(e);
}}
>
<div style={{ inlineSize: '800px', blockSize: '100px', backgroundColor: 'lightblue' }} />
</div>
<div ref={numberOfCallsRef} id="numberOfCalls">
Expand Down
43 changes: 14 additions & 29 deletions pages/table-fragments/grid-navigation-custom.page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import React, { useContext, useMemo, useRef, useState } from 'react';
import { orderBy, range } from 'lodash';

Expand All @@ -9,7 +10,6 @@ import {
AppLayout,
Button,
ButtonDropdown,
Checkbox,
CollectionPreferences,
ColumnLayout,
Container,
Expand All @@ -26,7 +26,6 @@ import {
SpaceBetween,
StatusIndicator,
} from '~components';
import { useEffectOnUpdate } from '~components/internal/hooks/use-effect-on-update';
import {
getTableCellRoleProps,
getTableColHeaderRoleProps,
Expand All @@ -41,7 +40,8 @@ import {
import AppContext, { AppContextType } from '../app/app-context';
import appLayoutLabels from '../app-layout/utils/labels';
import { contentDisplayPreferenceI18nStrings } from '../common/i18n-strings';
import { generateItems, id as generateId, Instance } from '../table/generate-data';
import { id as generateId, Instance } from '../table/generate-data';
import { allInstances50 } from '../table/instances-data';
import { stateToStatusIndicator } from '../table/shared-configs';

import styles from './styles.scss';
Expand All @@ -56,7 +56,6 @@ type PageContext = React.Context<
pageSize: number;
tableRole: TableRole;
actionsMode: ActionsMode;
autoRefresh: boolean;
visibleColumns: string;
}>
>;
Expand All @@ -70,30 +69,28 @@ const actionsModeOptions = [
{ value: 'inline', label: 'Inline (anti-pattern)' },
];

const allItems = allInstances50.slice(0, 25);

let refreshIndex = 26;

export default function Page() {
const [toolsOpen, setToolsOpen] = useState(false);
const { urlParams, setUrlParams } = useContext(AppContext as PageContext);
const {
pageSize = 10,
tableRole = 'grid',
actionsMode = 'dropdown',
autoRefresh = false,
visibleColumns:
visibleColumnsString = 'id,actions,state,imageId,dnsName,type,inline-select,inline-radio,inline-input',
} = urlParams;
const visibleColumns = visibleColumnsString.split(',').filter(Boolean);

const [items, setItems] = useState(generateItems(25));
const [refreshCounter, setRefreshCounter] = useState(0);
window.refreshItems = () => setRefreshCounter(prev => prev + 1);

useEffectOnUpdate(() => {
Copy link
Member Author

@pan-kot pan-kot Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auto-refresh feature was not used in integration tests, but it was causing issues: in React 18 with strict mode the useEffectOnUpdate callback is triggered even when the dependencies did not change. As result, the table's state changed, causing some tests to fail.

setItems(prev => [...prev.slice(1), ...generateItems(1)]);
if (autoRefresh) {
const timeoutId = setTimeout(() => setRefreshCounter(prev => prev + 1), 10000);
return () => clearTimeout(timeoutId);
}
}, [autoRefresh, refreshCounter]);
const [items, setItems] = useState(allItems);
const refreshItems = () =>
setItems(prev =>
refreshIndex < 50 ? [...prev.slice(1), { ...allInstances50[refreshIndex++], id: generateId() }] : prev
);
window.refreshItems = refreshItems;

const columnDefinitions = [
{
Expand Down Expand Up @@ -210,17 +207,6 @@ export default function Page() {
title="Preferences"
confirmLabel="Confirm"
cancelLabel="Cancel"
customPreference={(
customValue: undefined | { autoRefresh: boolean },
setCustomValue: (value: { autoRefresh: boolean }) => void
) => (
<Checkbox
checked={!!customValue?.autoRefresh}
onChange={event => setCustomValue({ autoRefresh: event.detail.checked })}
>
Auto-refresh every 10 seconds
</Checkbox>
)}
preferences={{
contentDisplay: columnDefinitions.map(column => ({
id: column.key,
Expand All @@ -233,7 +219,6 @@ export default function Page() {
.filter(column => column.visible)
.map(column => column.id)
.join(','),
autoRefresh: detail.custom.autoRefresh,
})
}
contentDisplayPreference={{
Expand All @@ -248,7 +233,7 @@ export default function Page() {
}}
/>

<Button onClick={() => setRefreshCounter(prev => prev + 1)} iconName="refresh" ariaLabel="Refresh">
<Button onClick={refreshItems} iconName="refresh" ariaLabel="Refresh">
Refresh
</Button>
</SpaceBetween>
Expand Down
Loading
Loading