Skip to content

FOUC when loading CSS #291

@jaysoo

Description

@jaysoo

Scenario

Given the following element: (See https://github.com/jaysoo/example-react-helmet)

  <Helmet
    style={[{
      cssText: `
        .message {
          text-align: center;
          font-size: 48px;
          color: magenta;
        }
      `
    }]}
  />
  <p className="message">
    Hello World!
  </p>
</div>

I know this is a contrived example, and not how you should be styling React apps. The real world example involves allowing user customization via custom CSS.

Expected

The element is rendered, and the user sees "Hello World!" in large, magenta text.

Actual

The user will see a flash of unstyled content (FOUC) before the <style> is inserted into <head>. This seems to be caused by react-helmet v5's use of requestIdleCallback, which forces the head tag insertion to happen after the rendered element has been updated in the DOM.

Note: This does not happen with version 3.x.

fouc

Workaround

I don't see any obvious workarounds, unless something clever is done using onChangeClientState. Suggestions welcomed.

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