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

Use clientOnly without isolating component in its own file #840

Open
MengLinMaker opened this issue Aug 7, 2024 · 3 comments
Open

Use clientOnly without isolating component in its own file #840

MengLinMaker opened this issue Aug 7, 2024 · 3 comments
Labels
solidstart Related to SolidStart

Comments

@MengLinMaker
Copy link

What is this request related to?

Request

📋 Suggested

https://docs.solidjs.com/solid-start/reference/client/client-only

📋 General description or bullet points

Provide a way of using clientOnly without creating a separate file.
Code wise, this could be more ergonomic.

Could also create a helper function to directly translate component function to client only component.

import { clientOnly } from "@solidjs/start"

function ClientOnlyComponent() {
  const location = window.document.location
  return <div>{location.href}</div>
}

type ResolveClientComponent = (value: {
  default: Component
}) => void

export default clientOnly(
  () =>
    new Promise((resolve: ResolveClientComponent) => {
      resolve({ default: ClientOnlyComponent })
    }),
)

🖥️ Reproduction of code samples in StackBlitz

StackBlitz doesn't support solid-start

@MengLinMaker MengLinMaker added the pending review Awaiting review by team members. label Aug 7, 2024
@LadyBluenotes LadyBluenotes added improve documentation and removed pending review Awaiting review by team members. labels Aug 27, 2024
@LadyBluenotes LadyBluenotes removed their assignment Aug 27, 2024
@atilafassina atilafassina changed the title [Request]: Use clientOnly without isolating component in its own file Sep 1, 2024
@atilafassina
Copy link
Member

I'll check if this can be accomplished this way and I'll check with the team if there's any repercussions I'm not able to predict right now.

As for the helper, this is probably a feature request to made on SolidStart. In this repository we just document the existing APIs and offer guides on how to use them.

@MengLinMaker
Copy link
Author

I have a working wrapper which looks something like this:

import { clientOnly } from '@solidjs/start'
import { Component } from 'solid-js'

// Client side render wrapper
type ResolveClientComponent<T> = (value: {
  default: Component<T>
}) => void

export const useClient = <T,>(App: Component<T>) => {
  return clientOnly(() => {
    return new Promise((resolve: ResolveClientComponent<T>) => {
      resolve({ default: App })
    })
  })
}

@brenelz
Copy link
Collaborator

brenelz commented Sep 26, 2024

I think we probably need to figure out a code solution to this before being able to document it. I think using this would be recommended

https://github.com/lxsmnsyc/solid-use/blob/main/docs/client-only.md

@LadyBluenotes LadyBluenotes added solidstart Related to SolidStart and removed improve documentation labels Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solidstart Related to SolidStart
Projects
None yet
Development

No branches or pull requests

4 participants