-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IE11 Compatibility #6
Comments
I haven't tried it, but you should be able to use proxy-polyfill. If you would like to try this library with proxy-polyfill, I'm happy to help. |
@dai-shi what do you think of a compatibility mode alternative where it falls back to just rendering everything? |
@andrewluetgers Yeah, that should be one option, if it's OK with the app. const useTrackedStateWithFallback =
typeof Proxy !== 'undefined' ? () => useTrackedState() : () => useSelector(s => s); |
I managed to use IE with fallback to Context. First problem is that your library is published in ES6 and i couldnt add it to Babel transform, so i copied it to external. Next i had to add fake pollyfills, without these, IE panicked. window.Symbol = window.Symbol || (() => null);
window.Reflect = window.Reflect || {}; Then i added switch between tracked and untracked version to my store /**
* react-tracked does not support IE11 (no Proxy)
* IE will still load library but wont use it
* It will be slow but working
* No extra libraries are loaded for modern browsers in this case
*/
const factory = window.Proxy ? trackedFactory : untrackedFactory;
export const {
CheckoutStore,
useTracked,
useTrackedState,
useUpdate,
useSelector,
memo,
getUntrackedObject,
} = factory(reducer, initialState, asyncActionHandlers); And lastly there are those two factories types import * as React from 'react';
import { createContainer, memo, getUntrackedObject } from '_TS_/libs/external/react-tracked';
import useReducerAsync from '../useReducerAsync';
const trackedFactory = (reducer, initialState, asyncActionHandlers) => {
/**
* `react-tracked` takes care of unneeded rerenders
*/
const {
Provider,
useTracked,
useTrackedState,
useUpdate,
useSelector,
}: {
Provider;
useTracked(any?): [CheckoutState, React.Dispatch<CheckoutAction>];
useTrackedState(): CheckoutState;
useUpdate(): React.Dispatch<CheckoutAction>;
useSelector(selector: (state: CheckoutState) => unknown);
} = createContainer(() => useReducerAsync(
reducer,
initialState,
asyncActionHandlers,
));
const CheckoutStore = (props: { children }): React.ReactElement => {
const { children } = props;
return (
<Provider>
{children}
</Provider>
);
};
return {
CheckoutStore,
useTracked,
useTrackedState,
useUpdate,
useSelector,
memo,
getUntrackedObject,
};
};
export default trackedFactory; import * as React from 'react';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
import useReducerAsync from '../useReducerAsync';
const untrackedFactory = (reducer, initialState, asyncActionHandlers) => {
const CheckoutStoreContext = React.createContext<[ CheckoutState, any ]>(null);
const CheckoutStore = (props: {children}): React.ReactElement => {
const { children } = props;
const [state, dispatch] = useReducerAsync(reducer, initialState, asyncActionHandlers);
return (
<CheckoutStoreContext.Provider value={[state, dispatch]}>
{ children }
</CheckoutStoreContext.Provider>
);
};
const useTracked = (): [CheckoutState, React.Dispatch<CheckoutAction>] => (
React.useContext(CheckoutStoreContext)
);
const useSelector = (selector: (state: CheckoutState) => unknown): unknown => {
const [state] = React.useContext(CheckoutStoreContext);
return selector(state);
};
const useUpdate = (): React.Dispatch<CheckoutAction> => {
const [,dispatch] = React.useContext(CheckoutStoreContext);
return dispatch;
};
const useTrackedState = (): CheckoutState => {
const [state] = React.useContext(CheckoutStoreContext);
return state;
};
return {
CheckoutStore,
useTracked,
useTrackedState,
useUpdate,
useSelector,
memo: React.memo,
getUntrackedObject: (obj) => obj, // just return given
};
};
export default untrackedFactory; |
@aiphee Thanks sooooo much for your trial and those notes!
However, I knew not all bundlers can configure it very well.
OK, I didn't know this. This means that proxy-polyfill isn't enough for IE11 anyway.
Cool.
Are you interested in trying proxy-polyfill? If so, I can try working on resolving |
Closing this. If someone is interested in it, I will reopen it. |
Not an issue but just want to confirm there is no support to < IE 11 since this library is using proxy.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#Browser_compatibility
And it's also not possible to be compiled or polyfilled by webpack or babel as per discussion below:
https://stackoverflow.com/questions/45285992/es6-proxy-polyfill-for-ie11?rq=1
Any advice would be appreciated!
The text was updated successfully, but these errors were encountered: