Skip to content

Commit

Permalink
[fix] StyleSheet SSR API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mathieudutour authored and necolas committed Jan 29, 2021
1 parent a660377 commit 900e7e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ export default function createStyleResolver() {
return result;
},
resolve,
sheet
get sheet() {
return sheet;
}
};
}

Expand Down

0 comments on commit 900e7e5

Please sign in to comment.