markfinger / python-react

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

Allow to disable caching of JSX files #35

Closed jphalip closed 9 years ago

jphalip commented 9 years ago

I've noticed that the JSX files are somehow cached in the python process' memory, I assume for performance reasons. Changes made to a JSX file will only take effect after restarting the Django server. Could there be a way to avoid caching those JSX files? Or perhaps this feature already exists and I might have missed something in the documentation? (if so, I'm sorry!)

Thanks for a great app!

markfinger commented 9 years ago

@jphalip

It uses a node process to do the rendering and bundling. Node caches imported files similarly to python, so we get around it by using webpack to bundle the code into a single file which has a name containing a hash of the contents.

Webpack uses filesystem watchers to trigger rebuilds of the bundle. Sometimes the watchers can flake out or miss changes, but it's fairly rare. If you're codebase is part of a network mount or something similarly strange, they'll probably not work at all.

You can turn off the watchers (they default to DEBUG)

DJANGO_WEBPACK = {
    'WATCH_SOURCE': False
}

With the latest release, it'll be

WEBPACK = {
    'WATCH_SOURCE_FILES': False,
}

That'll trigger webpack to rebuild the entire bundle whenever a request comes in. It'll be slow, but it should fix the problems.