spatie / server-side-rendering

Server side rendering JavaScript in a PHP application
https://sebastiandedeyne.com/posts/2018/server-side-rendering-javascript-from-php
MIT License
602 stars 34 forks source link

Allow context to be sent back up with `dispatch` #17

Closed sebastiandedeyne closed 6 years ago

sebastiandedeyne commented 6 years ago

The magic dispatch function should accept a second argument to send up context.

Implementation idea: dispatch returns a JSON-serialized object, with the html in one key, and context in another.

{
  "html": "....",
  "context": {
    "meta": "<meta ...>"
  }
}

This is a breaking change, and would change the return of Engine::run() from a string to an array or custom object.

See spatie/laravel-server-side-rendering#18 for a real-world use case.

robinvdvleuten commented 6 years ago

This would be so useful 👍

robinvdvleuten commented 6 years ago

I desperately need it for CSS-in-JS support, where I now solve it by just letting Node.js render the complete HTML page (webstronauts/laravel-liftoff/resources/assets/js/entry-server.js).

robinvdvleuten commented 6 years ago

I've created #19 to support this.