Shopify / shopify-app-bridge

https://shopify.dev/docs/api/app-bridge
88 stars 9 forks source link

navigationMenu.set function doesn't work properly #70

Closed redareda9 closed 2 years ago

redareda9 commented 3 years ago

Describe the bug

After creating a navigation menu using NavigationMenu.create, the menu shows up but calling set function doesn't update the menu as described by the description.

To Reproduce

Steps to reproduce the behaviour:

  1. Build an embedded app
  2. Create a menu using NavigationMenu.create
  3. Subscribe to redirects using app.subscribe(Redirect.Action.APP
  4. Set active menu from callback to update the active menu Item
  5. Look at the menu not updating itself
 const dashboardLink = AppLink.create(app, {
    label: 'Dashboard',
    destination: '/',
  });
  const settingsLink = AppLink.create(app, {
    label: 'Settings',
    destination: '/settings',
  });

  const menuItems = [dashboardLink, settingsLink]

  let navigationMenu = NavigationMenu.create(app, {
    items: menuItems,
    active: undefined
  });

  useEffect(() => {
    app.subscribe(Redirect.Action.APP, (payload: Redirect.AppPayload) => {
      console.log(`Navigated to ${payload.path}`)
      const item = menuItems.find(i => i.destination === payload.path)
      console.log('item :>> ', item);
      navigationMenu = navigationMenu.set({ active: item })
    });
  }, [app])

Expected behaviour

The navigation menu item should become active as soon as we click on it.

Contextual information

Packages and versions

Additional context

I'm using NextJS and Next-router to handle client routing and not refresh the page.

zappingseb commented 2 years ago

same here

henrytao-me commented 2 years ago

Hi @zappingseb I just tested it again on my test app, it works as expected. The menu item is active as soon as it is clicked.