Replies: 14 comments 12 replies
-
Does this mean that some I have a project with a bunch of ESM scripts, for which I added If Next outputs are for modern browsers, it’d be really cool if it was ESM everywhere! Altenratively, if files in |
Beta Was this translation helpful? Give feedback.
-
Will Next's output apply workarounds for Edge and Safari? I believe Safari 11 on iOS still crashes when encountering async arrow functions within a class body, and Edge 16 is missing support for non-shorthand destructured argument defaults in Arrow Functions, etc (full list). |
Beta Was this translation helpful? Give feedback.
-
When will the Opt-in flag be available for people who want to test, and adopt it early? |
Beta Was this translation helpful? Give feedback.
-
What is a modern browser is something that will evolve with time, so this pattern is probably here to stay. For many companies and products supporting legacy browsers will always be important, yet they don't want to reduce the quality of the main build. The build time is really not a problem here imo, if you want a legacy browsers you have good business reason for it and you'd accept a small overhead when releasing your app in prod.
|
Beta Was this translation helpful? Give feedback.
-
For reference https://www.tiktok.com now transforms all code to |
Beta Was this translation helpful? Give feedback.
-
I'd like to kindly remind folks as we work towards a solution here that while the majority of individuals are using modern browsers, the market for Internet Explorer 11 (and below) is still large even though it is reaching end of life soon. For example, the company I work for gets about 20% of annual revenue through IE 11. This is primarily through B2B integrations with older SAP instances. Many IT departments are very slow to upgrade, which puts our end customers in a position where they do not have a choice of what browser to use, so asking the end customer to upgrade to a modern browser is sometimes not possible. We have more users on IE 11 than on modern Firefox or Safari. We recently made the decision to use Next.js, partially due to its built in support for IE 11, so I ask that we keep this large customer base in mind. That being said, is there an option to have 2 builds, modern and legacy, and then do user agent sniffing on the server to serve the appropriate bundle? It would be nice to relegate the ES5 transpiling and polyfilling to the legacy browser bundle only. The tradeoff of a longer build time is fine if I'm giving my customers a better experience by serving a leaner bundle to modern browsers. I'm curious if Next.js could also handle modern and legacy CSS stylesheet bundles? AFAIK Differential Serving using |
Beta Was this translation helpful? Give feedback.
-
I like the idea of adding opt-in support and configuration for v12 using built-in browserlist support in package.json. It seems to require the least amount of effort. It also feels better in terms of feature alignment since if I follow correctly there's currently no way to accomplish this with SWC. As far as I can tell, if someone would like to do this in a project today, it would only be possible if they fall back to using Babel which has other obvious performance drawbacks and is (relatively) more painful to configure. Adding support in this way cleanly tees up the wider rollout for this feature to be as simple as a configuration flip. I don't know when v13 is supposed to be released, but this way if enough users express a desire to push this change back (for example until after IEs EoL) their concerns can be addressed appropriately without preventing other users from experiencing the benefits of a lighter bundle with the fastest compiler today. |
Beta Was this translation helpful? Give feedback.
-
I’m sympathetic to the continued need to support IE but I don’t think that it should be so influential as to bend the implementation for the vast majority of end-users of Next.is apps. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
So I'm trying to get Next 12.1.6 to ignore older browsers like IE11, and I've added a Am I forced to use ES5? Some other comments and the documentation seem to indicate that that is not the case. I understand that some people need to support older browsers still, but why force that on everybody? |
Beta Was this translation helpful? Give feedback.
-
I've implemented the JS part of this RFC and the experimental flags to try it out are landed in 12.2:
|
Beta Was this translation helpful? Give feedback.
-
The use of |
Beta Was this translation helpful? Give feedback.
-
I am still using babel, because I use vanilla-extract. Setting In the meantime I manually added the new defaults via So in package.json: {
"browserslist": [
"chrome 61",
"edge 16",
"firefox 60",
"opera 48",
"safari 11"
]
} |
Beta Was this translation helpful? Give feedback.
-
This shipped in Next.js 13! Learn more: https://nextjs.org/blog/next-13 |
Beta Was this translation helpful? Give feedback.
-
Edit: This shipped in Next.js 13! Learn more: https://nextjs.org/blog/next-13
Background
Next.js currently targets ES5 for JS output and autoprefixes CSS in order to support legacy browsers. This results in much larger JS and CSS output because newer features need to be down-leveled.
For example, ES5 doesn’t include many of the JavaScript syntax features we use today such as async/await, Object rest/spread, for-of loop, optional chaining, nullish coalescing, etc.
In addition to syntax down-leveling, Next.js also injects polyfills such as
Object.assign()
,URL
, etc. However, those are only included in browsers that require them (using thenomodule
attribute).Proposal
We propose changing the default Next.js output to target modern browsers that support ES Modules, which accounts for 93% of global usage:
This change would reduce JS/CSS bundle size for all applications that use the default Next.js configuration. Next.js will continue to autoprefix CSS for the supported browsers above when necessary.
Changing the default output target would align Next.js with Vite and SvelteKit. In addition, most other tools don’t support ES5 such as esbuild and Angular.
The notable browser missing here is Internet Explorer which will soon reach End Of Life.
This would also fix obscure bugs caused by down-leveling to ES5 such as #30892.
Note: This proposal is not suggesting changing the output to ESM, but rather using that feature as a way to determine which browsers we consider “modern”.
Backwards Compatibility
Changing default configuration is considered semver major and will not ship until Next.js 13.
However, Next.js will still maintain backwards compatibility for developers who wish to upgrade to Next.js 13 and continue supporting legacy browsers, such as IE 11. There are a few options:
legacyBrowsers: true
innext.config.js
to emit the same JS/CSS output as today. This could work exactly the same as today. Alternatively, it could create two builds: one modern<script type=module>
and one legacy<script nomodule>
, therefore increasing build times..browserslistrc
andbrowserslist
frompackage.json
for PostCSS, but don’t pass it to the JavaScript transformations (yet). Browserslist is already supported in SWC, so we’d only have to pass the browserslist loading result as an option. (related discussion)Release Timeline
Changing default configuration is considered semver major and will not ship until Next.js 13.
However, users may wish to adopt this change today, so we could provide a flag to enable the new behavior with Next.js 12. Similar to the options above but reversed:
legacyBrowsers: false
innext.config.js
.browserslistrc
orbrowserslist
inpackage.json
Feedback
We’d love to hear your feedback on which solution would work better for your team and why.
Beta Was this translation helpful? Give feedback.
All reactions