Skip to content

Switch to the new Sprockets processor #385

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

Merged
merged 2 commits into from
Oct 29, 2015

Conversation

eugenijusr
Copy link
Contributor

Starting version 4 Sprockets is removing the register_engine method which registers JSX transformers using Tilt based templates breaking this gem for the current Rails 5 master. This has been deprecated since Sprockets version 3:
https://github.com/rails/sprockets/blob/master/UPGRADING.md

This PR adds a JSX Processor and registers it via register_processor as application/jsx mime type. Is there a reserved mime type for JSX templates?

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

end

def call(input)
@output ||= JSX::transform(input[:data])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm as you can see in the specs, this @output is getting assigned in the first use, but then never being reassigned. This causes all inputs to have the same output!

Is there a downside to simply

class Processor 
  def self.call(input)
    JSX::transform(input[:data])
  end 
end

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was done for performance reasons in the Tilt template version of this. For these Sprocket processors there is a way to do a similar thing by implementing an optional cache_key method.

@rmosolgo
Copy link
Member

Thanks for updating us!

I don't think there is a special mime type for .jsx. They're usually requested & served as JavaScript files, so I think the normal JS mime type is good enough!

@eugenijusr eugenijusr force-pushed the sprockets4-compatibility branch from fdb6a0f to c8ecba2 Compare October 28, 2015 18:56
@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

end

def call(input)
{data: JSX::transform(input[:data])}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from https://github.com/rails/sprockets#return-hash:

Returning a String is shorthand for returning { data: str }

Can we return a string only? Do we need any metadata?

@rmosolgo
Copy link
Member

✨ Thanks again for getting us up-to-date (and getting me up to date 😝) !

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

Successfully merging this pull request may close these issues.

3 participants