Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request]: Add ssr option to dynamic #258

Closed
pveierland opened this issue Dec 24, 2024 · 1 comment · Fixed by #331
Closed

[Feature request]: Add ssr option to dynamic #258

pveierland opened this issue Dec 24, 2024 · 1 comment · Fixed by #331
Assignees
Labels
enhancement New feature or request typescript Requires typescript knowledge

Comments

@pveierland
Copy link

pveierland commented Dec 24, 2024

Is your feature request related to a problem? Please describe.

The dynamic feature currently does not support disabling server-side rendering. This means that any component must be renderable server-side. It would be helpful if tuono had the ssr option in the same way as Next.js where server-side rendering can be disabled for a dynamically imported component.

This would make it easier to use components like react-markdown that uses browser APIs like document directly and for which polyfills are difficult and/or not the desired approach.

Describe the solution you'd like

I'd like the dynamic function to support a second options object parameter with an ssr key which can be set to false to disable server-side rendering of a dynamically included component, see:

https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading#with-no-ssr

Describe alternatives you've considered

Dependencies

  • yarn add react-markdown

Attempt 1: tuono.dynamic

import type { JSX } from 'react'
import { Suspense } from 'react'
import { dynamic } from 'tuono'

const Markdown: any = dynamic(() => import('react-markdown'))

export default function IndexPage(): JSX.Element {
  return (
    <Suspense>
      <Markdown>{'# Hi, *Pluto*!'}</Markdown>
    </Suspense>
  )
}

❌ Result: Server failure (no server log output)

Attempt 2: React.lazy

import type { JSX } from 'react'
import { lazy, Suspense } from 'react'

const Markdown = lazy(() => import('react-markdown'))

export default function IndexPage(): JSX.Element {
  return (
    <Suspense>
      <Markdown>{'# Hi, *Pluto*!'}</Markdown>
    </Suspense>
  )

❌ Server log: <unknown>:304616: Uncaught ReferenceError: document is not defined

Additional context

No response

@pveierland pveierland added the enhancement New feature or request label Dec 24, 2024
@Valerioageno
Copy link
Member

That is a great suggestion! Definitely we will address this soon!

@Valerioageno Valerioageno added the typescript Requires typescript knowledge label Dec 24, 2024
@Valerioageno Valerioageno added bug Something isn't working and removed enhancement New feature or request labels Jan 3, 2025
@Valerioageno Valerioageno self-assigned this Jan 4, 2025
@Valerioageno Valerioageno added enhancement New feature or request and removed bug Something isn't working labels Jan 5, 2025
@Valerioageno Valerioageno moved this to In progress in Road to V1 Jan 5, 2025
@github-project-automation github-project-automation bot moved this from In progress to Done in Road to V1 Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request typescript Requires typescript knowledge
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants