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

Currently incompatible with Nextjs/SSR #4

Open
ljosberinn opened this issue Jun 4, 2020 · 4 comments · May be fixed by #7
Open

Currently incompatible with Nextjs/SSR #4

ljosberinn opened this issue Jun 4, 2020 · 4 comments · May be fixed by #7
Labels
enhancement New feature or request

Comments

@ljosberinn
Copy link

Hi,

thanks for this! Technically coming from font-picker-react, but the underlying issue is in here.

Currently, importing FontPicker imports font-manager, which imports loadFontPreviews, which imports dependencies from './font-styles/declarations.

When initially loading that file, it will instantly try append a style element to <head>.

Can probably be easily fixed by something like:

let previewFontsStylesheet: HTMLStyleElement;

/**
 * Add declaration for applying the specified preview font
 */
export function applyFontPreview(previewFont: Font, selectorSuffix: string): void {
	if(!previewFontsStylesheet && typeof document !== 'undefined') {
		previewFontsStylesheet = document.createElement('style');
		document.head.appendChild(previewFontsStylesheet);
	}

	const fontId = getFontId(previewFont.family);
	const style = `
			#font-button-${fontId}${selectorSuffix} {
				font-family: "${previewFont.family}";
			}
		`;
	previewFontsStylesheet.appendChild(document.createTextNode(style));
}
@samuelmeuli
Copy link
Owner

Thanks for opening the issue! Would you be interested in creating a PR?

@samuelmeuli samuelmeuli added the enhancement New feature or request label Jun 7, 2020
@ljosberinn
Copy link
Author

Afraid not, I was just opening this on behalf of someone else

@n3s7or
Copy link

n3s7or commented Apr 10, 2021

One workaround for this is to avoid SSR like so:

import dynamic from "next/dynamic";

const FontPicker = dynamic(() => import("font-picker-react"), {
    ssr: false,
});

@magicspon magicspon linked a pull request Mar 9, 2022 that will close this issue
@magicspon
Copy link

magicspon commented Mar 9, 2022

I've opened a PR that fixes this issue

tested locally with nextjs + my own hook, based on the react lib
https://gist.github.com/magicspon/7e9c7283240b9d8a093ff0ae29c07a25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants