Skip to content

[Bug?]: Props from nested sets are propagating up to parent sets #9304

@Tobbe

Description

@Tobbe

What's not working?

We have this test case in the framework

describe('Multiple nested sets', () => {
  const HomePage = () => <h1>Home Page</h1>
  const Page = () => <h1>Page</h1>

  const DebugLayout = (props) => {
    return (
      <div>
        <p>Theme: {props.theme}</p>
        <p>Other Prop: {props.otherProp}</p>
        <p>Page Level: {props.level}</p>
        {props.children}
      </div>
    )
  }

  const TestRouter = () => (
    <Router>
      <Route path="/" page={HomePage} name="home" />
      <Set level="1" theme="blue" wrap={DebugLayout}>
        <Route path="/level1" page={Page} name="level1" />
        <Set level="2" theme="red" otherProp="bazinga">
          <Route path="/level2" page={Page} name="level2" />
          <Set level="3" theme="green">
            <Route path="/level3" page={Page} name="level3" />
          </Set>
        </Set>
      </Set>
    </Router>
  )

  test('level 1, matches expected props', async () => {
    const screen = render(<TestRouter />)

    act(() => navigate('/level1'))

    await waitFor(() => {
      expect(screen.queryByText(`Theme: blue`)).toBeInTheDocument()
      expect(screen.queryByText(`Page Level: 1`)).toBeInTheDocument()
    })
  })

  test('level 2, should override level 1', async () => {
    const screen = render(<TestRouter />)

    act(() => navigate('/level2'))

    await waitFor(() => {
      expect(screen.queryByText(`Theme: red`)).toBeInTheDocument()
      expect(screen.queryByText(`Other Prop: bazinga`)).toBeInTheDocument()
      expect(screen.queryByText(`Page Level: 2`)).toBeInTheDocument()
    })
  })

  test('level 3, should override level 1 & 2 and pass through other props', async () => {
    const screen = render(<TestRouter />)

    act(() => navigate('/level3'))

    await waitFor(() => {
      expect(screen.queryByText(`Theme: green`)).toBeInTheDocument()
      expect(screen.queryByText(`Other Prop: bazinga`)).toBeInTheDocument()
      expect(screen.queryByText(`Page Level: 3`)).toBeInTheDocument()
    })
  })
})

I think it's wrong. The theme prop from level 2 and level 3 should not be passed to DebugLayout. It should only always see "blue".

Going back to RW v4.5.0 I see the behavior I'm expecting. So this is new(ish)

How do we reproduce the bug?

Just run yarn test in the framework and that testcase will be run. But because the assumptions in the test case are wrong (IMO) it'll pass. But if you update them to behave like the router used to be have the test case will start to fail.

What's your environment? (If it applies)

No response

Are you interested in working on this?

  • I'm interested in working on this

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/needs-infoMore information is needed for reproduction

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions