jpudysz / react-native-unistyles

Level up your React Native StyleSheet

Home Page:https://unistyl.es

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hot reloading with custom plugins throws error

freddybreitenstein opened this issue · comments

Description

Error: You are trying to register a plugin with a name that is already registered

` public addPlugin = (plugin: UnistylesPlugin, notify: boolean = true) => {
if (plugin.name.startsWith('__unistyles')) {
throw new Error(UnistylesError.InvalidPluginName)
}

    if (this.plugins.some(({ name }) => name === plugin.name)) {
        throw new Error(UnistylesError.DuplicatePluginName)
    }

    this.plugins = [plugin].concat(this.plugins)
    this.unistylesBridge.addPlugin(plugin.name, notify)
}`

Fails on this.plugins = [plugin].concat(this.plugins)

Steps to reproduce

  1. Create the following plugin:
import type { UnistylesPlugin } from "react-native-unistyles";

export const fontFamilyPlugin: UnistylesPlugin = {
  name: "fontFamilyPlugin",
  onParsedStyle: (key, styles, runtime) => {
    styles.fontFamily = "Noto Sans";

    return styles;
  },
};
  1. Add it to the Unistyles config:
import { UnistylesRegistry } from "react-native-unistyles";

import { breakpoints } from "./breakpoints";
import { fontFamilyPlugin } from "./plugins/fontFamilyPlugin";
import { darkTheme, lightTheme } from "./themes";

export const initializeUnistyles = () =>
  UnistylesRegistry.addThemes({
    light: lightTheme,
    dark: darkTheme,
  })
    .addConfig({
      adaptiveThemes: true,
      plugins: [fontFamilyPlugin],
    })
    .addBreakpoints(breakpoints);

  1. Run your expo app on the iOS simulator
  2. Make a code change after launch and save so that the app hot reloads
  3. Error

Snack or a link to a repository (optional)

No response

Unistyles version

2.3.0

React Native version

0.73.4

Platforms

iOS

Engine

Hermes

Architecture

Paper (old)

Thanks for the report. I can disable throwing errors for DEV builds 👍 thanks for spotting it!

That was a quick reply if I ever saw one! Thanks I'd appreciate as it will get annoying in the long run.