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

feat: Disable SSR flag #374

Open
3 tasks done
marcincodes opened this issue Aug 12, 2023 · 0 comments
Open
3 tasks done

feat: Disable SSR flag #374

marcincodes opened this issue Aug 12, 2023 · 0 comments
Labels

Comments

@marcincodes
Copy link

marcincodes commented Aug 12, 2023

Prerequisites

Describe the Feature Request

Add option to generated react libraries with disabled SSR in React

Describe the Use Case

Generated components should be able to omit SSR phase of rendering in multiple react ssr frameworks like Next.js, Remix and other

Describe Preferred Solution

Wrap every component in "no SSR" component when flag is enabled

Describe Alternatives

Using https://github.com/kadirahq/react-no-ssr when consuming component or add such wrapper into every project

Related Code

You can easily disable SSR using componentDidMount/useEffect:

class NoSSR extends React.Component {
  constructor(...args) {
    super(...args);
    this.state = {
      canRender: false
    };
  }

  componentDidMount() {
    this.setState({canRender: true});
  }

  render() {
    const { children, onSSR = <DefaultOnSSR />} = this.props;
    const { canRender } = this.state;

    return canRender ? children : onSSR;
  }
}

Source: https://github.com/kadirahq/react-no-ssr/blob/master/src/index.js

Additional Information

Sample hydration mismatch in Next.js app:
image

Similar issue: #226

Edit: I'm happy to help to contribute this feature if you want it in react output target

@ionitron-bot ionitron-bot bot added the triage label Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant