From c0260589f5d54f2792c2add69722115f8f4f9cc3 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Wed, 19 Oct 2016 14:39:56 +1100 Subject: [PATCH 01/30] Removed a doc heading that no longer linked --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 0ab5e57..f87db89 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@ Documentation - [Usage in development](#usage-in-development) - [Usage in production](#usage-in-production) - [Overriding the renderer](#overriding-the-renderer) -- [Django integration](#django-integration) - [Settings](#settings) - [Running the tests](#running-the-tests) From e0ad6ae2da3795ed0c345f141983fb3064af3b98 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Wed, 19 Oct 2016 14:56:14 +1100 Subject: [PATCH 02/30] Added a Frequently Asked Questions to the docs Links to @Anima-t3d's investigation in #70 --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index f87db89..7aee006 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Documentation - [Usage in production](#usage-in-production) - [Overriding the renderer](#overriding-the-renderer) - [Settings](#settings) +- [Frequently Asked Questions](#frequently-asked-questions) - [Running the tests](#running-the-tests) @@ -285,6 +286,19 @@ A complete url to an endpoint which accepts POST requests conforming to Default: `'http://127.0.0.1:9009/render'` +Frequently Asked Questions +-------------------------- + +### Can python-react integrate with Django? + +python-react can integrate with Django's settings and the renderer integration can resolve relative paths to components via django's static file finders. + +### Can python-react integrate with Web2Py? + +[@Anima-t3d](https://github.com/Anima-t3d) has a write-up of their experience +in [#70](https://github.com/markfinger/python-react/issues/70#issuecomment-254396083). + + Running the tests ----------------- From 8dc3a11a6be50e33a029f340833a8b00d263e853 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Mon, 16 Jan 2017 10:03:27 +1100 Subject: [PATCH 03/30] Added production warning re: `NODE_ENV` --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 7aee006..868fbdc 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,11 @@ In production environments, you should ensure that `RENDER` is set to True. You will want to run the render server under whatever supervisor process suits your need. Depending on your setup, you may need to change the `RENDER_URL` setting to reflect your environment. +The render server should be run with the `NODE_ENV` environment variable set to `production`, +eg: `NODE_ENV=production node render_server.js`. React defaults to development mode and relies on the +`NODE_ENV` variable to deactivate dev-oriented code (types and constraint checking) that slows down renders. +Defining this variable will ensure that your code is rendered much faster. + Depending on your load, you may want to use a worker farm to handle rendering. Node's [cluster module](https://nodejs.org/api/cluster.html) provides an easy way to fork a process and serve multiple instances from a single network address. From 6d10b59b41691d9db908323a5babd604b0fdef4b Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Mon, 16 Jan 2017 12:18:24 +1100 Subject: [PATCH 04/30] CI fixes + docs --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index eba3223..2308405 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,15 @@ env: - DJANGO_VERSION=1.8.1 install: + # Install node 6 (current LTS as of January 2017) + - "rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install 6" + # Install latest npm - "npm install -g npm" + # Install node deps for render server - "cd tests" - "npm install" - "cd .." + # Setup python packages - "pip install Django==$DJANGO_VERSION" - "pip install -r requirements.txt" From 17b6c61ce72600d72ed39b9791cba78e64bc279e Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Mon, 16 Jan 2017 13:48:32 +1100 Subject: [PATCH 05/30] CI fix to improve error clarity --- tests/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index e2ef88f..ffd9cfa 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -13,8 +13,16 @@ output = process.stdout.readline().decode('utf-8') +def read_line(): + return process.stdout.readline().decode('utf-8') + if output.strip() == '': - output += process.stdout.readline().decode('utf-8') + output += read_line() if 'React render server' not in output: - raise Exception('Unexpected output: "{}"'.format(output)) + if 'module.js' in output: + line = read_line() + while line: + output += line + os.linesep + line = read_line() + raise Exception('Unexpected output from render server subprocess...' + os.linesep + os.linesep + output) From be10f22367fd9072e346f4d9837e417c2de71676 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Mon, 16 Jan 2017 13:49:52 +1100 Subject: [PATCH 06/30] Code cleanup for the test suite's subprocess --- tests/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index ffd9cfa..b8d4847 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -11,11 +11,10 @@ # Ensure the process is killed on exit atexit.register(lambda _process: _process.kill(), process) -output = process.stdout.readline().decode('utf-8') - def read_line(): return process.stdout.readline().decode('utf-8') +output = read_line() if output.strip() == '': output += read_line() From 44186cb217d617f50c511c10df8432eca463e3eb Mon Sep 17 00:00:00 2001 From: Corey Burmeister Date: Thu, 23 Feb 2017 09:46:07 -0800 Subject: [PATCH 07/30] Add timeout to RenderServer.render() This commit adds a configurable timeout to the `render` method signature within `RenderServer`. This defaults to 10 seconds; 5 for sending the request and 5 for reading the response. --- react/render_server.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/react/render_server.py b/react/render_server.py index 63b07be..33cbf67 100644 --- a/react/render_server.py +++ b/react/render_server.py @@ -20,7 +20,10 @@ def __unicode__(self): class RenderServer(object): - def render(self, path, props=None, to_static_markup=False, request_headers=None): + def render( + self, path, props=None, to_static_markup=False, request_headers=None, + timeout=None + ): url = conf.settings.RENDER_URL if props is not None: @@ -45,12 +48,17 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None) if request_headers is not None: all_request_headers.update(request_headers) + # Add a send/receive timeout with the request if not specified + if not isinstance(timeout, (tuple, int, float)): + timeout = (5, 5) + try: res = requests.post( url, data=serialized_options, headers=all_request_headers, - params={'hash': options_hash} + params={'hash': options_hash}, + timeout=timeout ) except requests.ConnectionError: raise RenderServerError('Could not connect to render server at {}'.format(url)) From b1e09d36f741ee9027f790c469c7ac0f6b67492a Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Tue, 28 Feb 2017 08:23:05 +1100 Subject: [PATCH 08/30] Update documentation for RenderServer API. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 868fbdc..14237f9 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,7 @@ you can consistently define the `renderer` argument to `render_component`. For e from react.render import render_component class MyRenderer(object): - def render(self, path, props=None, to_static_markup=False): + def render(self, path, props=None, to_static_markup=False, request_headers=None, timeout=None): # ... def my_render_function(*args, **kwargs): From c811ca6c4c4cac127e2298a25bcb895fbccee0e3 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Tue, 28 Feb 2017 08:23:40 +1100 Subject: [PATCH 09/30] 4.0.0 --- CHANGELOG.md | 16 ++++++++++++++++ react/__init__.py | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76c631c..cd44dbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,22 @@ Changelog ========= +### 4.0.0 (28/2/2017) + +- **Possibly breaking change** `RenderServer.render` now accepts a `timeout` keyword argument. There are some + edge-cases where this may break down-stream code. + ([Corey Burmeister](https://github.com/cburmeister)) + https://github.com/markfinger/python-react/pull/73 +- Documentation updates regarding production environments. The key takeaway is to ensure that you are using + the `NODE_ENV=production` environment variable so that React runs without debugging helpers which slow down + rendering. +- Documentation updates regarding `RenderServer` API. + +### 3.0.1 (6/4/2016) + +- Documentation updates. + + ### 3.0.0 (6/4/2016) - **Possibly breaking change** render_component now accepts a `request_headers` keyword argument. diff --git a/react/__init__.py b/react/__init__.py index 90a0993..917afc5 100644 --- a/react/__init__.py +++ b/react/__init__.py @@ -1,3 +1,3 @@ -__version__ = '3.0.1' +__version__ = '4.0.0' default_app_config = 'react.apps.ReactConfig' \ No newline at end of file From 2e2823537100615d8d6f9547dfb4099adad43229 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Tue, 28 Feb 2017 08:36:32 +1100 Subject: [PATCH 10/30] Updating FAQ --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 14237f9..6875957 100644 --- a/README.md +++ b/README.md @@ -296,13 +296,24 @@ Frequently Asked Questions ### Can python-react integrate with Django? -python-react can integrate with Django's settings and the renderer integration can resolve relative paths to components via django's static file finders. +python-react can integrate with Django's settings and the renderer integration can +resolve relative paths to components via django's static file finders. + +### How do I handle Django's translation and gettext with React components? + +[@sillygod](https://github.com/sillygod) sparked a discussion of this at issue +[#69](https://github.com/markfinger/python-react/issues/69). ### Can python-react integrate with Web2Py? [@Anima-t3d](https://github.com/Anima-t3d) has a write-up of their experience in [#70](https://github.com/markfinger/python-react/issues/70#issuecomment-254396083). +### How do I pass child components to the root component? + +[@Anima-t3d](https://github.com/Anima-t3d) sparked a discussion of this at issue +[#70](https://github.com/markfinger/python-react/issues/71). + Running the tests ----------------- From 84e2f19dc7e5e1a235e4928d19b345d2d8f8f768 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Tue, 28 Feb 2017 08:37:38 +1100 Subject: [PATCH 11/30] Not sure why I added those at symbols... --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6875957..2d65b64 100644 --- a/README.md +++ b/README.md @@ -301,17 +301,17 @@ resolve relative paths to components via django's static file finders. ### How do I handle Django's translation and gettext with React components? -[@sillygod](https://github.com/sillygod) sparked a discussion of this at issue +[sillygod](https://github.com/sillygod) sparked a discussion of this at issue [#69](https://github.com/markfinger/python-react/issues/69). ### Can python-react integrate with Web2Py? -[@Anima-t3d](https://github.com/Anima-t3d) has a write-up of their experience +[Anima-t3d](https://github.com/Anima-t3d) has a write-up of their experience in [#70](https://github.com/markfinger/python-react/issues/70#issuecomment-254396083). ### How do I pass child components to the root component? -[@Anima-t3d](https://github.com/Anima-t3d) sparked a discussion of this at issue +[Anima-t3d](https://github.com/Anima-t3d) sparked a discussion of this at issue [#70](https://github.com/markfinger/python-react/issues/71). From d8e8b4572f18da30397927fed7155a328348ede8 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Tue, 28 Feb 2017 08:38:53 +1100 Subject: [PATCH 12/30] Typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d65b64..f1650cc 100644 --- a/README.md +++ b/README.md @@ -312,7 +312,7 @@ in [#70](https://github.com/markfinger/python-react/issues/70#issuecomment-25439 ### How do I pass child components to the root component? [Anima-t3d](https://github.com/Anima-t3d) sparked a discussion of this at issue -[#70](https://github.com/markfinger/python-react/issues/71). +[#71](https://github.com/markfinger/python-react/issues/71). Running the tests From 1bad117ab36ced678b3c99b876b5e3eb7baa0750 Mon Sep 17 00:00:00 2001 From: Corey Burmeister Date: Tue, 28 Feb 2017 14:08:42 -0800 Subject: [PATCH 13/30] Extend timeout to render_component() This commit extends the `timeout` parameter within `RenderServer.render` to `render_component`. --- react/render.py | 4 ++-- react/render_server.py | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/react/render.py b/react/render.py index 83173d0..447c340 100644 --- a/react/render.py +++ b/react/render.py @@ -4,7 +4,7 @@ from .render_server import render_server -def render_component(path, props=None, to_static_markup=False, renderer=render_server, request_headers=None): +def render_component(path, props=None, to_static_markup=False, renderer=render_server, request_headers=None, timeout=None): if not os.path.isabs(path): abs_path = staticfiles.find(path) if not abs_path: @@ -14,4 +14,4 @@ def render_component(path, props=None, to_static_markup=False, renderer=render_s if not os.path.exists(path): raise ComponentSourceFileNotFound(path) - return renderer.render(path, props, to_static_markup, request_headers) + return renderer.render(path, props, to_static_markup, request_headers, timeout=timeout) diff --git a/react/render_server.py b/react/render_server.py index 33cbf67..a7b1907 100644 --- a/react/render_server.py +++ b/react/render_server.py @@ -20,10 +20,7 @@ def __unicode__(self): class RenderServer(object): - def render( - self, path, props=None, to_static_markup=False, request_headers=None, - timeout=None - ): + def render(self, path, props=None, to_static_markup=False, request_headers=None, timeout=None): url = conf.settings.RENDER_URL if props is not None: From e2e343bbd04abee2c28f22b1bc63e06b54f9a97c Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Wed, 1 Mar 2017 10:25:26 +1100 Subject: [PATCH 14/30] Docs for #74 --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index f1650cc..da12786 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,12 @@ render_component( request_headers={ 'Accept-Language': 'da, en-gb;q=0.8, en;q=0.7' }, + + # An optional timeout that is used when handling communications with the render server. + # Can be an integer, a float, or a tuple containing two numeric values (the two values + # represent the individual timeouts on the send & receive phases of the request). + # Note that if not defined, this value will default to (5, 5) + timeout=None ) ``` From 75d87a26e69f51606b6d34c2e648ca8007490f22 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Wed, 1 Mar 2017 10:25:46 +1100 Subject: [PATCH 15/30] 4.1.0 --- CHANGELOG.md | 7 +++++++ react/__init__.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd44dbb..07f3f60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changelog ========= +### 4.1.0 (1/3/2017) + +- `render_component` now accepts a `timeout` keyword argument which is passed to `RenderServer.render`. + ([Corey Burmeister](https://github.com/cburmeister)) + https://github.com/markfinger/python-react/pull/74 + + ### 4.0.0 (28/2/2017) - **Possibly breaking change** `RenderServer.render` now accepts a `timeout` keyword argument. There are some diff --git a/react/__init__.py b/react/__init__.py index 917afc5..5e58b2f 100644 --- a/react/__init__.py +++ b/react/__init__.py @@ -1,3 +1,3 @@ -__version__ = '4.0.0' +__version__ = '4.1.0' default_app_config = 'react.apps.ReactConfig' \ No newline at end of file From 58b2b608d125519bcce8036f6046c8f131491b4f Mon Sep 17 00:00:00 2001 From: Mike Plis Date: Tue, 8 Aug 2017 08:51:35 -0400 Subject: [PATCH 16/30] Update render_server.py --- react/render_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react/render_server.py b/react/render_server.py index a7b1907..2cecaa2 100644 --- a/react/render_server.py +++ b/react/render_server.py @@ -47,7 +47,7 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None, # Add a send/receive timeout with the request if not specified if not isinstance(timeout, (tuple, int, float)): - timeout = (5, 5) + timeout = 5.0 try: res = requests.post( From 5631e2b211be5b1a6f2b74893a1fab8b591c03df Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Wed, 9 Aug 2017 10:14:35 +1000 Subject: [PATCH 17/30] 4.1.1 --- CHANGELOG.md | 8 ++++++++ react/__init__.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07f3f60..94fcd9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Changelog ========= +### 4.1.1 (9/8/2017) + +- Update timeout in render_server.py. + ([Mike Plis](https://github.com/mplis)) + https://github.com/markfinger/python-react/pull/81 + + + ### 4.1.0 (1/3/2017) - `render_component` now accepts a `timeout` keyword argument which is passed to `RenderServer.render`. diff --git a/react/__init__.py b/react/__init__.py index 5e58b2f..2906628 100644 --- a/react/__init__.py +++ b/react/__init__.py @@ -1,3 +1,3 @@ -__version__ = '4.1.0' +__version__ = '4.1.1' default_app_config = 'react.apps.ReactConfig' \ No newline at end of file From f6a13d354f216f6e4792c84eb9f0f07b3572bd82 Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Mon, 16 Jul 2018 11:19:11 +0430 Subject: [PATCH 18/30] API for returning extra items returned by render server --- react/render_server.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/react/render_server.py b/react/render_server.py index 2cecaa2..54f84c3 100644 --- a/react/render_server.py +++ b/react/render_server.py @@ -8,9 +8,10 @@ class RenderedComponent(object): - def __init__(self, markup, props): + def __init__(self, markup, props, extra): self.markup = markup self.props = props + self.extra = extra def __str__(self): return self.markup @@ -67,8 +68,9 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None, obj = res.json() - markup = obj.get('markup', None) - err = obj.get('error', None) + markup = obj.pop('markup', None) + err = obj.pop('error', None) + extra = obj if err: if 'message' in err and 'stack' in err: @@ -80,7 +82,7 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None, if markup is None: raise ReactRenderingError('Render server failed to return markup. Returned: {}'.format(obj)) - return RenderedComponent(markup, serialized_props) + return RenderedComponent(markup, serialized_props, extra) render_server = RenderServer() From db30691d18656d81907eb5daaedf0d0d306cbf6c Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Mon, 16 Jul 2018 20:44:21 +0430 Subject: [PATCH 19/30] Renamed extra to data --- react/render_server.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/react/render_server.py b/react/render_server.py index 54f84c3..13bbcae 100644 --- a/react/render_server.py +++ b/react/render_server.py @@ -8,10 +8,10 @@ class RenderedComponent(object): - def __init__(self, markup, props, extra): + def __init__(self, markup, props, data): self.markup = markup self.props = props - self.extra = extra + self.data = data def __str__(self): return self.markup @@ -70,7 +70,7 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None, markup = obj.pop('markup', None) err = obj.pop('error', None) - extra = obj + data = obj if err: if 'message' in err and 'stack' in err: @@ -82,7 +82,7 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None, if markup is None: raise ReactRenderingError('Render server failed to return markup. Returned: {}'.format(obj)) - return RenderedComponent(markup, serialized_props, extra) + return RenderedComponent(markup, serialized_props, data) render_server = RenderServer() From 1167ba033ee1747005dd3dba1643d22c83e04233 Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Mon, 16 Jul 2018 22:44:55 +0430 Subject: [PATCH 20/30] Added new data api to the docs --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index da12786..31470e9 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ The object returned has two properties: - `markup` - the rendered markup - `props` - the JSON-serialized props + - `data` - extra data returned by the render server If the object is coerced to a string, it will emit the value of the `markup` attribute. @@ -82,6 +83,8 @@ for a simple server that will cover most cases. The key files for the render ser - [render_server.js](examples/basic_rendering/render_server.js) - the server's source code - [package.json](examples/basic_rendering/package.json) - the server's dependencies, installable with [npm](http://npmjs.com) + +You can also return extra data from your render server and these data will be stored in `data` attribute of the response object. Using React on the front-end From cb554d974646a7ea17de35012668fd191c00e009 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Tue, 17 Jul 2018 10:23:41 +1000 Subject: [PATCH 21/30] Docs Added some more detail/example for the `data` prop. Fixed some mixed tabs/spaces in the docs. --- README.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 31470e9..a2d4e40 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ The object returned has two properties: - `markup` - the rendered markup - `props` - the JSON-serialized props - - `data` - extra data returned by the render server + - `data` - the data returned by the render server If the object is coerced to a string, it will emit the value of the `markup` attribute. @@ -83,8 +83,6 @@ for a simple server that will cover most cases. The key files for the render ser - [render_server.js](examples/basic_rendering/render_server.js) - the server's source code - [package.json](examples/basic_rendering/package.json) - the server's dependencies, installable with [npm](http://npmjs.com) - -You can also return extra data from your render server and these data will be stored in `data` attribute of the response object. Using React on the front-end @@ -258,7 +256,7 @@ from react.conf import settings DEBUG = True settings.configure( - RENDER=not DEBUG, + RENDER=not DEBUG, RENDER_URL='http://127.0.0.1:9009/render', ) ``` @@ -273,7 +271,7 @@ INSTALLED_APPS = ( ) REACT = { - 'RENDER': not DEBUG, + 'RENDER': not DEBUG, 'RENDER_URL': 'http://127.0.0.1:8001/render', } ``` @@ -303,6 +301,22 @@ Default: `'http://127.0.0.1:9009/render'` Frequently Asked Questions -------------------------- +### How do I return extra data from the render server? + +You can edit the render server's code and annotate the returned payload with whatever data +that you like. The payload provided by the render server is available under the `data` attribute +of the response object. + +For example: + +```python +from react.render import render_component + +rendered = render_component('path/to/component.js') + +print(rendered.data) +``` + ### Can python-react integrate with Django? python-react can integrate with Django's settings and the renderer integration can From 6211e3147c4d680440f47eb8060fe5e3385da239 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Tue, 17 Jul 2018 10:34:54 +1000 Subject: [PATCH 22/30] 4.2.0 --- CHANGELOG.md | 7 +++++++ react/__init__.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94fcd9d..7ed3c3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changelog ========= +### 4.2.0 (17/6/2018) + +- API for returning extra items returned by render server. + ([Sassan Haradji](https://github.com/sassanh)) + https://github.com/markfinger/python-react/pull/87 + + ### 4.1.1 (9/8/2017) - Update timeout in render_server.py. diff --git a/react/__init__.py b/react/__init__.py index 2906628..4eed8e1 100644 --- a/react/__init__.py +++ b/react/__init__.py @@ -1,3 +1,3 @@ -__version__ = '4.1.1' +__version__ = '4.2.0' default_app_config = 'react.apps.ReactConfig' \ No newline at end of file From 8853887b9ad69004713fcf1d5dc921d4e006f4e1 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Tue, 17 Jul 2018 10:51:59 +1000 Subject: [PATCH 23/30] Fixed a missing argument bug when using RENDER = False --- react/render_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react/render_server.py b/react/render_server.py index 13bbcae..679cc8b 100644 --- a/react/render_server.py +++ b/react/render_server.py @@ -30,7 +30,7 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None, serialized_props = None if not conf.settings.RENDER: - return RenderedComponent('', serialized_props) + return RenderedComponent('', serialized_props, {}) options = { 'path': path, From e33781f8efb553ecc07de99a4f1d68fe43ca478a Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Tue, 17 Jul 2018 10:52:08 +1000 Subject: [PATCH 24/30] 4.2.1 --- CHANGELOG.md | 6 ++++++ react/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ed3c3e..b21d1ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========= +### 4.2.1 (17/6/2018) + +- Fix for a missing argument bug that could occur with rendering deactivated. + + + ### 4.2.0 (17/6/2018) - API for returning extra items returned by render server. diff --git a/react/__init__.py b/react/__init__.py index 4eed8e1..0910eff 100644 --- a/react/__init__.py +++ b/react/__init__.py @@ -1,3 +1,3 @@ -__version__ = '4.2.0' +__version__ = '4.2.1' default_app_config = 'react.apps.ReactConfig' \ No newline at end of file From b3826c1dc115400749a57233eac94cf06d49af71 Mon Sep 17 00:00:00 2001 From: Jaylum Chen Date: Wed, 8 Aug 2018 18:16:12 -0700 Subject: [PATCH 25/30] take url as an arg --- react/render_server.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/react/render_server.py b/react/render_server.py index 679cc8b..b7d7d48 100644 --- a/react/render_server.py +++ b/react/render_server.py @@ -21,8 +21,9 @@ def __unicode__(self): class RenderServer(object): - def render(self, path, props=None, to_static_markup=False, request_headers=None, timeout=None): - url = conf.settings.RENDER_URL + def render(self, path, props=None, to_static_markup=False, request_headers=None, timeout=None, url=None): + if not url: + url = conf.settings.RENDER_URL if props is not None: serialized_props = json.dumps(props, cls=JSONEncoder) From 8a44adf0d9d2bb1078d759c1fae219b75005a024 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Mon, 8 Oct 2018 20:54:46 +1100 Subject: [PATCH 26/30] 4.3.0 --- CHANGELOG.md | 20 ++++++++++++++++++-- react/__init__.py | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b21d1ad..2d309cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,19 @@ Changelog ========= + +### 4.3.0 (8/10/2018) + +- Add option to pass a URL explicitly instead of reading from settings. + ([jchen-eb](https://github.com/jchen-eb)) + https://github.com/markfinger/python-react/pull/88 + + ### 4.2.1 (17/6/2018) - Fix for a missing argument bug that could occur with rendering deactivated. - ### 4.2.0 (17/6/2018) - API for returning extra items returned by render server. @@ -21,7 +28,6 @@ Changelog https://github.com/markfinger/python-react/pull/81 - ### 4.1.0 (1/3/2017) - `render_component` now accepts a `timeout` keyword argument which is passed to `RenderServer.render`. @@ -40,6 +46,7 @@ Changelog rendering. - Documentation updates regarding `RenderServer` API. + ### 3.0.1 (6/4/2016) - Documentation updates. @@ -65,6 +72,7 @@ Changelog ([Pringels](https://github.com/Pringels)) https://github.com/markfinger/python-react/pull/55 + ### 2.0.0 (22/9/2015) - **Breaking change** The base renderer's __init__ no longer accepts the RENDER_URL setting as an argument. @@ -89,6 +97,7 @@ Changelog - Fixed a potential path issue in config files - Replaced the webpack-service dependency with webpack-wrapper. + ### 0.8.0 (26/1/2015) - Boosting render performance by using a dedicated render server. @@ -97,6 +106,7 @@ Changelog render server, 'django_react.render_server.ReactRenderServer'. The legacy renderer is useable by setting DJANGO_REACT['RENDERER'] = 'django_react.renderer.ReactRenderer'. + ### 0.7.0 (2/1/2015) - Changed `django_react.exceptions.ReactComponentMissingSourceAttribute` to `django_react.exceptions.ReactComponentMissingSource` @@ -107,10 +117,12 @@ Changelog - The Python<->JS bridge used to render components now relies on a `--serialized-props-file` argument, formerly it was `--serialized-props`. - Switched the JSX loader to a fork which improves the debug information provided during error handling + ### 0.6.0 (24/12/2014) - The NODE_ENV environment setting is now controlled by the `DJANGO_REACT['DEBUG']` setting. Activating it will provides some improvements to the rendering performance. + ### 0.5.0 (14/12/2014) - Renamed `django_react.exceptions.PropSerialisationError` to `django_react.exceptions.PropSerializationError`. @@ -132,6 +144,7 @@ Changelog - Added a test suite and harness. - Added basic documentation. + ### 0.4.0 (11/12/2014) - Fixed a bug where errors caused during a component's prop serialization could silently fail. @@ -144,6 +157,7 @@ Changelog - `ReactComponent.get_component_variable` is now `ReactComponent.get_library`. - Moved the Webpack configuration into the ReactComponent class. + ### 0.3.0 (3/12/2014) - `django_react.exceptions.ReactComponentSourceFileNotFound` is now `django_react.exceptions.SourceFileNotFound` @@ -154,10 +168,12 @@ Changelog - `django_react.utils.render` no longer accepts a `ReactComponent` as an argument, it now takes `path_to_source`, `serialised_props`, and `to_static_markup`. - `django_react/render.js` no longer accepts the `--path-to-component` argument, instead it takes `--path-to-source`. + ### 0.2.0 (3/12/2014) - Replaced the post-install step in setup.py with django-node's dependency and package resolver. + ### 0.1.0 (2/12/2014) - Initial release diff --git a/react/__init__.py b/react/__init__.py index 0910eff..66cf931 100644 --- a/react/__init__.py +++ b/react/__init__.py @@ -1,3 +1,3 @@ -__version__ = '4.2.1' +__version__ = '4.3.0' default_app_config = 'react.apps.ReactConfig' \ No newline at end of file From 787a17a2fc82ce56e67b2f731154cefe59388efc Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 14 Sep 2020 11:48:57 -0300 Subject: [PATCH 27/30] Test on travis with newer versions of Python and Django --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2308405..7fcdacb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,13 @@ language: python python: - "2.7" - - "3.4" + - "3.8" env: - DJANGO_VERSION=1.7.8 - DJANGO_VERSION=1.8.1 + - DJANGO_VERSION=2.2.16 + - DJANGO_VERSION=3.1.1 install: # Install node 6 (current LTS as of January 2017) From c68dacc4d53449e5e1f049f317b1f542cabe33c0 Mon Sep 17 00:00:00 2001 From: Tim Gates Date: Mon, 28 Dec 2020 21:46:38 +1100 Subject: [PATCH 28/30] docs: fix simple typo, browswer -> browser There is a small typo in examples/frontend-rendering-with-webpack/README.md. Should read `browser` rather than `browswer`. --- examples/frontend-rendering-with-webpack/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/frontend-rendering-with-webpack/README.md b/examples/frontend-rendering-with-webpack/README.md index f7b9908..05f9421 100644 --- a/examples/frontend-rendering-with-webpack/README.md +++ b/examples/frontend-rendering-with-webpack/README.md @@ -1,7 +1,7 @@ Running the example =================== -As mentioned in the ***Using React on the front-end*** section, [Webpack](https://webpack.github.io/) is used to bundle the respective js files into `dist.js` and included in `index.html`. To make React attributes like `onClick` etc. work, the app has to be re-rendered (along with all the props passed down) when it loads on the browswer. React is intelligent enough to not re-paint the browser and only update the changes, thus adding all the component properties. +As mentioned in the ***Using React on the front-end*** section, [Webpack](https://webpack.github.io/) is used to bundle the respective js files into `dist.js` and included in `index.html`. To make React attributes like `onClick` etc. work, the app has to be re-rendered (along with all the props passed down) when it loads on the browser. React is intelligent enough to not re-paint the browser and only update the changes, thus adding all the component properties. In this example, the basic_rendering example is modified to submit the Comment Form through ajax and update the Comment List by fetching the updated comments and rendering the application with new props. From fe54b3e78fda2952d22fb32d89bf91bdebc393b9 Mon Sep 17 00:00:00 2001 From: lolivera-eb <80480298+lolivera-eb@users.noreply.github.com> Date: Mon, 5 Jul 2021 14:50:42 -0300 Subject: [PATCH 29/30] update python version --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7fcdacb..a61f73b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: python python: - "2.7" + - "3.5" + - "3.7" - "3.8" env: @@ -9,6 +11,7 @@ env: - DJANGO_VERSION=1.8.1 - DJANGO_VERSION=2.2.16 - DJANGO_VERSION=3.1.1 + - DJANGO_VERSION=1.8.19 install: # Install node 6 (current LTS as of January 2017) From 1703ebe0805fd187f54a945ca03796ece518fca1 Mon Sep 17 00:00:00 2001 From: xav <73826012+gravybrux@users.noreply.github.com> Date: Thu, 29 Jun 2023 15:25:41 +0100 Subject: [PATCH 30/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a2d4e40..b73e30c 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ rendered = render_component('path/to/component.jsx', {'foo': 'bar'}) print(rendered) ``` -The object returned has two properties: +The object returned has three properties: - `markup` - the rendered markup - `props` - the JSON-serialized props