Skip to content

Currently incompatible with Nextjs/SSR #4

@ljosberinn

Description

@ljosberinn

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));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions