-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
How to use React Spectrum with Next.js #760
Comments
Hmm, I think you may need to override the webpack config to add css-loader? Possibly the next-css package could help? https://github.com/vercel/next-plugins/tree/master/packages/next-css |
I believe this is because of this vercel/next.js#12079. It does seem like the vercel team is working on it. |
Could you allow us to import the css manually? |
This should be solved in near future (hopefully). vercel/next.js#15208 |
#835 sets up a test harness to ensure all the components work in an SSR environment. If anyone would like to contribute tests to help with this effort, please feel free! π |
Not sure this is a good workaround or not, but it is a workaround. Install the following dependencies:
And edit your
|
This should be fixed as of #994! We have a bit of testing to do, but things are looking good. We'll be getting this into the next release along with some docs about how to use React Spectrum/React Aria with Next.js and SSR in general. π |
@devongovett awesome! |
@devongovett Thank you for resolving this issue, Devon! Is there an estimated timeline for when the next release of React Spectrum is going to be? We're considering moving away from a different design library, and I'd love to see if Spectrum/Aria/Stately meet our use cases going forward (in a Next.js application.) |
@SheaBelsky we have testing scheduled for Friday, so should be early next week if all goes well. Working on the docs as well. π |
@devongovett That's great to hear, thank you! |
Release is now out! See our guides for React Spectrum and React Aria to learn more. π |
Hi, Error:
next info output:
|
I've followed the instructions here: https://react-spectrum.adobe.com/react-spectrum/ssr.html It still doesn't work on Next.js. |
@giovanniincammicia It should be working now. Can you post any specific errors you're getting? Don't forget to disable React strict mode if it is enabled in |
I'm having a similar issue with the latest version of Next.js and react-spectrum |
@reidbarber
This is my // @ts-check
import withTM from 'next-transpile-modules';
/**
* Don't be scared of the generics here.
* All they do is to give us autocompletion when using this.
*
* @template {import('next').NextConfig} T
* @param {T} config - A generic parameter that flows through to the return type
* @constraint {{import('next').NextConfig}}
*/
function defineNextConfig(config) {
return config;
}
export default withTM([
'@adobe/react-spectrum',
'@react-spectrum/actiongroup',
'@react-spectrum/breadcrumbs',
'@react-spectrum/button',
'@react-spectrum/badge',
'@react-spectrum/buttongroup',
'@react-spectrum/calendar',
'@react-spectrum/checkbox',
'@react-spectrum/combobox',
'@react-spectrum/contextualhelp',
'@react-spectrum/datepicker',
'@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/list',
'@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/illustrations',
'@spectrum-icons/ui',
'@spectrum-icons/workflow',
])(
defineNextConfig({
reactStrictMode: false,
swcMinify: true,
output: 'standalone',
experimental: {
newNextLinkBehavior: true,
},
})
); I tried with I am using pnpm as a package manager. When trying to start dev server I am getting following error:
Also I don't need any react-spectrum styles I just want to use your Can you somehow let us youse your Unfortunatelly |
I managed to get this working by switching to yarn. |
Looks like you used next.config.mjs, which uses ESM. See #3630 we're working on support for that. |
ESM is not a problem here, I tried with .config.js and requires and there is the same error when using pnpm. It looks like there is some issue with peer dependencies. <SSRProvider>
<Provider theme={defaultTheme} colorScheme='light'>
....
</Provider>
</SSRProvider> When i remove node_modules and install dependencies with yarn and then start dev server i get this error:
So I installed this package I will post here both lock files maybe it will be helpfull First one is The second one is |
The https://react-spectrum.adobe.com/react-spectrum/ssr.html#nextjs is outdated. In Next v13.1 you can do the following -const withTM = require('next-transpile-modules')(['awesome_module']);
-module.exports = withTM({});
+module.exports = {
+ transpilePackages: ['awesome_module'],
+}; Ref: https://github.com/martpie/next-transpile-modules/releases/tag/the-end So your next.config.js should look like the below module.exports = {
transpilePackages: [
"@adobe/react-spectrum",
"@react-spectrum/actiongroup",
"@react-spectrum/badge",
"@react-spectrum/breadcrumbs",
"@react-spectrum/button",
"@react-spectrum/buttongroup",
"@react-spectrum/calendar",
"@react-spectrum/checkbox",
"@react-spectrum/color",
"@react-spectrum/combobox",
"@react-spectrum/contextualhelp",
"@react-spectrum/datepicker",
"@react-spectrum/dialog",
"@react-spectrum/divider",
"@react-spectrum/dnd",
"@react-spectrum/form",
"@react-spectrum/icon",
"@react-spectrum/illustratedmessage",
"@react-spectrum/image",
"@react-spectrum/label",
"@react-spectrum/labeledvalue",
"@react-spectrum/layout",
"@react-spectrum/link",
"@react-spectrum/list",
"@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/illustrations",
"@spectrum-icons/ui",
"@spectrum-icons/workflow",
], Ref: next.config.js and #3895 |
Thanks for the update, docs update here #3897 |
I think you already know... Add @react-spectrum/actionbar module.exports = { best regards. |
β Question
Next.js does not support importing of CSS from
node_modules
, is there a workaround for getting Spectrum and Next.js to play together?π¦ Context
I just created an empty Next.js project and tried to import @adobe/react-spectrum but it complains with the following error:
π» Code Sample
Empty Next.js project with the example from Spectrum Getting started in
pages/index.js
The text was updated successfully, but these errors were encountered: