Open mihirsoni opened 9 years ago
Hi, @mihirsoni, some users are having a issue with the directive, as you can see in @nrcook's answer here: https://github.com/talyssonoc/react-laravel/issues/28#issuecomment-114667043
You can use the facade directly until I (or somebody else that send a PR) fix it, I hope it works for you!
@talyssonoc Hey , I tried to use the same but it doesn't run and give us segementation fault, do we need to add any extra configs for the same ?
Well, it should work like this... what V8Js
version are you using?
@talyssonoc here is the my phpInfo details.
V8 Javascript Engine enabled V8 Engine Compiled Version 4.6.0 V8 Engine Linked Version 4.6.0 (candidate) Version 0.2.1
@mihirsoni, can you please change the source of vendor\talyssonoc\react-laravel\lib\ReactServiceProvider.php
to this and check if it works:
<?php namespace React;
use Illuminate\Support\ServiceProvider;
class ReactServiceProvider extends ServiceProvider {
public function boot() {
$blade = $this->app->make('view')->getEngineResolver()
->resolve('blade')->getCompiler();
$blade->extend(function($view) {
$pattern = $this->createMatcher('react_component');
return preg_replace($pattern, '<?php echo React::render$2; ?>', $view);
});
$this->publishes([
__DIR__ . '/../assets' => public_path('vendor/react-laravel'),
], 'assets');
$this->publishes([
__DIR__ . '/../config/config.php' => config_path('react.php'),
], 'config');
}
public function register() {
$this->app->bind('React', function() {
if($this->app->environment('production')
&& $this->app->make('cache')->has('reactSource')
&& $this->app->make('cache')->has('componentsSource')) {
$reactSource = $this->app->make('cache')->get('reactSource');
$componentsSource = $this->app->make('cache')->get('componentsSource');
}
else {
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'react');
$reactSource = file_get_contents(config('react.source'));
$componentsSource = file_get_contents(config('react.components'));
if($this->app->environment('production')) {
$this->app->make('cache')->forever('reactSource', $reactSource);
$this->app->make('cache')->forever('componentsSource', $componentsSource);
}
}
return new React($reactSource, $componentsSource);
});
}
protected function createMatcher($function) {
return '/(?<!\w)(\s*)@' . $function . '(\s*\(.*\))/';
}
}
Tell me if it does work, so I can put it in master branch!
@mihirsoni can you check this so I can close the issue or try to solve some other way? Also, can you try to run php artisan view:clear
and see if the component does render?
@talyssonoc, I checked with ReactServiceProvider code replacement - no result. I have similar situation, V8 installed and works well, {!! React::render('Message', [ 'name' => 'Hue' ], [ 'prerender' => true ]) !!} works fine, but @react_component('Message', ['name' => 'Hue']) doesn't renders. I have simple nginx + php-fpm stack insalled on Yosemite (and Ubuntu at hosting side) w/o Homestead.
Huuum, that's weird :disappointed:. Did you try the php artisan view:clear
?
Yep, I tried all of guessed manipulation throw the related issues, but ain't get result. How can I help? Where I should look for? At least simple blade call of {!! React::render(...) !!} works. Any suggestion?
For some reason the directive is not being registered (some that tested said that the code do not pass inside the closure of the registering of the directive), I never passed by this before, do you know some reason for it to happen?
btw did you try Flux? will it work with such structure? I was just going to check, but stumbled at component config.
I didn't tried yet, but I see no reason for Flux don't work, it just renders components on the server, if you use some lib that allows application bootstraping (like Alt) I guess it would work!
+1 I just cloned the example project, {!! React::render('Message', [ 'name' => 'Hue' ]) !!}
was the only way I could get it to work.
Hi ,
I have been trying since long to make it react-laravel work but it seems may be I am missing something, I have installed all the required dependencies after that I tried the demo project but still it didn't work,
https://github.com/talyssonoc/react-laravel-example
/Mihir