mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
The PR adds the new `polyfill.io` instance endpoint (from Fastly and Cloudflare) to the `eslint-plugin-next`'s `no-unwanted-polyfillio` rules, so these new endpoints can be detected by the rule. --- `polyfill.io` was acquired by **a China-based CDN company** "Funnull", see [the announcement from the `polyfill.io` domain owner's Twitter](https://x.com/JakeDChampion/status/1761315227008643367) and https://github.com/polyfillpolyfill/polyfill-service/issues/2834. Despite Funnull's claims of operating in the United States, the predominance of Simplified Chinese on its website suggests otherwise, and it turns out that **"Funnull" is notorious for providing service for the betting and pornography industries**. [The original creator of the `polyfill.io` has voiced his concern on Twitter](https://twitter.com/triblondon/status/1761852117579427975). And since the acquisition, numerous issues have emerged (https://github.com/polyfillpolyfill/polyfill-service/issues/2835, https://github.com/polyfillpolyfill/polyfill-service/issues/2838, https://github.com/alist-org/alist/issues/6100), rendering the `polyfill.io` service **extremely unstable**. Since then, Fastly ([Announcement](https://community.fastly.com/t/new-options-for-polyfill-io-users/2540)) and Cloudflare ([Announcement](https://blog.cloudflare.com/polyfill-io-now-available-on-cdnjs-reduce-your-supply-chain-risk)) has hosted their own instances of `polyfill.io` service. --------- Co-authored-by: Steven <[email protected]>
146 lines
4.2 KiB
TypeScript
146 lines
4.2 KiB
TypeScript
import rule from '@next/eslint-plugin-next/dist/rules/no-unwanted-polyfillio'
|
|
import { RuleTester } from 'eslint'
|
|
;(RuleTester as any).setDefaultConfig({
|
|
parserOptions: {
|
|
ecmaVersion: 2018,
|
|
sourceType: 'module',
|
|
ecmaFeatures: {
|
|
modules: true,
|
|
jsx: true,
|
|
},
|
|
},
|
|
})
|
|
const ruleTester = new RuleTester()
|
|
|
|
ruleTester.run('unwanted-polyfillsio', rule, {
|
|
valid: [
|
|
`import {Head} from 'next/document';
|
|
|
|
export class Blah extends Head {
|
|
render() {
|
|
return (
|
|
<div>
|
|
<h1>Hello title</h1>
|
|
<script src='https://polyfill.io/v3/polyfill.min.js?features=AbortController'></script>
|
|
</div>
|
|
);
|
|
}
|
|
}`,
|
|
`import {Head} from 'next/document';
|
|
|
|
export class Blah extends Head {
|
|
render() {
|
|
return (
|
|
<div>
|
|
<h1>Hello title</h1>
|
|
<script src='https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver'></script>
|
|
</div>
|
|
);
|
|
}
|
|
}`,
|
|
`import Script from 'next/script';
|
|
|
|
export function MyApp({ Component, pageProps }) {
|
|
return (
|
|
<div>
|
|
<Component {...pageProps} />
|
|
<Script src='https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver' />
|
|
</div>
|
|
);
|
|
}`,
|
|
`import Script from 'next/script';
|
|
|
|
export function MyApp({ Component, pageProps }) {
|
|
return (
|
|
<div>
|
|
<Component {...pageProps} />
|
|
<Script src='https://polyfill-fastly.io/v3/polyfill.min.js?features=IntersectionObserver' />
|
|
</div>
|
|
);
|
|
}`,
|
|
],
|
|
|
|
invalid: [
|
|
{
|
|
code: `import {Head} from 'next/document';
|
|
|
|
export class Blah extends Head {
|
|
render() {
|
|
return (
|
|
<div>
|
|
<h1>Hello title</h1>
|
|
<script src='https://polyfill.io/v3/polyfill.min.js?features=WeakSet%2CPromise%2CPromise.prototype.finally%2Ces2015%2Ces5%2Ces6'></script>
|
|
</div>
|
|
);
|
|
}
|
|
}`,
|
|
errors: [
|
|
{
|
|
message:
|
|
'No duplicate polyfills from Polyfill.io are allowed. WeakSet, Promise, Promise.prototype.finally, es2015, es5, es6 are already shipped with Next.js. See: https://nextjs.org/docs/messages/no-unwanted-polyfillio',
|
|
type: 'JSXOpeningElement',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
export class Blah {
|
|
render() {
|
|
return (
|
|
<div>
|
|
<h1>Hello title</h1>
|
|
<script src='https://polyfill.io/v3/polyfill.min.js?features=Array.prototype.copyWithin'></script>
|
|
</div>
|
|
);
|
|
}
|
|
}`,
|
|
errors: [
|
|
{
|
|
message:
|
|
'No duplicate polyfills from Polyfill.io are allowed. Array.prototype.copyWithin is already shipped with Next.js. See: https://nextjs.org/docs/messages/no-unwanted-polyfillio',
|
|
type: 'JSXOpeningElement',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `import NextScript from 'next/script';
|
|
|
|
export function MyApp({ Component, pageProps }) {
|
|
return (
|
|
<div>
|
|
<Component {...pageProps} />
|
|
<NextScript src='https://polyfill.io/v3/polyfill.min.js?features=Array.prototype.copyWithin' />
|
|
</div>
|
|
);
|
|
}`,
|
|
errors: [
|
|
{
|
|
message:
|
|
'No duplicate polyfills from Polyfill.io are allowed. Array.prototype.copyWithin is already shipped with Next.js. See: https://nextjs.org/docs/messages/no-unwanted-polyfillio',
|
|
type: 'JSXOpeningElement',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `import {Head} from 'next/document';
|
|
|
|
export class ES2019Features extends Head {
|
|
render() {
|
|
return (
|
|
<div>
|
|
<h1>Hello title</h1>
|
|
<script src='https://polyfill.io/v3/polyfill.min.js?features=Object.fromEntries'></script>
|
|
</div>
|
|
);
|
|
}
|
|
}`,
|
|
errors: [
|
|
{
|
|
message:
|
|
'No duplicate polyfills from Polyfill.io are allowed. Object.fromEntries is already shipped with Next.js. See: https://nextjs.org/docs/messages/no-unwanted-polyfillio',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|