Next.js: [docs] Document config.clientBootstrap

Created on 13 Dec 2017  路  4Comments  路  Source: vercel/next.js

The recently added config option for adding a custom bootstrap file to the main bundle is mentioned only in comments here and there so far, so thought to turn this into an actual task for clarity.

References:

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior


I'd expect to

  • find config.clientBootstrap documented in main README
  • find an example showing how to use this (suggestion: use something common like babel-polyfill in the example to help issues such as #2468)

As a side note, it seems that there are no tests exercising this config option, but perhaps that can be seen as a different task than these docs.

Notes

Something to be aware of with this config (and the docs): sadly this option does not help with everything. I tried to add EventSource polyfill for webpack-hot-middleware to make the dev mode work in IE11, but this custom bootstrap is injected too late and thus it does not help with this kind of polyfilling.

Most helpful comment

@arunoda made an example internally, he can commit it to the repository 馃憤

All 4 comments

@arunoda made an example internally, he can commit it to the repository 馃憤

I'm trying to run a polyfill for intersection-observer using the clientBootstrap:

async function loadPolyfills() {
    const polyfills = [];
    console.log("Running polyfills!");
    if(!supportsIntersectionObserver()) {
        polyfills.push(import('intersection-observer'))
    }

    let all = await Promise.all(polyfills);
    return all;
}

function supportsIntersectionObserver() {
    return (
        'IntersectionObserver' in global &&
        'IntersectionObserverEntry' in global &&
        'intersectionRatio' in IntersectionObserverEntry.prototype
    )
}

loadPolyfills().then((polyfills) => {
    console.log(polyfills);
});

Unfortunately my react code is starting before the polyfill loads. What am I missing here?

We might remove clientBootstrap feature from Next.js in the future.
So instead use this: https://github.com/zeit/next.js/pull/3568

It's the same as clientBootstrap, but just using webpack config.

@designspin your issue is because of the promise usage.
Try to load polyfills using NPM as shown in the ^^ mentioned example.
If not, start a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

havefive picture havefive  路  3Comments

renatorib picture renatorib  路  3Comments

timneutkens picture timneutkens  路  3Comments

formula349 picture formula349  路  3Comments

olifante picture olifante  路  3Comments