Skip to content

Commit aa10b89

Browse files
committed
Bug fixes.
- Fixed an issue where bundled components would have issues would have issues resolving which how to find React. - Fixed an issue where rendered markup was not having mark_safe applied.
1 parent ad30938 commit aa10b89

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

django_react/bundle.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,19 @@ def get_webpack_config(path, translate=None, var=None):
3434
libraryTarget: 'umd',
3535
library: '{var}'
3636
}},
37-
externals: ['react'],
37+
externals: [
38+
{{
39+
'react': {{
40+
commonjs2: '{path_to_react}',
41+
root: 'React'
42+
}}
43+
}}
44+
],
3845
devtool: 'eval\''''.format(
3946
dir=os.path.dirname(path),
4047
file='./' + os.path.basename(path),
4148
var=var,
49+
path_to_react=os.path.join(os.path.dirname(__file__), 'services', 'node_modules', 'react'),
4250
)
4351

4452
if translate:

django_react/render.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def __init__(self, markup, path_to_source, props, serialized_props, watch_source
2222
self.to_static_markup = to_static_markup
2323

2424
def __str__(self):
25-
return self.render_markup()
25+
return mark_safe(self.render_markup())
2626

2727
def __unicode__(self):
28-
return self.render_markup()
28+
return mark_safe(unicode(self.render_markup()))
2929

3030
def render_markup(self):
3131
markup = self.markup
@@ -43,11 +43,13 @@ def render_props(self):
4343

4444
def get_bundle(self):
4545
if not self.bundle:
46-
raise ComponentWasNotBundled((
47-
'The component "{path}" was not bundled during the rendering process. '
48-
'Call render_component with `bundle`, `translate`, or `watch_source` '
49-
'keyword arguments set to `True` to ensure that it is bundled.'
50-
).format(path=self.path_to_source))
46+
raise ComponentWasNotBundled(
47+
(
48+
'The component "{path}" was not bundled during the rendering process. '
49+
'Call render_component with `bundle`, `translate`, or `watch_source` '
50+
'keyword arguments set to `True` to ensure that it is bundled.'
51+
).format(path=self.path_to_source)
52+
)
5153
return self.bundle
5254

5355
def get_var(self):

django_react/services/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ def render(self, path_to_source, serialized_props, to_static_markup):
2020
except NodeServiceError as e:
2121
six.reraise(ComponentRenderingError, ComponentRenderingError(*e.args), sys.exc_info()[2])
2222

23-
return response.text
23+
markup = response.text.encode('utf-8')
24+
25+
return markup

0 commit comments

Comments
 (0)