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

fix(next@15): use the asset prefix when loading a CSS in App Router #72095

Merged
merged 5 commits into from
Dec 12, 2024
Merged
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
6 changes: 5 additions & 1 deletion packages/next/src/build/webpack/config/blocks/css/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,11 @@ export const css = curry(async function css(
insert: function (linkTag: HTMLLinkElement) {
if (typeof _N_E_STYLE_LOAD === 'function') {
const { href, onload, onerror } = linkTag
_N_E_STYLE_LOAD(new URL(href).pathname).then(
_N_E_STYLE_LOAD(
href.indexOf(window.location.origin) === 0
? new URL(href).pathname
: href
).then(
Comment on lines +622 to +626
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sokra @ijjk I updated the fix to avoid a regression when the assetPrefix config is not used. I used the same kind of check than in the MiniCssExtractPlugin webpack plugin.

() => onload?.call(linkTag, { type: 'load' } as Event),
() => onerror?.call(linkTag, {} as Event)
)
Expand Down
3 changes: 3 additions & 0 deletions test/integration/next-dynamic-css-asset-prefix/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
assetPrefix: 'http://localhost:__CDN_PORT__/path-prefix',
}
27 changes: 27 additions & 0 deletions test/integration/next-dynamic-css-asset-prefix/src/Component2.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import styles from './Component2.module.scss'

export default function Content2() {
return (
<div className={styles.container}>
<h1 className={styles.header}>Where does it come from?</h1>
<div className={styles.textContent}>
Contrary to popular belief, Lorem Ipsum is not simply random text. It
has roots in a piece of classical Latin literature from 45 BC, making it
over 2000 years old. Richard McClintock, a Latin professor at
Hampden-Sydney College in Virginia, looked up one of the more obscure
Latin words, consectetur, from a Lorem Ipsum passage, and going through
the cites of the word in classical literature, discovered the
undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33
of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by
Cicero, written in 45 BC. This book is a treatise on the theory of
ethics, very popular during the Renaissance. The first line of Lorem
Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is
reproduced below for those interested. Sections 1.10.32 and 1.10.33 from
"de Finibus Bonorum et Malorum" by Cicero are also reproduced in their
exact original form, accompanied by English versions from the 1914
translation by H. Rackham.
</div>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.header {
font-style: italic;
}

.container {
background-color: #dddddd;
padding: 1rem;
}

.textContent {
color: #666;
letter-spacing: -1px;
}
29 changes: 29 additions & 0 deletions test/integration/next-dynamic-css-asset-prefix/src/Content.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import styles from './Content.module.css'
import Content2 from './Component2'

export default function Content() {
return (
<div className={styles.container}>
<h1 className={styles.header}>Where does it come from?</h1>
<div className={styles.textContent}>
Contrary to popular belief, Lorem Ipsum is not simply random text. It
has roots in a piece of classical Latin literature from 45 BC, making it
over 2000 years old. Richard McClintock, a Latin professor at
Hampden-Sydney College in Virginia, looked up one of the more obscure
Latin words, consectetur, from a Lorem Ipsum passage, and going through
the cites of the word in classical literature, discovered the
undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33
of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by
Cicero, written in 45 BC. This book is a treatise on the theory of
ethics, very popular during the Renaissance. The first line of Lorem
Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is
reproduced below for those interested. Sections 1.10.32 and 1.10.33 from
"de Finibus Bonorum et Malorum" by Cicero are also reproduced in their
exact original form, accompanied by English versions from the 1914
translation by H. Rackham.
</div>
<Content2 />
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.header {
font-style: italic;
}

.container {
background-color: #dddddd;
padding: 1rem;
}

.textContent {
color: #666;
letter-spacing: -1px;
}
Loading
Loading