Unverified Commit 9ab8828f authored by Will Binns-Smith's avatar Will Binns-Smith Committed by GitHub

Apply next/font to foreign code (#58461)

This applies next/font to third party code like that in `node_modules`


Closes PACK-1964
parent 3ec0551f
...@@ -75,13 +75,19 @@ pub async fn get_next_server_internal_transforms_rules( ...@@ -75,13 +75,19 @@ pub async fn get_next_server_internal_transforms_rules(
let mut rules = vec![]; let mut rules = vec![];
match context_ty { match context_ty {
ServerContextType::Pages { .. } => {} ServerContextType::Pages { .. } => {
// Apply next/font transforms to foreign code
rules.push(get_next_font_transform_rule());
}
ServerContextType::PagesApi { .. } => {} ServerContextType::PagesApi { .. } => {}
ServerContextType::PagesData { .. } => {} ServerContextType::PagesData { .. } => {}
ServerContextType::AppSSR { .. } => {} ServerContextType::AppSSR { .. } => {
rules.push(get_next_font_transform_rule());
}
ServerContextType::AppRSC { ServerContextType::AppRSC {
client_transition, .. client_transition, ..
} => { } => {
rules.push(get_next_font_transform_rule());
if let Some(client_transition) = client_transition { if let Some(client_transition) = client_transition {
rules.push(get_next_css_client_reference_transforms_rule( rules.push(get_next_css_client_reference_transforms_rule(
client_transition, client_transition,
......
import { font1 } from 'my-font'
export default function HomePage() {
return (
<p id="third-party-page" className={font1.className}>
{JSON.stringify(font1)}
</p>
)
}
import { font1 } from 'my-font'
export default function HomePage() {
return (
<p id="third-party-page" className={font1.className}>
{JSON.stringify(font1)}
</p>
)
}
...@@ -30,6 +30,7 @@ describe.each([['app'], ['app-old']])('%s', (fixture: string) => { ...@@ -30,6 +30,7 @@ describe.each([['app'], ['app-old']])('%s', (fixture: string) => {
files: { files: {
app: new FileRef(join(__dirname, fixture)), app: new FileRef(join(__dirname, fixture)),
fonts: new FileRef(join(__dirname, 'fonts')), fonts: new FileRef(join(__dirname, 'fonts')),
node_modules: new FileRef(join(__dirname, 'node_modules')),
'next.config.js': new FileRef(join(__dirname, 'next.config.js')), 'next.config.js': new FileRef(join(__dirname, 'next.config.js')),
}, },
dependencies: { dependencies: {
...@@ -105,6 +106,17 @@ describe.each([['app'], ['app-old']])('%s', (fixture: string) => { ...@@ -105,6 +106,17 @@ describe.each([['app'], ['app-old']])('%s', (fixture: string) => {
}, },
}) })
}) })
it('should transform code in node_modules', async () => {
const $ = await next.render$('/third-party')
expect(JSON.parse($('#third-party-page').text())).toEqual({
className: '__className_3953ad',
style: {
fontFamily: "'__font1_3953ad'",
},
variable: '__variable_3953ad',
})
})
}) })
describe('computed styles', () => { describe('computed styles', () => {
......
import localFont from 'next/font/local'
export const font1 = localFont({ src: '../../fonts/font1.woff2', variable: '--font-1' })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment