message: Only load text encoding polyfill if browser doesn't support it.
  Saves us 500kb of javascript loading on everything but Edge & IE.
diff: import * as _ from 'lodash';
  -import { TextEncoder as TextEncoderPoly } from 'text-encoding';
  import { getResources as getResources_} from './get-resources';
  import store from '../../redux';
  @@ -35,17 +34,25 @@ const isImpersonateEnabled = () => !!store.getState().UI.get('impersonate');
  const getImpersonateSubprotocols = () => {
  const {kind, name} = store.getState().UI.get('impersonate', {});
  if (!name) {
  - return;
  + return Promise.resolve();
  }
  - let encoder;
  + let textEncoder;
  try {
  - encoder = new TextEncoder('utf-8');
  + textEncoder = new TextEncoder('utf-8');
  } catch (e) {
  // eslint-disable-next-line no-console
  console.info('Browser lacks TextEncoder. Falling back to polyfill.', e);
  - encoder = new TextEncoderPoly('utf-8');
  }
  +
  + let promise;
  + if (textEncoder) {
  + promise = Promise.resolve(textEncoder);
  + } else {
  + promise = import('text-encoding').then(module => new module.TextEncoder('utf-8'));
  + }
  +
  + return promise.then(encoder => {
  /* Subprotocols are comma-separated, so commas aren't allowed. Also "="
  * and "/" aren't allowed, so base64 but replace illegal chars.
  */
  @@ -59,6 +66,7 @@ const getImpersonateSubprotocols = () => {
  if (kind === 'Group') {
  return [`Impersonate-Group.${enc}`];
  }
  + });
  };
  const actions = {
  @@ -150,18 +158,19 @@ const actions = {
  // start the process over when:
  // 1. the WS closes abnormally
  // 2. the WS can not establish a connection within $TIMEOUT
  - const pollAndWatch = () => (delete POLLs[id]) && k8sList(k8skind, query, true)
  - .then(res => {
  + const pollAndWatch = () => (delete POLLs[id]) && Promise.all([
  + getImpersonateSubprotocols(),
  + k8sList(k8skind, query, true).then(res => {
  dispatch(actions.loaded(id, res.items));
  if (WS[id]) {
  return;
  }
  -
  - const subProtocols = getImpersonateSubprotocols();
  -
  - const resourceVersion = res.metadata.resourceVersion;
  - WS[id] = k8sWatch(k8skind, {...query, resourceVersion}, {subProtocols, timeout: 60 * 1000})
  - .onclose(event => {
  + const { resourceVersion } = res.metadata;
  + return resourceVersion;
  + })
  + ]).then(([subProtocols, resourceVersion]) => {
  + WS[id] = WS[id] || k8sWatch(k8skind, {...query, resourceVersion}, {subProtocols, timeout: 60 * 1000});
  + WS[id].onclose(event => {
  // Close Frame Status Codes: https://tools.ietf.org/html/rfc6455#section-7.4.1
  if (event.code !== 1006) {
  return;
  @@ -186,6 +195,7 @@ const actions = {
  if (POLLs[id]) {
  return;
  }
  +
  POLLs[id] = setTimeout(pollAndWatch, 15 * 1000);
  })
  .onmessage(msg => {
  