Skip to content

Doesn’t seem to receive new renderer when replaced #388

@alanhogan

Description

@alanhogan

Version: 6.0.0 (5.2.0 also)
Environment: DOM
Type: Bug


Description

It doesn't seem like the Fela Provider component updates its renderer when the renderer prop is updated.

Steps to reproduce

import React from 'react';

// Fela
import { Provider as FelaProvider } from 'react-fela';
import { createRenderer as createFelaRenderer } from 'fela';
import dynamicPrefixer from 'fela-plugin-dynamic-prefixer';
import fallbackValue from 'fela-plugin-fallback-value';
import rtl from 'fela-plugin-rtl';

export default class Providers extends React.Component {
  // Commented out to be sure this is not the source of the bug
  // // Need to generate a new Fela renderer for RTL vs LTR.
  // shouldComponentUpdate(nextProps, nextState) {
  //   return nextProps.rtl !== this.props.rtl;
  // }

  render() {
    const felaPlugins = [dynamicPrefixer({
        userAgent: navigator.userAgent,
        keepUnprefixed: true
      }),
      fallbackValue()
    ];

    if (this.props.rtl) felaPlugins.push(rtl());

    return (
      <FelaProvider renderer={createFelaRenderer({plugins: felaPlugins})}>
        {this.props.children}
      </FelaProvider>
    );
  }
}

// Then render the Providers component with dynamic rtl property
<Providers rtl={dynamic}>

Expected Behavior

RTL should be enabled or disabled as the appropriate property is toggled.

Actual Behavior

it does not. This is despite felaPlugins definitely gaining an additional item when rtl is true. And the rtl() plugin works if the initial state of the RTL variable is true (and then it keeps working when the RTL variable is false) or if it's hard-coded in the plugin array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions