[fix] StyleSheet SSR API

Without a getter, an outdated version of `sheet` is returned after
`getStyleSheet` is called. This is exposed in the public API via
`AppRegistry.getApplication`.

Close #1874
This commit is contained in:
Mathieu Dutour
2021-01-13 10:42:37 +01:00
committed by Nicolas Gallagher
parent a660377050
commit 900e7e5c01
2 changed files with 24 additions and 1 deletions
@@ -1,9 +1,11 @@
/* eslint-env jasmine, jest */
import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
import I18nManager from '../../I18nManager';
import ReactNativePropRegistry from '../ReactNativePropRegistry';
import createStyleResolver from '../createStyleResolver';
const canUseDOM = ExecutionEnvironment.canUseDOM;
let styleResolver;
describe('StyleSheet/createStyleResolver', () => {
@@ -74,5 +76,24 @@ describe('StyleSheet/createStyleResolver', () => {
test('resolves inline-style pointerEvents to classname', () => {
expect(styleResolver.resolve({ pointerEvents: 'box-none' })).toMatchSnapshot();
});
describe('sheet', () => {
beforeEach(() => {
ExecutionEnvironment.canUseDOM = false;
});
afterEach(() => {
ExecutionEnvironment.canUseDOM = canUseDOM;
});
test('returns the new sheet once re-initialized', () => {
const sheet = styleResolver.sheet;
// re-initialize the sheet
styleResolver.getStyleSheet();
expect(styleResolver.sheet).not.toBe(sheet);
});
});
});
});
@@ -237,7 +237,9 @@ export default function createStyleResolver() {
return result;
},
resolve,
sheet
get sheet() {
return sheet;
}
};
}