Vega carousel does not re-render its children when data changes even if keys are stable

:warning: Before you continue


Before submitting a bug report, please review our troubleshooting documentation at Redirect | /docs/vega/0.24/troubleshoot-overview.html

If you still want to file a bug report, please make sure to fill in all the details below and provide the necessary information.

NOTE: PLEASE ONLY REPORT A SINGLE BUG USING THIS TEMPLATE.
If you’re experiencing multiple issues, please file a separate report for each.


:backhand_index_pointing_right: Bug Description


1. Summary

The children should re-render if keys are same on data changes but they do not.

App Name:
App Link on Amazon Appstore (found through Developer Console → Actions column in App List → View on Amazon.com):

Bug Severity
Select one that applies

  • Impacts operation of app
  • Blocks current development
  • Improvement suggestion
  • Issue with documentation (If selected, please share the doc link and describe the issue)
  • Other

2. Steps to Reproduce

  1. [List the steps for reproducing the bug]
  2. [Any specific component or method call in React Native triggering the issue]
  3. …

3. Observed Behavior

Explain what actually happened, noting any discrepancies or malfunctions.

no change is observed in children<!-- Answer here -->

4. Expected Behavior

Describe what you expected the SDK to do under normal operation.

children should re-render when data changes

4.a Possible Root Cause & Temporary Workaround

Fill out anything you have tried. If you don’t know, N/A is acceptable

use React context which wraps the carousel and is read by the children

5. Logs or crash report

(Please make sure to provide relevant logs as attachment)

For crash issues, please refer this guide for faster troubleshooting: Detect Where the App Crash Originates - Amazon Vega Docs

  • App/Device Logs

  • Crash Logs

  • Crash Report

  • For issues with Vega Studio Extension, please share log files from below folders:
    For v0.22+:

    ~/.vscode/extensions/amazon.vega-extension-<version>/ExtensionLogs
    ~/.vscode/extensions/amazon.vega-ui-extension-<version>/ExtensionLogs
    

    For v0.21 and earlier:

     ~/.vscode/extensions/amazon.kepler-extension-<version>/ExtensionLogs
     ~/.vscode/extensions/amazon.kepler-ui-extension-<version>/ExtensionLogs
    

6. Environment

Please fill out the fields related to your bug below:

  • SDK Version: 0.23.8358

  • React Native Version: (e.g., RN0.72/RN0.83)

  • App State: [Foreground]

  • OS Information: Please ssh into the device via vega exec vda shell (or kepler exec vda shell for v0.21 and earlier) and copy the output from cat /etc/os-release into the answer section below. Note, if you don’t have a simulator running or device attached, the command will respond with vda: no devices/emulators found

    <!-- Answer here if applicable --> 
    

7. Example Code Snippet / Screenshots / Screengrabs

Include any relevant code or component setup in React Native that can help reproduce the bug.

import { Carousel, type CarouselRenderInfo } from '@amazon-devices/vega-carousel'
import { useCallback, useMemo, useState } from 'react'
import { Pressable, StyleSheet, Text, View } from 'react-native'
import { Button } from '@amzn/kepler-ui-components'

type CardProps = {
  title: string
  description: string
  isFavorite: boolean
}

type CardData = CardProps & {
  id: number
}

const UPDATED_DATA: CardData[] = [
  {
    id: 10001,
    title: 'Title 1',
    description: 'A description of the content',
    isFavorite: true,
  },
  {
    id: 10002,
    title: 'Title 2',
    description: 'ocer aliquam vergo',
    isFavorite: false,
  },
  {
    id: 10003,
    title: 'Title 3',
    description: 'textus abeo dicta',
    isFavorite: false,
  },
  {
    id: 10004,
    title: 'Title 4',
    description: 'admiratio calculus curtus',
    isFavorite: false,
  },
  {
    id: 10005,
    title: 'Title 5',
    description: 'tondeo sto commemoro',
    isFavorite: false,
  },
]

const INITIAL_DATA: CardData[] = [
  {
    id: 10001,
    title: 'Title 2',
    description: 'A description of the content',
    isFavorite: true,
  },
  {
    id: 10002,
    title: 'Title 2',
    description: 'ocer aliquam vergo',
    isFavorite: false,
  },
  {
    id: 10003,
    title: 'Title 3',
    description: 'textus abeo dicta',
    isFavorite: false,
  },
  {
    id: 10004,
    title: 'Title 4',
    description: 'admiratio calculus curtus',
    isFavorite: false,
  },
  {
    id: 10005,
    title: 'Title 5',
    description: 'tondeo sto commemoro',
    isFavorite: false,
  },
]

const itemStyle = { pressedItemScaleFactor: 1 }

const Card = (props: CardProps) => {
  const { title, description, isFavorite } = props
  const [isFocused, setFocus] = useState<boolean>(false)
  return (
    <Pressable
      style={[styles.card, isFocused ? styles.focusedCard : null]}
      onBlur={() => setFocus(false)}
      onFocus={() => setFocus(true)}
    >
      <View style={styles.metadata}>
        <Text style={styles.text}>{title}</Text>
        <Text style={styles.text}>{description}</Text>
      </View>
      {isFavorite ? <Text style={styles.text}>💗</Text> : null}
    </Pressable>
  )
}

const renderItem = ({ item }: CarouselRenderInfo<CardData>) => (
  <Card
    title={item.title}
    description={item.description}
    isFavorite={item.isFavorite}
  />
)

const CarouselStory = () => {
  const [data, setData] = useState(INITIAL_DATA)
  const [favoriteIndex, setFavoriteIndex] = useState(0)

const [dataState, updateDataState] = useState(INITIAL_DATA)


useEffect(() => {
  const timer = setTimeout(() => {
    updateDataState(UPDATED_DATA)
  }, 7000)
  return () => clearTimeout(timer)
}, [])

  const dataAdapter = useMemo(
    () => ({
      getItem: (index: number) => dataState[index],
      getItemCount: () => dataState.length,
      getItemKey: ({ item, index }: { item: CardData; index: number }) =>
        `${item.id}-${index}`,
      notifyDataError: () => false,
    }),
    [dataState],
  )

  return (
    <View style={styles.container}>
      <View style={styles.settings}>
        <Button
          label="<"
          onPress={() => updateFavorite(favoriteIndex - 1)}
          variant="primary"
        />
        <Text style={styles.text}>{favoriteIndex}</Text>
        <Button
          label=">"
          onPress={() => updateFavorite(favoriteIndex + 1)}
          variant="primary"
        />
      </View>
      <Carousel
        orientation="horizontal"
        dataAdapter={dataAdapter}
        renderItem={renderItem}
        itemStyle={itemStyle}
        containerStyle={styles.carousel}
      />
    </View>
  )
}

const CARD_WIDTH = 300
const CARD_HEIGHT = 200

const styles = StyleSheet.create({
  container: {
    backgroundColor: 'black',
    flexDirection: 'column',
    gap: 16,
  },
  settings: {
    display: 'flex',
    flexDirection: 'row',
    alignItems: 'center',
    gap: 16,
  },
  carousel: {
    height: CARD_HEIGHT,
  },
  card: {
    display: 'flex',
    flexDirection: 'column',
    justifyContent: 'space-between',
    alignItems: 'center',
    backgroundColor: '#333333',
    borderRadius: 8,
    borderWidth: 2,
    width: CARD_WIDTH,
    height: CARD_HEIGHT,
    padding: 10,
  },
  focusedCard: {
    borderStyle: 'solid',
    borderWidth: 2,
    borderColor: '#cccccc',
  },
  metadata: {
    display: 'flex',
    flexDirection: 'column',
    gap: 8,
  },
  text: {
    color: 'white',
    fontSize: 30,
  },
})

export default CarouselStory



:backhand_index_pointing_right: Playback Issues


If this is a playback issue, please provide your content URL, any pre-conditions (like geo-location), and let us know if it’s x86 or arm7.


<!-- Describe your playback issue if applicable -->

Please share the following details in addition:_

  • Player SDK: [Bitmovin, Shaka, ...]
  • Player SDK Version: [e.g. 1.23]
    • Audio Codecs: [AAC, ...]
    • Video Codecs: [h.264, mp4]
    • Manifest Types: [m3u8, dash, etc ..]

Q: If applicable, please provide your media/content url
If this is created dynamically, tokenized, etc please provide a way for us to access it

[N/A or Content / Media Url for testing]

Q: Are there any special headers required to reproduce the issue you are facing?

[N/A or Insert Headers]

Additionally please provide the following if possible
Provide Screenshots / Screengrabs / Logs. Please include as much information as you can that will help debug.

<!-- Answer here if applicable --> 

:backhand_index_pointing_right: Additional Context


Any Additional Context you would like to provide?
Add any other relevant information, such as recent updates to the SDK, dependencies, or device OS that may affect the bug.

https://community.amazondeveloper.com/t/carousel-does-not-re-render-when-data-changes/14196 this issue has been filed earlier for VUIC carousel but was never fixed.

Hi @Rishabh_Ritweek,

Thank you for the detailed bug report and the complete code snippet on the Carousel not reflecting data changes.

One thing worth noting from the documentation: the Vega Carousel consumes data through the dataAdapter callbacks (getItem, getItemCount, getItemKey, notifyDataError) and recycles its item views. The uniqueId prop is documented as “an arbitrary and unique identifier for this carousel that determines when to recycle the carousel and its items.” The Carousel is also app-bundled, so please run npm update @amazon-devices/vega-carousel to confirm you’re on the latest package. (The current version includes fixes to view recycling.) (Reference: Get Started with Vega Carousel - Get Started with Vega Carousel - Amazon Vega Docs)

Beyond that, our team is investigating the re-render behavior you’ve described and will provide an update as soon as we have more information.

Thanks for helping us improve the Vega platform.

Warm regards,
Aishwarya

i can confirm that I am on 0.2.1 which is latest..