Coder Social home page Coder Social logo

Comments (7)

Dryymoon avatar Dryymoon commented on September 24, 2024

I have adapted version for latest React 15*.
Fully worked example, but for now its very simple:
https://gist.github.com/Dryymoon/49f2d5d631b6ba9a35ac663e59c193ce
The advantage of this solution - that for cache props calculated very deeply and fast.
Not testen in prod.

from react-ssr-optimization.

megatolya avatar megatolya commented on September 24, 2024

Ok! thanks a lot 👍

from react-ssr-optimization.

megatolya avatar megatolya commented on September 24, 2024

@Dryymoon can you help me?

I replaced electrode-react-ssr-optimization/lib/index.js file with your gist. And got error:

 TypeError: Can't add property _instantiateReactComponent, object is not extensible
    at WrappedInstantiateReactComponent (/Users/megatolya/workspace/mobile/node_modules/electrode-react-ssr-optimization/lib/index.js:95:46)
    at /Users/megatolya/workspace/mobile/node_modules/domino-react/lib/ReactServerRendering.js:37:31
    at ReactServerRenderingTransaction.Mixin.perform (/Users/megatolya/workspace/mobile/node_modules/domino-react/lib/Transaction.js:136:20)
    at renderToStringImpl (/Users/megatolya/workspace/mobile/node_modules/domino-react/lib/ReactServerRendering.js:36:24)
    at Object.renderToString (/Users/megatolya/workspace/mobile/node_modules/domino-react/lib/ReactServerRendering.js:54:10)
    at _store (/Users/megatolya/workspace/mobile/app/lib/utils/render.js:47:53)
    at Object.renderLayout (/Users/megatolya/workspace/mobile/app/lib/utils/render.js:74:31)
    at Object.Wrapper (/Users/megatolya/workspace/mobile/app/wrapper.js:80:29)
    at next (native)
    at onFulfilled (/Users/megatolya/workspace/mobile/node_modules/co/index.js:65:19)

which refs here: https://gist.github.com/Dryymoon/49f2d5d631b6ba9a35ac663e59c193ce#file-reactcachepatch-js-L90
Without replacing was the same error.
Tried it on react 0.14.8 and 0.15.1.
Stackoverflow says components are freezed now and you can't access them directly but you can clone them. So I removed all Object.preventExtensions (instantiateReactComponent.js) and Object.freeze (react/lib/ReactElement.js) from react.
And it stopped throwing exceptions. But cache didnt work.

const reactOptimizer = require("electrode-react-ssr-optimization");
const keyGenerator = props => {
   console.log('hello!', props);
   return 'asd';
};
reactOptimizer.add('MovieHeader', keyGenerator);
reactOptimizer.enable(true);

In console was:

React Caching Enabled :)
React succesful Patched for Caching
React succesful Patched for Caching

But component was updating like before. keyGenerator wasnt called. What can be wrong with my prj?

I can try make simple app which reproduce error if you want.

from react-ssr-optimization.

Dryymoon avatar Dryymoon commented on September 24, 2024

This code not needed - const reactOptimizer = require("electrode-react-ssr-optimization"); const keyGenerator = props => { console.log('hello!', props); return 'asd'; }; reactOptimizer.add('MovieHeader', keyGenerator); reactOptimizer.enable(true);
And electrode-react-ssr-optimization not used at all in my component.

Partial Example of My webpack config for server build:

var config = {}; config.devtool = 'cheap-module-source-map'; config.context = appRootDir; config.entry = []; config.entry.push('./src/helpers/react/ReactCachePatch.js'); config.entry.push('./src/server.js'); config.target = 'node'; config.node = { global: true, __dirname: false, __filename: false, process: true, Buffer: true }; ...

See "ReactCachePatch" In this config entries it come before any entery.
For use without webpack Include this file in main or bootstrap server script(once on porject) before any imports or requires of react or any components that uses react.

When This patch only works when NODE_ENV=== 'production', because in dev mode React checking for imutability of component.

For now - usage - in any react class ->
export default class ... extends Component { static cache = {} // No attributes for now. render() {...} }

static cache = {} <- it instruct ReactCache Module for enabling smart cache for this component.

from react-ssr-optimization.

Dryymoon avatar Dryymoon commented on September 24, 2024

How you and others paste code in comments on Github in pretty style?

from react-ssr-optimization.

megatolya avatar megatolya commented on September 24, 2024

ok thx i'll try it later!

How you and others paste code in comments on Github in pretty style?

like this:
screen shot 2016-09-09 at 20 50 54

from react-ssr-optimization.

megatolya avatar megatolya commented on September 24, 2024

I reproduced the way you described. It seems working but I have some questions about how to control it.

It works if i add static cache = {} to top-level components but dumb components are not cached. For example, If i add static cache = {} to MoviePage (smart component), then it will be cached and movie pages would be the same for all different movies (that have totally another props). So I don't control cache validation and it seems useless.

In electrode readme you described a way to validate cache of components with cool api. Can I do the same things with your new flow?

P.S. am i right that electrode (this repo) is not used in your new flow. And ReactCache module is only file that do all cache work?
P.P.S. we can speak russian if you ok 😊

from react-ssr-optimization.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.