Skip to content

Next 9 dynamic router invalid tag if you use a styled(Link) from styled-components #7817

@MikeMuxika

Description

@MikeMuxika

Bug report

When passing a next Link as a styled component to the dynamic routing feature, you receive an "Invariant Violation: Invalid tag: /post/second/second-comment" error. It seems that the dynamic-router is very explicitly looking for and is inflexible in allowing a styled-components wrapper to it.

To Reproduce

  1. Use the example from: https://github.com/zeit/next.js/tree/canary/examples/dynamic-routing
  2. Install styled-components library
  3. Open pages/post/[id]/index.js in your editor
  4. add the line import styled from "styled-components"
  5. Create a styled component using the next/link component with any styling you'd like. const TestLink = styled(Link) cursor: pointer;``
  6. Replace any of the instances of with your TestLink version
  7. Check out the behavior in your browser.

Expected behavior

Expect to see the exact same dynamic route navigation behavior as the vanilla version of the example.

Additional context

I first ran into the issue on a separate project. After searching, I found the example linked above. With some trial and error, I narrowed down that the only difference between the example and my code was the use of styled components. I then verified that this was the cause by adding styled components to the dynamic-routing example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions