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

Prevent component from breaking during server side rendering #626

Closed
carloslancha opened this issue Feb 23, 2018 · 1 comment
Closed

Prevent component from breaking during server side rendering #626

carloslancha opened this issue Feb 23, 2018 · 1 comment
Assignees
Labels
status: next-release Issues that will enter into the next release type: bug Issues reporting that Component is not doing what should be done type: feature request Issues that are open to adding new features

Comments

@carloslancha
Copy link
Contributor

In those components that uses the dom in the lifecycle we need to implement this pattern in order to avoid problems in SSR

import {isServerSide} from 'metal';
import Component from 'metal-component';
import Soy from 'metal-soy';
import Toggler from 'metal-toggler';

import templates from './Sidebar.soy.js';

class Sidebar extends Component {
	attached() {
		if (isServerSide()) {
			return;
		}

		Toggler.CSS_EXPANDED = 'open';

	    this._toggler = new Toggler({
			content: '.sidebar-toggler-content',
			header: '.sidebar-toggler'
		});
	}

	disposed() {
		if (isServerSide()) {
			return;
		}

		this._toggler.dispose();
	}

};

Soy.register(Sidebar, templates);

export default Sidebar;
@carloslancha carloslancha added type: bug Issues reporting that Component is not doing what should be done type: feature request Issues that are open to adding new features labels Feb 23, 2018
@julien
Copy link
Contributor

julien commented Feb 23, 2018

Thanks @carloslancha

@carloslancha carloslancha self-assigned this Feb 23, 2018
@carloslancha carloslancha added the status: next-release Issues that will enter into the next release label Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: next-release Issues that will enter into the next release type: bug Issues reporting that Component is not doing what should be done type: feature request Issues that are open to adding new features
Projects
None yet
Development

No branches or pull requests

2 participants