Skip to content

Commit ce963f7

Browse files
authored
Add "use client" to components in build for Next.js app dir (#5498)
1 parent 1cba01d commit ce963f7

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

.parcelrc-build

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "@parcel/config-default",
3+
"resolvers": ["@parcel/resolver-glob", "..."],
4+
"transformers": {
5+
"packages/**/intl/*.json": ["parcel-transformer-intl"],
6+
"bundle-text:*.svg": ["@parcel/transformer-svg", "@parcel/transformer-inline-string"],
7+
"*.svg": ["@parcel/transformer-svg-react"],
8+
"*.{js,mjs,jsm,jsx,es6,cjs,ts,tsx}": [
9+
"@parcel/transformer-js",
10+
"@parcel/transformer-react-refresh-wrap"
11+
]
12+
},
13+
"optimizers": {
14+
"{main,module}.js": ["...", "parcel-optimizer-react-client"]
15+
}
16+
}

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ publish-nightly: build
9292
yarn publish:nightly
9393

9494
build:
95-
parcel build packages/@react-{spectrum,aria,stately}/*/ packages/@internationalized/{message,string,date,number}/ packages/react-aria-components --no-optimize
95+
parcel build packages/@react-{spectrum,aria,stately}/*/ packages/@internationalized/{message,string,date,number}/ packages/react-aria-components --no-optimize --config .parcelrc-build
9696
yarn lerna run prepublishOnly
9797
for pkg in packages/@react-{spectrum,aria,stately}/*/ packages/@internationalized/{message,string,date,number}/ packages/@adobe/react-spectrum/ packages/react-aria/ packages/react-stately/ packages/react-aria-components/; \
9898
do cp $$pkg/dist/module.js $$pkg/dist/import.mjs; \

packages/@adobe/react-spectrum/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13+
'use client';
14+
1315
export {ActionGroup} from '@react-spectrum/actiongroup';
1416
export {Badge} from '@react-spectrum/badge';
1517
export {Breadcrumbs} from '@react-spectrum/breadcrumbs';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2023 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
const {Optimizer} = require('@parcel/plugin');
14+
const {blobToString} = require('@parcel/utils');
15+
16+
module.exports = new Optimizer({
17+
async optimize({bundle, contents, map}) {
18+
if (!/@react-spectrum|react-aria-components/.test(bundle.target.distDir)) {
19+
return {contents, map};
20+
}
21+
22+
map?.offsetLines(2, 0);
23+
return {
24+
contents: `"use client";
25+
26+
${await blobToString(contents)}`,
27+
map
28+
};
29+
}
30+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "parcel-optimizer-react-client",
3+
"version": "1.0.0",
4+
"private": true,
5+
"main": "ReactClientOptimizer.js",
6+
"engines": {
7+
"parcel": "^2.10.2"
8+
},
9+
"dependencies": {
10+
"@parcel/plugin": "^2.10.2"
11+
}
12+
}

0 commit comments

Comments
 (0)