Comments (7)
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.
Ok! thanks a lot 👍
from react-ssr-optimization.
@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.
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.
How you and others paste code in comments on Github in pretty style?
from react-ssr-optimization.
ok thx i'll try it later!
How you and others paste code in comments on Github in pretty style?
from react-ssr-optimization.
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)
- Compatibility with Webpack and Babel HOT 3
- difference between electrode-react-ssr-caching? HOT 1
- Cache All Option? HOT 1
- TypeError: Can't add property _instantiateReactComponent, object is not extensible HOT 1
- Cache based on context HOT 2
- Webpack integration HOT 4
- Cached template strings causes issues with escaped strings HOT 1
- Avoid caching a component because of a prop HOT 2
- React streaming HOT 2
- Module is not working with react and react-dom 16.4.0 HOT 3
- Is react and react-dom required in package.json? HOT 2
- Still Maintained?
- Alternative?
- Template Attrs open to XSS
- Feature Request: Allow environment setting REACT_SSR_OPTIMIZATION_ENV with fallback to NODE_ENV HOT 3
- Wrong images URL in the HTML rendered by the server HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-ssr-optimization.