Skip to content
Closed
Show file tree
Hide file tree
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
50 changes: 50 additions & 0 deletions lib/getModules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This defines a function called `getModules` that can get an array of all
// React Spectrum modules.
//
// One use case for this function is it can be used to wrap the Next.js
// configuration in `next.config.js` so that React Spectrum works in Next.js
// without any errors.
//
// You can do something like this in your `next.config.js`:
//
// <next.config.js>
//
// const nextTranspileModules = require("next-transpile-modules");
// const getReactSpectrumModules = require("react-spectrum-monorepo/lib/getModules");
//
// // This wraps the Next.js configuration to do some transpilations so that React
// // Spectrum works in Next.js without any errors.
// //
// // Inspired by https://react-spectrum.adobe.com/react-spectrum/ssr.html#nextjs
// //
// const withTM = nextTranspileModules(getReactSpectrumModules());
//
// module.exports = withTM({
// // Your Next.js configuration
// });
//
// </next.config.js>

const fs = require("fs");

const flatten = (arr) => arr.reduce((acc, val) => acc.concat(val));

const getModules = () =>
flatten(
// Returns something like [
// '@adobe/react-spectrum',
// '@adobe/react-spectrum-ui',
// '@adobe/react-spectrum-workflow',
// '@react-spectrum/actiongroup',
// '@react-spectrum/breadcrumbs',
// '@react-spectrum/button',
// ...
// '@spectrum-icons/ui',
// '@spectrum-icons/workflow'
// ]
["@adobe", "@react-spectrum", "@spectrum-icons"].map((ns) =>
fs.readdirSync(`./node_modules/${ns}`).map((dir) => `${ns}/${dir}`)
)
);

module.exports = getModules;
53 changes: 9 additions & 44 deletions packages/dev/docs/pages/react-spectrum/ssr.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,52 +58,17 @@ First, you’ll need to install an additional Next.js plugin:
yarn add next-transpile-modules
```

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.
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.

```tsx
const withTM = require("next-transpile-modules")([
"@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/table",
"@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"
]);
const nextTranspileModules = require("next-transpile-modules");
const getReactSpectrumModules = require("react-spectrum-monorepo/lib/getModules");

// This wraps the Next.js configuration to do some transpilations so that React
// Spectrum works in Next.js without any errors.
//
// Inspired by https://react-spectrum.adobe.com/react-spectrum/ssr.html#nextjs
Copy link
Member

Choose a reason for hiding this comment

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

not sure we need this inspiredby as it's self referential?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh ha ha oops. That's left over from when it was living in my project. 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, maybe this should live in another package. It was developed for Next.js and not everyone is going to use Next.js. I created a new repo for it:

https://github.com/msabramo/get-react-spectrum-modules

though I do wonder if it will have more "gravitas" if the repo lives under some more official scope like @adobe or @react-spectrum...?

Copy link
Member

Choose a reason for hiding this comment

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

well, we do have a monorepo, so it doesn't haven't to live in a separate repo, just in its own package here. I'm not sure what scope we'd give it, maybe start with @adobe, you can find that one in packages/@adobe

const withTM = nextTranspileModules(getReactSpectrumModules());

module.exports = withTM({
// Your Next.js configuration
Expand Down