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

Update SSR docs for Next.js 11 #2215

Merged
merged 2 commits into from
Aug 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 45 additions & 12 deletions packages/dev/docs/pages/react-spectrum/ssr.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,63 @@ Finally, when using server side rendering, the `locale` prop should be set expli

[Next.js](https://nextjs.org) is a framework for building websites and web applications with React. It supports both server side rendering as well as static rendering. In addition to using an `SSRProvider`, a small amount of configuration is required to get React Spectrum’s CSS working with Next.js.

First, you’ll need to install a couple Next.js plugins:
First, you’ll need to install an additional Next.js plugin:

```
yarn add next-compose-plugins @zeit/next-css next-transpile-modules
yarn add next-transpile-modules
```

With these installed, add the following to your `next.config.js` file. This will ensure that React Spectrum’s CSS is loaded properly by Next.js.
With this installed, add the following to your `next.config.js` file. This will ensure that React Spectrum’s CSS is loaded properly by Next.js. Note that packages may need to be removed or added to the config below if using an older or newer version of React Spectrum.

```tsx
const withPlugins = require('next-compose-plugins');
const withCSS = require('@zeit/next-css');
const withTM = require('next-transpile-modules')([
'@adobe/react-spectrum',
'@spectrum-icons/.*',
'@react-spectrum/.*'
const withTM = require("next-transpile-modules")([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my own knowledge: the star patterns don't work any more here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct; it seems like it is not possible since v5 of this plugin (Source). I believe these docs were written at v4. There are some alternate solutions in the thread, so if people feel strongly about implementing one of those, that could be an option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to explain what is going on here. Is this just a list of everything you use in your project? Would you really have the monopackage and a bunch of the individual ones too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I'll add that. I wasn't able to get individual packages working. It looks like it requires every one to be included, as well as the monopackage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving as is for now, as to not cause extra confusion. We can follow up if we manage to get individual packages working.

"@adobe/react-spectrum",
"@react-spectrum/actiongroup",
"@react-spectrum/breadcrumbs",
"@react-spectrum/button",
"@react-spectrum/buttongroup",
"@react-spectrum/checkbox",
"@react-spectrum/combobox",
"@react-spectrum/dialog",
"@react-spectrum/divider",
"@react-spectrum/form",
"@react-spectrum/icon",
"@react-spectrum/illustratedmessage",
"@react-spectrum/image",
"@react-spectrum/label",
"@react-spectrum/layout",
"@react-spectrum/link",
"@react-spectrum/listbox",
"@react-spectrum/menu",
"@react-spectrum/meter",
"@react-spectrum/numberfield",
"@react-spectrum/overlays",
"@react-spectrum/picker",
"@react-spectrum/progress",
"@react-spectrum/provider",
"@react-spectrum/radio",
"@react-spectrum/slider",
"@react-spectrum/searchfield",
"@react-spectrum/statuslight",
"@react-spectrum/switch",
"@react-spectrum/tabs",
"@react-spectrum/text",
"@react-spectrum/textfield",
"@react-spectrum/theme-dark",
"@react-spectrum/theme-default",
"@react-spectrum/theme-light",
"@react-spectrum/tooltip",
"@react-spectrum/view",
"@react-spectrum/well",
"@spectrum-icons/ui",
"@spectrum-icons/workflow"
]);

module.exports = withPlugins([withCSS, withTM], {
module.exports = withTM({
// Your Next.js configuration
});
```

For an example of a working Next.js app using React Spectrum, see [this repo](https://github.com/devongovett/rsp-next).

Comment on lines -77 to -78
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to handle for this PR, but would be good to track somewhere that we should update/create a new example repo for a example Next.js app

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update my app? I accept PRs :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better. I'll make one and we can keep this in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

## Gatsby

[Gatsby](https://www.gatsbyjs.com) is a static site generator built with React. Gatsby works out of the box with React Spectrum without any additional configuration. For an example of a working Gatsby site using React Spectrum, see [this repo](https://github.com/devongovett/rsp-gatsby).