Giter Site home page Giter Site logo

Comments (13)

talyssonoc avatar talyssonoc commented on May 22, 2024

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!

from react-laravel.

mihirsoni avatar mihirsoni commented on May 22, 2024

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

from react-laravel.

talyssonoc avatar talyssonoc commented on May 22, 2024

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

from react-laravel.

mihirsoni avatar mihirsoni commented on May 22, 2024

@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

from react-laravel.

talyssonoc avatar talyssonoc commented on May 22, 2024

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

from react-laravel.

talyssonoc avatar talyssonoc commented on May 22, 2024

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

from react-laravel.

Jegulsky avatar Jegulsky commented on May 22, 2024

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

from react-laravel.

talyssonoc avatar talyssonoc commented on May 22, 2024

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

from react-laravel.

Jegulsky avatar Jegulsky commented on May 22, 2024

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?

from react-laravel.

talyssonoc avatar talyssonoc commented on May 22, 2024

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?

from react-laravel.

Jegulsky avatar Jegulsky commented on May 22, 2024

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

from react-laravel.

talyssonoc avatar talyssonoc commented on May 22, 2024

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!

from react-laravel.

jfefes avatar jfefes commented on May 22, 2024

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

from react-laravel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.