An implementation of React v15.x that optimizes for small script size

Overview

react-lite

Travis npm Join the chat at https://gitter.im/Lucifier129/react-lite

Introduction

react-lite is an implementation of React that optimizes for small script size.

Note: react-lite dose not support React v16.x now.

Size Comparison

Framework Version Minified Size
Ember 2.2.0 446kb
Polymer 1.0.6 183kb
Angular 1.4.8 148kb
React 0.14.3 136kb
Web Components Polyfill 0.7.19 118kb
Riot 2.3.11 20kb
React-lite 0.15.6 25kb
preact + preact-compat 8.2.1 5kb

React-lite supports the core APIs of React, such as Virtual DOM, intended as a drop-in replacement for React, when you don't need server-side rendering in browser(no ReactDOM.renderToString & ReactDOM.renderToStaticMarkup).

Usage

If you are using webpack, it's so easy to use react-lite, just config alias in webpack.config.js:

// webpack.config.js
{
    resolve: {
        alias: {
            'react': 'react-lite',
            'react-dom': 'react-lite'
        }
    }
}

Note: feel free to try react-lite, if something happen and we can't fix it in time, then use regular react instead.

Installation

You can install react-lite from npm:

npm install react-lite --save

Browser compatibility

supports IE9+ / ES5 enviroment

Documentation

learn react-lite from React official documentation

What can react-lite do?

just the same as what react does, see some demos below(I just add the alias to webpack.config.js, no need to do anything else):

React-lite vs React

via react-lite:

  • all of React.PropTypes method is no-op(empty function)
  • use React in server side rendering, and use React-lite in browser
    • react-lite will replace the dom tree with new dom tree
    • you had better avoid script|head|link tag in client side
  • can not use react-dev-tool inspect react-lite, should switch to regular react for debugging
  • react-lite only works with a JSX toolchain(issue)
  • unlike react, event object in react-lite is always persistent, and event.persist is set as no-op to avoid throwing error.
  • react-lite can't work with react-tap-event-plugin, please use fastclick instead. or add alias 'react-tap-event-plugin': 'react-lite/lib/react-tap-event-plugin', just like here
  • can't work with transform-react-inline-elements, you will get a bundle include both react and react-lite.
  • react-lite just follow the best practice of React.

Test

react-lite reuses react's unitest(170), you can see them in __test__, and run the tests with:

npm test

License: MIT (See LICENSE file for details)

Comments
  • Can not read property '$ updater' of undefined.

    Can not read property '$ updater' of undefined.

    we develop the use of react-lite for build project, when i in the react componentWillReceiveProps method dispatch an action , the react-lite will show zhe error : Can not read property '$ updater' of undefined., but i use react to build project will not report this error.

    I know you have a fix in the previous version of this problem(https://github.com/Lucifier129/react-lite/issues/82), but I use the new master code when I will report this error, so i don't no how to fix it

    opened by GrubbyHunter 19
  • Error relating to vchildren

    Error relating to vchildren

    Context is that we use:

    • webpack2
    • webpack-dll
    • reactrouter
    • split bundles to deliver react components
    page.route.js:168 TypeError: Cannot read property 'vchildren' of undefined
        at destroyVelem (webpack:///./~/react-lite/dist/react-lite.common.js?:363:25)
        at destroyVnode (webpack:///./~/react-lite/dist/react-lite.common.js?:150:9)
        at destroyVelem (webpack:///./~/react-lite/dist/react-lite.common.js?:367:9)
        at destroyVnode (webpack:///./~/react-lite/dist/react-lite.common.js?:150:9)
        at destroyVcomponent (webpack:///./~/react-lite/dist/react-lite.common.js?:492:5)
        at destroyVnode (webpack:///./~/react-lite/dist/react-lite.common.js?:153:9)
        at destroyVcomponent (webpack:///./~/react-lite/dist/react-lite.common.js?:492:5)
        at destroyVnode (webpack:///./~/react-lite/dist/react-lite.common.js?:153:9)
        at destroyVcomponent (webpack:///./~/react-lite/dist/react-lite.common.js?:492:5)
        at destroyVnode (webpack:///./~/react-lite/dist/react-lite.common.js?:153:9)
    
    opened by roastlechon 14
  • lot of bugs

    lot of bugs

    It seems that whatever I try to do with your code, I ran into errors, bugs or strange behaviour. Obviously this code is at a very early stage and not ready for production.

    • TypeError: Failed to execute 'replaceChild' on 'Node': parameter 2 is not of type 'Node'.
    • TypeError: Cannot read property 'childNodes' of null
    • TypeError: Cannot read property 'tagName' of null

    This is just a few errors I get all the time. And this is related till how you are dealing with the children, the fact you are not removing any children etc.

    In your velem and the destroy function. Seems sometimes it can't find the children it should unmount. Sometimes 1 or more of the children are undefined or null.

    And a lot more.

    I suggest try to copy some of the stuff from Virtual DOM as I have seen you tried in the beginning, but changed from that path. They are also following React and doesnt have this errors.

    React-lite is a good attempt, but not ready yet. For now I got enough because of this and performance so I move away to better solutions.

    Maybe one day in the future I will check back on this repo

    opened by himalayafan 14
  • Horrible performance

    Horrible performance

    Hi! I ran the vdom benchmark, and I have to state that the performance is horrible. Any plans to fix this shortly? Else, a very great concept. But there are so many vdom libraries out there that have better performance.

    opened by himalayafan 13
  • Issues with replaceChild  + solution

    Issues with replaceChild + solution

    I open a new ticket for this one. As mentioned replaceChild can be read-only. I was looking into your code, and figured out how to fix this. My solution is then also related to performance issues.

    The solution:

    In each prototype - stateless, component etc, you add this in the top:

    this.element = null

    In the init section where you create , change to

    * node = this.element = ....*

    And then when you do a diff / update, you do this:

    * newElement.element = this.element*

    Got it?

    So then when it comes to destroy, you do this

    this.element.parentNode.replaceChild(this.element, newElement.element)

    In this solution you will not to do a typeof to check if its a function anymore. Will give you some better performance :)

    Great work with react-lite!

    opened by himalayafan 10
  • component update clears innerHTML?

    component update clears innerHTML?

    <Editor ref="edit" id="editor" className="edit"
                  style={{
                    fontFamily: fields.fontFamily.value,
                    fontSize: fields.fontSize.value,
                    fontWeight: fields.fontBold.value ? 'bold' : 'normal',
                    color: fields.fontColor.value,
                  }}
                  onKeyDown={(e)=>this.onKeyDown(e)}
                  onInput={(e)=>this.onInput(e)}
                  dangerouslySetInnerHTML={{__html: currConver.editor}} />
    

    It seems the innerHTML clears when one of the css style updates. When I switch back to react, it works. Is it a bug of react-lite?

    opened by fritx 10
  • Cannot read property '$updater' of undefined

    Cannot read property '$updater' of undefined

    Uncaught TypeError: Cannot read property '$updater' of undefined

    When I include the below in my webpack.config to use react-lite in place of react, I rec'ing the above error. When I remove react-lite, my app works as expected.

    Is there any good way of debugging this?

    resolve: {
        alias: {
          'react': 'react-lite',
          'react-dom': 'react-lite'
        }
      }
    
    opened by tysonnero 9
  • Select Value not selecting option

    Select Value not selecting option

    When using "select" tag, the selected option is not displayed. This works in Chrome, but not IE or Edge.

    Expected Dropdown to show with the selected value picked in Edge or IE.

    Actual The first item is selected

    Example https://jsfiddle.net/xy99xexh/3/

    opened by gpltaylor 7
  • not work with react-boilerplate?

    not work with react-boilerplate?

    amazing work !

    i use react-lite with react-boilerplate , it did shrink the build size, but got this error in brower (regular react works fine):

    image

    webpack config

    Reproduce:

    check out a demo for this issue if you have time, then npm install && npm run build && cd ./build

    opened by mydearxym 7
  • Is there some way of forcing peer dependencies to react-lite?

    Is there some way of forcing peer dependencies to react-lite?

    So, I really like this project and use it in production on several projects. One problem I run into over and over again has to do with peer deps. I'll pull an npm package into my project, eg this React lightbox component, and it ends up forcing regular React to be bundled instead of react-lite due to peer deps.

    Yes I could go in and change the peer deps on each package, but that defeats the purpose of a package manager. I'm using browserify by the way, but would gladly switch to webpack if it makes this easier. Is anyone aware of a good way to force peer deps?

    opened by isaachinman 7
  • remove use of innerHTML repalce with createElement? React 15

    remove use of innerHTML repalce with createElement? React 15

    React 15 removed use of innerHTML and now uses createElement. See latest release notes.

    You are still using innerHTML - wich is slow - a lot.

    Are you going to fix this?

    opened by himalayafan 7
  • Uncaught InvalidStateError: Failed to execute 'setSelectionRange' on 'HTMLInputElement': The input element's type ('number') does not support selection.

    Uncaught InvalidStateError: Failed to execute 'setSelectionRange' on 'HTMLInputElement': The input element's type ('number') does not support selection.

    image

    Uncaught InvalidStateError: Failed to execute 'setSelectionRange' on 'HTMLInputElement': The input element's type ('number') does not support selection.

    "react-lite": "^0.15.38", "fastclick": "^1.0.6",

    google chrome: 63.0.3239.132, set toggle device toolbar on

    related issue: https://github.com/ftlabs/fastclick/issues/358

    It's probably an issue for fastclick, but it affects src/react-lite/lib/react-tap-event-plugin.js

    opened by mrdulin 2
  • Should I install fastclick by myself?

    Should I install fastclick by myself?

    I do not see fastclick list on devDependencies of package.json .

    Should I install fastclick by myself? Or, just add alias 'react-tap-event-plugin': 'react-lite/lib/react-tap-event-plugin'?

    react-lite/lib/react-tap-event-plugin.js:

    'use strict';
    
    var Fastclick = require('fastclick');
    module.exports = function injectTapEventPlugin() {
    	var supportTouch = ('ontouchstart' in document);
    	if (supportTouch) {
    		Fastclick.attach(document.body);
    	}
    };
    
    opened by mrdulin 3
  • onClick handler triggered for disabled button

    onClick handler triggered for disabled button

    As you can see here, onClick handler is not triggered when a disabled button is clicked (which is correct). However, it is triggered when clicking a <span> inside a disabled button.

    Is this a valid behavior? I'm only encountering this issue with react-lite, works fine with react.

    opened by b3llash 0
  • Not triggering click event the first time when used with material-ui

    Not triggering click event the first time when used with material-ui

    The bug can reproduce with Chrome and Edge, works fine in Firefox. Also, anujs(https://github.com/RubyLouvre/anu, another React-like library) and React works fine.

    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3192.0 Safari/537.36

    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16251

    Example: https://lucifier129.github.io/material-ui/build/#/

    In Chrome, I have to double-click a MenuItem to trigger its onClick event with react-lite. image

    I found the source of bug: https://github.com/callemall/material-ui/blob/master/src/internal/TouchRipple.js#L210. I replaced the rippleGroup to <div />, the issue still exists.

    
          rippleGroup = (
    -       <ReactTransitionGroup style={prepareStyles(mergedStyles)}>
    -         {ripples}
    -       </ReactTransitionGroup>
    +       <div />
          );
        }
    
    

    Then I tried to debug react-lite. The first click didn't trigger click event.

    image qq 20170830112738

    So I wrapped dispatchEvent with setTimeout to wait 65ms, now the click triggered normally. Delaying batchUpdate is useless. image

    I think it's maybe any function canceled mouseup event, but there're no function controlled event. qq 20170830112958

    Now I have no clue...

    opened by zsxsoft 2
  • Recommendation: component RUM performance react-lite vs react

    Recommendation: component RUM performance react-lite vs react

    Hi team, Really, really like the clear and focused objective of react-lite. Would it be possible to see a RUM-style performance (network-time, dom-time, time-to-visual render time, etc) comparison of the same (material-ui or similar) component examples running in react-lite and react?

    Ideally, zero difference or possibly better runtime performance and far-better initial-call network performance with a smaller .js file, but without seeing a comparison just assumptions.

    opened by dhartford 1
Releases(v0.15.30)
Owner
工业聚
Thinking, coding and writing for fun
工业聚
Generate font size variables for a fluid type scale with CSS clamp.

Fluid Type Scale Calculator Generate font size variables for a fluid type scale with CSS clamp. Overview Customize everything, grab the output CSS, an

Aleksandr Hovhannisyan 136 Dec 31, 2022
This simple and small react component can check your repository stars and change theme on light/dark

Repository metrics for react This beauty and easy (4KB) react component can help you add metrics to your repositories also you can change component th

Koma Human 2 Jun 25, 2022
Small (0.5 Kb) react hook for getting media breakpoints state info in runtime

tiny-use-media Small (0.5 Kb) react hook for getting media breakpoints state info in runtime Usage npm i tiny-use-media --save Adn in your react code

Valeriy Komlev 51 Dec 13, 2022
This command line helps you create components, pages and even redux implementation for your react project

react-help-create This command line helps you create components, pages and even redux implementation for your react project. How to install it? To ins

Omar 27 Dec 10, 2022
KochSnowFlake - implementation of Koch Snowflake with React+ TS

Koch Snowflake if you just want to play with it, follow, FOLLOW THIS LINK if you are curios about math of this project, FOLLOW THIS LINK installation

Mahyar 1 Mar 13, 2022
Plock is a responsive masonry layout implementation for React. Very simple to use and easy to understand.

About Plock ?? Plock is a responsive masonry layout implementation for React. Very simple to use and easy to understand. Can I see a demo? ?? The demo

Renato Pozzi 130 Dec 9, 2022
An implementation of GitHub's Primer Design System using React

Primer React A React implementation of GitHub's Primer Design System Documentation Our documentation site lives at primer.style/react. You'll be able

Primer 2.2k Dec 26, 2022
This is a Javascript / React implementation of Discord's OverlappingPanels

Overlapping Panels Gestures-driven navigation UI for React.js This is a Javascript / React implementation of Discord's OverlappingPanels. Gesture-base

Paul Makles 5 Feb 18, 2022
✂ Multiple scenes, one canvas! WebGL Scissoring implementation for React Three Fiber.

react-three-scissor Multiple scenes, one canvas! WebGL Scissoring implementation for React Three Fiber. scissor lets you render an infinite number of

Poimandres 79 Dec 28, 2022
Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.

Recoil · Recoil is an experimental set of utilities for state management with React. Please see the website: https://recoiljs.org Installation The Rec

Facebook Experimental 18.2k Jan 8, 2023
How to submit HTML forms to Google Sheets. (Updated for 2021 Script Editor)

Submit a HTML form to Google Sheets How to submit a simple HTML form to a Google Sheet using only HTML and JavaScript. Updated for Google Script Edito

Levi Nunnink 314 Jan 6, 2023
A node script that lists the cities on Santa's route from santatracker.google.com

Google Santa Route A script that lists the cities on Santa's route from santatracker.google.com based on the JSON containing all Santa's destinations.

Emile Calixte 1 Dec 24, 2021
A very lightweight and flexible accessible modal dialog script.

A11y Dialog This is a lightweight (1.3Kb) yet flexible script to create accessible dialog windows. Documentation ↗ Demo on CodeSandbox ↗ Features: Clo

Kitty Giraudel 2.1k Jan 2, 2023
Script to remove unnecessary properties from package.json on prepublish hook

clean-pkg-json Script to remove unnecessary properties from package.json on prepublish hook. Support this project by ⭐️ starring and sharing it. Follo

hiroki osame 37 Oct 16, 2022
A small component based app library composing user interfaces and apps.

See https://vibejs.com for ongoing documentation and info. VibeJS A small component based JavaScript library to build user interfaces and apps. If you

Bret 20 Nov 16, 2022
A small tool to help you check package duplicates in `yarn.lock`

Yarn Duplicate A small tool to help you check duplicate package and package size in yarn.lock. Usage Change to your project root folder, which have a

Cam Song 14 Aug 11, 2021
Grid-tool - Small tool that allows you to integrate a predefined or generated grid into your front-end development environment.

Grid tool Small tool that allows you to integrate a predefined or generated grid into your front-end development environment. Tool installation includ

hmongouachon 2 Jan 4, 2022
A small CLI tool to create a semantic release and git-cliff powered Changelog

cliff-jumper A small CLI tool to create a semantic release and git-cliff powered Changelog Description When managing a collection of projects you ofte

Favware 15 Sep 22, 2022
A small application to categorize and track your income and expenses.

Expense Tracker App with Typescript A small application to categorize and track your income and expenses. Expense Tracker App Demo Link You can check

Özge Coşkun Gürsucu 22 Jul 1, 2022