Skip to content

[Bug]: TableOfContents isn't working as expected #408

Description

@noxify

Description

Using the TableOfContents component in a nextjs layout produces the following error:

## Error Type
Console Error

## Error Message
Encountered a script tag while rendering React component. Scripts inside React components are never executed when rendering on the client. Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).


    at script (<anonymous>:null:null)
    at TableOfContents (src/components/table-of-contents-repro.tsx:29:5)
    at DocsReproSlugLayout (src/app/docs-repro/[...slug]/layout.tsx:138:35)

## Code Frame
  27 |
  28 |   return (
> 29 |     <RenounTableOfContents
     |     ^
  30 |       sections={sections}
  31 |       components={{
  32 |         Root: (props) => (

Next.js version: 16.2.5 (Turbopack)

Steps to Reproduce

Initial Setup:

git clone git@github.com:noxify/renoun-toc-repro.git
cd renoun-toc-repro
pnpm i 

Usage Example:

Interaction:

  1. Start the dev server ( pnpm dev )
  2. Browse in desktop mode ( >= 800px ) to: http://localhost:3000/docs-repro/lakeql/introduction/getting-started/
  3. Change the browser width to 700px or less ( to trigger the mobile mode )
  4. Change the browser width back to desktop mode
  5. Open the next dev tool to see the error

Expected Behavior

  • The error isn't shown and the script injection is working ( including the additional toc features like highlighting )

Actual Behavior

  • it seems that the script injection is working as expected
  • the section highlighting isn't shown based on this

Environment

  • renoun version: 11.7.1
  • Node version: 24.14.1
  • Browser (if applicable): Chromium based browser ( currently edge )
  • Any other relevant details nextjs 16.2.5

Additional Context

To make it work, I had to copy the renoun toc component ( src/components/toc ).

  • removed the inline script injection
  • added an export to TableOfContentsScript
  • added the local TableOfContentsScript component directly into the layout ( src/app/docs/[...slug]/layout.tsx )

The working version can be found here: http://localhost:3000/docs/lakeql/introduction/getting-started/

Here you can

  • change the browser width and the error does not occour
  • the current section is highlighted

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions