Skip to content

Client-Only Module Missing After Hot Reload #3718

@dcalhoun

Description

@dcalhoun

Applying the proposed solutions for client-only modules works for initial render, but any hot reload causes the client-only module to go become undefined.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Client-only modules re-render after a change is made to a relevant source file.

Current Behavior

Client-only modules disappear from the rendered tree (potentially throwing an error); as the module is undefined.

Steps to Reproduce (for bugs)

  1. Render a React component (parent) that relies on an client-only module (child). (example below)
  2. Make a change to to the parent.

Context

I desire to server-render my Next.js application, sans components that require client technology (e.g. a component for a YouTube video player is not server-renderable). I also desire to hot reload changes to components while working in my development environment.

Your Environment

Tech Version
next 4.2.3
node 8.9.4
OS macOS 10.13.3
browser Chrome 64.0.3282.140

Example

import React, { Component } from 'react';

let YouTube;

export default class VideoPlayer extends Component {
  constructor(props) {
    super(props);
    this.state = { renderYouTube: false };
  }

  // cDM is not invoked during a hot reload; which means YouTube is undefined
  // on any subsequent render.
  componentDidMount() {
    YouTube = require('react-youtube').default;
    this.setState({ renderYouTube: true });
  }

  render() {
    return (
      <div>
        {this.state.renderYouTube && <YouTube videoId={this.props.id} />}
      </div>
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions