Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@react_component directive is not working ? #41

Open
mihirsoni opened this issue Aug 17, 2015 · 13 comments
Open

@react_component directive is not working ? #41

mihirsoni opened this issue Aug 17, 2015 · 13 comments
Labels

Comments

@mihirsoni
Copy link

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

@talyssonoc talyssonoc added the bug label Aug 18, 2015
@talyssonoc
Copy link
Owner

Hi, @mihirsoni, some users are having a issue with the directive, as you can see in @nrcook's answer here: #28 (comment)

You can use the facade directly until I (or somebody else that send a PR) fix it, I hope it works for you!

@mihirsoni
Copy link
Author

@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 ?

@talyssonoc
Copy link
Owner

Well, it should work like this... what V8Js version are you using?

@mihirsoni
Copy link
Author

@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

@talyssonoc
Copy link
Owner

@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!

@talyssonoc
Copy link
Owner

@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?

@Jegulsky
Copy link

@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.

@talyssonoc
Copy link
Owner

Huuum, that's weird 😞. Did you try the php artisan view:clear?

@Jegulsky
Copy link

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?

@talyssonoc
Copy link
Owner

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?

@Jegulsky
Copy link

btw did you try Flux? will it work with such structure? I was just going to check, but stumbled at component config.

@talyssonoc
Copy link
Owner

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!

@jfefes
Copy link

jfefes commented Feb 19, 2016

+1 I just cloned the example project, {!! React::render('Message', [ 'name' => 'Hue' ]) !!} was the only way I could get it to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants