-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fixes #53190. Next.js App Router comprises two categories of resources, same-origin ones (RSC payload, in the form of inline `<script />`) and possibly third-party ones (chunks that respect the `assetPrefix`). The latter should also respect the `crossOrigin` option from `next.config.js`. Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
129 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function RootLayout({ children }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Index(props) { | ||
return <p id="title">IndexPage</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'app dir - crossOrigin config', | ||
{ | ||
files: __dirname, | ||
skipDeployment: true, | ||
}, | ||
({ next, isNextStart }) => { | ||
if (isNextStart) { | ||
it('skip in start mode', () => {}) | ||
return | ||
} | ||
it('should render correctly with assetPrefix: "/"', async () => { | ||
const $ = await next.render$('/') | ||
// Only potential external (assetPrefix) <script /> and <link /> should have crossorigin attribute | ||
$( | ||
'script[src*="https://example.vercel.sh"], link[href*="https://example.vercel.sh"]' | ||
).each((_, el) => { | ||
const crossOrigin = $(el).attr('crossorigin') | ||
expect(crossOrigin).toBe('use-credentials') | ||
}) | ||
|
||
// Inline <script /> (including RSC payload) and <link /> should not have crossorigin attribute | ||
$('script:not([src]), link:not([href])').each((_, el) => { | ||
const crossOrigin = $(el).attr('crossorigin') | ||
expect(crossOrigin).toBeUndefined() | ||
}) | ||
|
||
// Same origin <script /> and <link /> should not have crossorigin attribute either | ||
$('script[src^="/"], link[href^="/"]').each((_, el) => { | ||
const crossOrigin = $(el).attr('crossorigin') | ||
expect(crossOrigin).toBeUndefined() | ||
}) | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = { | ||
/** | ||
* The "assetPrefix" here doesn't needs to be real as we doesn't load the page in the browser in this test, | ||
* we only care about if all assets prefixed with the "assetPrefix" are having correct "crossOrigin". | ||
*/ | ||
assetPrefix: 'https://example.vercel.sh', | ||
|
||
/** | ||
* According to HTML5 Spec (https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attributes), | ||
* crossorigin="" and crossorigin="anonymous" has the same effect. And ReactDOM's preload methods (preload, preconnect, etc.) | ||
* will prefer crossorigin="" to save bytes. | ||
* | ||
* So we use "use-credentials" here for easier testing. | ||
*/ | ||
crossOrigin: 'use-credentials', | ||
} |