Skip to content

Link State Var Href JS Error #224

Closed

Description

@Alek99

Describe the bug
It seems href is not working with a state var. Getting a JS error in browser.

Error: Multiple children were passed to <Link> with `href` of `one_value` but only one child is supported https://nextjs.org/docs/messages/link-multiple-children

To Reproduce
Steps to reproduce the behavior:

  • Code/Link to Repo:
"""Welcome to Pynecone! This file create a counter app."""
import pynecone as pc
from typing import Dict

class State(pc.State):
    my_dict: Dict[str, str] = {"A": "/onevalue", "B": "/anothervalue"}

def index():
  return pc.link(
    pc.text("A"),
    href=State.my_dict["A"]
  )
# Add state and page to the app.
app = pc.App(state=State)
app.add_page(index, title="TableExample")
app.compile() 

Expected behavior
Expect it to work as a regular state var reference.
** Specifics (please complete the following information):**

  • Python Version:3.11
  • Pynecone Version:0.1.11
  • OS: Mac

Activity

  1. added
    bug
    on Jan 8, 2023
  2. picklelo commented on Jan 9, 2023

    @picklelo
    Contributor

    I think you can't pass a pc.text (or any other component) to a pc.link. This should work:

    def index():
      return pc.link(
        "A",
        href=State.my_dict["A"]
      )
    

    We should throw an exception in the compiler to catch this to avoid any JS errors.

    EDIT: Actually not sure why other components can't be nested, as long as there's only one...

  3. added this to the milestone on Jan 9, 2023
  4. self-assigned this
    on Jan 9, 2023
  5. modified the milestones: , on Jan 10, 2023
  6. xugaoxiang commented on Jan 11, 2023

    @xugaoxiang

    Same error on v0.1.11,python 3.8, nodejs 18.12.1, windows 10 64bit

    I use pc init and then pc run, powershell console outputs

    `

    dev
    next dev

    ready - started server on 0.0.0.0:3000, url: http://localhost:3000
    event - compiled client and server successfully in 12.6s (761 modules)
    Attention: Next.js now collects completely anonymous telemetry regarding usage.
    This information is used to shape Next.js' roadmap and prioritize features.
    You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
    https://nextjs.org/telemetry

    wait - compiling / (client and server)...
    event - compiled client and server successfully in 1596 ms (830 modules)
    wait - compiling /_error (client and server)...
    error - node_modules\next\dist\client\link.js (216:22) @ Object.LinkComponent [as render]
    error - Error: Multiple children were passed to with href of https://pynecone.io/docs/getting-started/introduction but only one child is supported https://nextjs.org/docs/messages/link-multiple-children
    at Object.LinkComponent [as render] (webpack-internal:///./node_modules/next/dist/client/link.js:216:23)
    at ReactDOMServerRenderer.render (C:\Users\Administrator\Desktop\pc_app.web\node_modules\react-dom\cjs\react-dom-server.node.development.js:3872:44)
    at ReactDOMServerRenderer.read (C:\Users\Administrator\Desktop\pc_app.web\node_modules\react-dom\cjs\react-dom-server.node.development.js:3690:29)
    at Object.renderToString (C:\Users\Administrator\Desktop\pc_app.web\node_modules\react-dom\cjs\react-dom-server.node.development.js:4298:27)
    at renderDocument (C:\Users\Administrator\Desktop\pc_app.web\node_modules\next\dist\server\render.js:736:47)
    at Object.renderToHTML (C:\Users\Administrator\Desktop\pc_app.web\node_modules\next\dist\server\render.js:819:34)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async doRender (C:\Users\Administrator\Desktop\pc_app.web\node_modules\next\dist\server\base-server.js:687:38)
    at async cacheEntry.responseCache.get.isManualRevalidate.isManualRevalidate (C:\Users\Administrator\Desktop\pc_app.web\node_modules\next\dist\server\base-server.js:796:28)
    at async C:\Users\Administrator\Desktop\pc_app.web\node_modules\next\dist\server\response-cache\index.js:80:36 {
    page: '/'
    }
    `

  7. Alek99 commented on Jan 11, 2023

    @Alek99
    MemberAuthor

    Can you send a snippet of your code or is it the code from above?

  8. Alek99 commented on Jan 11, 2023

    @Alek99
    MemberAuthor

    Ah ok I see your on windows we almost have windows support done should have it up soon this is the last error to fix

  9. xugaoxiang commented on Jan 11, 2023

    @xugaoxiang

    Can you send a snippet of your code or is it the code from above?

    source code

    """Welcome to Pynecone! This file outlines the steps to create a basic app."""
    from pcconfig import config
    
    import pynecone as pc
    
    docs_url = "https://pynecone.io/docs/getting-started/introduction"
    filename = f"{config.app_name}/{config.app_name}.py"
    
    
    class State(pc.State):
        """The app state."""
    
        pass
    
    
    def index():
        return pc.center(
            pc.vstack(
                pc.heading("Welcome to Pynecone!", font_size="2em"),
                pc.box("Get started by editing ", pc.code(filename, font_size="1em")),
                pc.link(
                    "Check out our docs!",
                    href=docs_url,
                    border="0.1em solid",
                    padding="0.5em",
                    border_radius="0.5em",
                    _hover={
                        "color": "rgb(107,99,246)",
                    },
                ),
                spacing="1.5em",
                font_size="2em",
            ),
            padding_top="10%",
        )
    
    
    # Add state and page to the app.
    app = pc.App(state=State)
    app.add_page(index)
    app.compile()
    
    
  10. assigned and unassigned on Jan 13, 2023
  11. Alek99 commented on Jan 13, 2023

    @Alek99
    MemberAuthor

    Working on this now

  12. Inkee1 commented on Jan 16, 2023

    @Inkee1
  13. xugaoxiang commented on Jan 17, 2023

    @xugaoxiang

    Working on this now

    Error still exists, already update to v0.1.12.

  14. linked a pull request that will close this issueAdd windows support #290on Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions