Skip to content

[Bug]: [REACT - Next.js] floating-ui is causing server error on SSR #2970

@maciej-jezierski

Description

@maciej-jezierski

Describe the Bug

We set up a project with the instruction of the https://docs.storefrontui.io/v2/react/getting-started.html
After set up we added SfButton and got an intermediate error

Expected behavior

Adding any component shouldn't cause errors on SSR

Steps to reproduce

Remove "use client"; line and it starts break

app/page.tsx

import { SfButton } from "@storefront-ui/react";
import Image from "next/image";
​
export default function ButtonBlock() {
  return (
    <div>
      <Image
        src="https://www.winparts.eu/assets/img/logo.svg"
        alt="logo"
        width={208}
        height={87}
      />
      <SfButton className="!bg-sale">Hello</SfButton>
    </div>
  );
}```

### SFUI version

@storefront-ui/react@2.5.0

### Framework

React, Next.js

### Node version

16

### Browser

Chrome

### OS

Linux

### Relevant log output

```shell
./app/page.tsx
ReactServerComponentsError:

You're importing a component that needs useEffect. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.
Learn more: https://nextjs.org/docs/getting-started/react-essentials

   ,-[/home/bravebison/winparts-storefront/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.esm.js:1:1]
 1 | import { arrow as arrow$1, computePosition } from '@floating-ui/dom';
 2 | export { autoPlacement, autoUpdate, computePosition, detectOverflow, flip, getOverflowAncestors, hide, inline, limitShift, offset, platform, shift, size } from '@floating-ui/dom';
 3 | import * as React from 'react';
 4 | import { useLayoutEffect, useEffect } from 'react';
   :                           ^^^^^^^^^
 5 | import * as ReactDOM from 'react-dom';
 6 | 
 7 | /**
   `----

The error was caused by importing '@storefront-ui/react/dist/index.mjs' in './app/page.tsx'.

Maybe one of these should be marked as a client entry with "use client":
  ./app/page.tsx

Able to fix / change the documentation?

  • Yes
  • No

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions