Skip to content

Commit

Permalink
feat: add NullStyleInjector with warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Apr 4, 2020
1 parent 2ce54f2 commit 5dacdf2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions packages/glaze/src/StyleInjector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Based on:

import React from 'react';

import { canUseDOM } from './env';

const MAX_RULE_COUNT = 0xffff;

class RuleManager {
Expand Down Expand Up @@ -99,6 +101,27 @@ export interface StyleInjector {
nullifyRule(index: number): void;
}

export class NullStyleInjector implements StyleInjector {
ruleManager: RuleManager = new RuleManager(this, new Map());

// eslint-disable-next-line class-methods-use-this
addRule(): number {
// TODO: Add instructions for resolving the situation
if (canUseDOM) {
// eslint-disable-next-line no-console
console.warn('Client-side rendering of dynamic styles is not set up');
} else {
// eslint-disable-next-line no-console
console.warn('Server-side rendering of dynamic styles is not set up');
}

return 0;
}

// eslint-disable-next-line class-methods-use-this
nullifyRule(): void {}
}

export class VirtualStyleInjector implements StyleInjector {
ruleManager: RuleManager = new RuleManager(this, new Map());

Expand Down
4 changes: 2 additions & 2 deletions packages/glaze/src/StyleInjectorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import React from 'react';
import { canUseDOM, isDev } from './env';
import {
DebuggableStyleInjector,
NullStyleInjector,
OptimizedStyleInjector,
StyleInjector,
VirtualStyleInjector,
} from './StyleInjector';

export const StyleInjectorContext = React.createContext<StyleInjector>(
Expand All @@ -14,7 +14,7 @@ export const StyleInjectorContext = React.createContext<StyleInjector>(
? isDev
? new DebuggableStyleInjector()
: new OptimizedStyleInjector()
: new VirtualStyleInjector(), // TODO: Create a special warning class
: new NullStyleInjector(),
);

export interface StyleInjectorProviderProps {
Expand Down

0 comments on commit 5dacdf2

Please sign in to comment.