markfinger / python-react

Server-side rendering of React components
MIT License
1.62k stars 116 forks source link

List index out of range #36

Closed jrasanen closed 9 years ago

jrasanen commented 9 years ago

I have a simple JSX-file, which outputs "Hello django-react", it works fine until randomly starts throwing error 500.

Environment:

Request Method: GET
Request URL: http://localhost:8000/signup

Django Version: 1.8.1
Python Version: 2.7.9
Installed Applications:
('django.contrib.contenttypes',
 'django.contrib.auth',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'react',
 'js_host',
 'webpack',
 'volu')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')

Traceback:
File "/Users/jrasanen/.virtualenvs/reacttest/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/jrasanen/Development/volu/reacttest/volu/views.py" in signup
  29.         to_static_markup=no_js
File "/Users/jrasanen/.virtualenvs/reacttest/lib/python2.7/site-packages/react/render.py" in render_component
  106.         path = bundled_component.get_paths()[0]

Exception Type: IndexError at /signup
Exception Value: list index out of range

Console output while refreshing the page 3-10 times:

[14/May/2015 09:10:12]"GET /static/webpack/bundles/react-components/jsx__Signup-d830a531c93fdf23d1d0.js HTTP/1.1" 200 265277
[14/May/2015 09:10:29]"GET /signup HTTP/1.1" 200 3429
[14/May/2015 09:10:29]"GET /static/webpack/bundles/react-components/jsx__Signup-ac957b77ea30095bc2f6.js HTTP/1.1" 200 265298
[14/May/2015 09:10:31]"GET /signup HTTP/1.1" 200 3430
[14/May/2015 09:10:31]"GET /static/webpack/bundles/react-components/jsx__Signup-ac957b77ea30095bc2f6.js HTTP/1.1" 200 265298
[14/May/2015 09:10:38]"GET /signup HTTP/1.1" 200 3449
[14/May/2015 09:10:38]"GET /static/webpack/bundles/react-components/jsx__Signup-11528387cafe8d8fda1c.js HTTP/1.1" 200 265298
[14/May/2015 09:10:40]"GET /signup HTTP/1.1" 200 3427
[14/May/2015 09:10:40]"GET /static/webpack/bundles/react-components/jsx__Signup-11528387cafe8d8fda1c.js HTTP/1.1" 200 265298
[14/May/2015 09:10:42]"GET /signup HTTP/1.1" 200 3425
[14/May/2015 09:10:42]"GET /static/webpack/bundles/react-components/jsx__Signup-11528387cafe8d8fda1c.js HTTP/1.1" 200 265298
[14/May/2015 09:10:56]"GET /signup HTTP/1.1" 200 3503
[14/May/2015 09:10:57]"GET /static/webpack/bundles/react-components/jsx__Signup-8b546af9446e430db8fa.js HTTP/1.1" 200 265366
[14/May/2015 09:10:58]"GET /signup HTTP/1.1" 200 3481
[14/May/2015 09:10:58]"GET /static/webpack/bundles/react-components/jsx__Signup-8b546af9446e430db8fa.js HTTP/1.1" 200 265366
[14/May/2015 09:11:05]"GET /signup HTTP/1.1" 500 73901
[14/May/2015 09:11:06]"GET /signup HTTP/1.1" 500 73901
[14/May/2015 09:11:07]"GET /signup HTTP/1.1" 500 73901
[14/May/2015 09:11:18]"GET /signup HTTP/1.1" 500 73901
[14/May/2015 09:11:49]"GET /signup HTTP/1.1" 500 73901
jrasanen commented 9 years ago

Restarting Django-server doesn't help. But removing all the pyc files with "find . -name "*.pyc" | xargs rm" and then booting debug server seems to work.

My view:

def signup(request):
    no_js = False

    signup_component = render_component(
        os.path.join(settings.BASE_DIR, 'static', 'jsx', 'Signup.jsx'),
        props={
            'hello': "Django"
        },
        translate=True,
        to_static_markup=no_js
    )

    context = {
        'signup': signup_component,
        'no_js': no_js
    }
    return render(request, 'users/signup.html', context)

Change props hello from "Django" to "React", and refreshing the page couple times always triggers the error.

jrasanen commented 9 years ago

Fixed by upgrading Python 2.7.x --> Python 3.x

Edit: Nope, still does this at times with Python 3

markfinger commented 9 years ago

Looks like webpack might be flaking out. Might be related to https://github.com/markfinger/python-webpack/issues/19

markfinger commented 9 years ago

Should be fixed now. The problem was in the JS lib, so you'll need to refer to https://github.com/markfinger/python-webpack/issues/19#issuecomment-102326983 for a diff that you'll need to make

jrasanen commented 9 years ago

Great, thanks!

fellu commented 9 years ago

I get this error too, django console says: - Broken pipe from ('127.0.0.1', 35699)

Happens if jsx file is saved multiple times quickly