Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Allow engine mounting to be disabled #1605

Merged
merged 2 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,021 changes: 0 additions & 1,021 deletions gems/quilt_rails/.rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml

This file was deleted.

27 changes: 6 additions & 21 deletions gems/quilt_rails/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This file strictly follows the rules defined in the Ruby style guide:
# http://shopify.github.io/ruby-style-guide/
# Before updating anything please sync-up with #ruby-style-guide on Slack.
inherit_from:
- http://shopify.github.io/ruby-style-guide/rubocop.yml
inherit_gem:
rubocop-shopify: rubocop.yml

AllCops:
TargetRubyVersion: 2.6.3
Expand All @@ -12,13 +12,12 @@ AllCops:
- 'vendor/**/*'
- '*.gemspec'

Rails:
Enabled: false

Metrics/PerceivedComplexity:
Max: 6
Exclude:
- bin/**/*

CyclomaticComplexity:
Metrics/CyclomaticComplexity:
Max: 6
Exclude:
- bin/**/*
Expand All @@ -41,16 +40,6 @@ Metrics/BlockLength:
- config/initializers/**/*
- config/environments/**/*

Metrics/BlockNesting:
CountBlocks: false
Max: 1
Exclude:
- lib/**/*.rake
- test/**/*
- bin/**/*
- Gemfile
- config/initializers/**/*

Metrics/ClassLength:
CountComments: true
Max: 100
Expand All @@ -64,18 +53,14 @@ Naming/MethodName:
Style/ClassAndModuleChildren:
Enabled: false

Metrics/LineLength:
Layout/LineLength:
Max: 120
Exclude:
- Guardfile
- Gemfile
- config/**/*
- bin/**/*

Metrics/PerceivedComplexity:
Exclude:
- bin/**/*

Style/MethodCallWithArgsParentheses:
Exclude:
- bin/**/*
Expand Down
5 changes: 5 additions & 0 deletions gems/quilt_rails/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

<!-- ## [Unreleased] -->

### Added

- Added `config.mount` (default `true`) option to disable automatic engine mounting.
([#1605](https://github.com/Shopify/quilt/pull/1605))

## [3.3.0] - 2020-08-10

### Added
Expand Down
2 changes: 2 additions & 0 deletions gems/quilt_rails/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ source('https://rubygems.org')

gemspec

gem('rubocop-shopify', require: false)

group :test do
gem 'minitest'
gem 'minitest-hooks'
Expand Down
44 changes: 25 additions & 19 deletions gems/quilt_rails/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,43 +66,40 @@ GEM
zeitwerk (~> 2.2, >= 2.2.2)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.0)
ast (2.4.1)
builder (3.2.4)
coderay (1.1.2)
coderay (1.1.3)
concurrent-ruby (1.1.7)
crass (1.0.6)
erubi (1.9.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.3)
loofah (2.6.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
metaclass (0.0.4)
method_source (0.9.2)
method_source (1.0.0)
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.11.3)
minitest (5.14.1)
minitest-hooks (1.5.0)
minitest (> 5.3)
mocha (1.9.0)
metaclass (~> 0.0.1)
mocha (1.11.2)
nio4r (2.5.2)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
parallel (1.17.0)
parser (2.6.3.0)
ast (~> 2.4.0)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
parallel (1.19.2)
parser (2.7.1.4)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (4.0.5)
rack (2.2.3)
rack-proxy (0.6.5)
Expand Down Expand Up @@ -142,15 +139,23 @@ GEM
thor (>= 0.20.3, < 2.0)
rainbow (3.0.0)
rake (13.0.1)
rubocop (0.74.0)
jaro_winkler (~> 1.5.1)
regexp_parser (1.7.1)
rexml (3.2.4)
rubocop (0.86.0)
parallel (~> 1.10)
parser (>= 2.6)
parser (>= 2.7.0.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml
rubocop-ast (>= 0.0.3, < 1.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0)
parser (>= 2.7.1.4)
rubocop-git (0.1.3)
rubocop (>= 0.24.1)
rubocop-shopify (1.0.4)
rubocop (>= 0.85, < 0.87)
ruby-progressbar (1.10.1)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
Expand All @@ -165,7 +170,7 @@ GEM
thread_safe (0.3.6)
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.6.0)
unicode-display_width (1.7.0)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -182,6 +187,7 @@ DEPENDENCIES
quilt_rails!
rubocop (~> 0.74)
rubocop-git (~> 0.1.3)
rubocop-shopify
sqlite3

BUNDLED WITH
Expand Down
2 changes: 2 additions & 0 deletions gems/quilt_rails/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ Rake::TestTask.new do |t|
t.name = 'test:unit'
t.pattern = 'test/quilt_rails/**/*_test.rb'
end

task(default: %i(test))
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class PerformanceReportController < ActionController::Base
def create
process_report

render json: { result: 'success' }, status: 200
render(json: { result: 'success' }, status: 200)
rescue ActionController::ParameterMissing => error
render json: { error: error.message, status: 422 }
render(json: { error: error.message, status: 422 })
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ def create_procfile_entry
if File.exist?(procfile_path)
append_file(procfile_path, File.read(File.expand_path(find_in_source_paths(procfile_path))))
else
copy_file procfile_path
copy_file(procfile_path)
end
end

def create_route_file
routes_path = "config/routes.rb"

if File.exist?(routes_path)
route "mount Quilt::Engine, at: '/'"
route("mount Quilt::Engine, at: '/'")
else
copy_file "routes.rb", routes_path
copy_file("routes.rb", routes_path)
end

say "Added Quilt engine mount"
say("Added Quilt engine mount")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ReactSetupGenerator < Rails::Generators::Base
def install_js_dependencies
return if options.skip_yarn?

say "Installing react and types dependencies"
say("Installing react and types dependencies")
system("yarn add "\
"typescript@~3.8.0 "\
"react@~16.11.0 "\
Expand Down
3 changes: 2 additions & 1 deletion gems/quilt_rails/lib/quilt_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ module Quilt
end

require "quilt_rails/version"
require "quilt_rails/engine"
require "quilt_rails/logger"
require "quilt_rails/configuration"
require "quilt_rails/react_renderable"
require "quilt_rails/performance"
require "quilt_rails/trusted_ui_server_csrf_strategy"
require "quilt_rails/header_csrf_strategy"

require "quilt_rails/engine"
require "quilt_rails/monkey_patches/active_support_reloader" if Rails.env.development?
20 changes: 13 additions & 7 deletions gems/quilt_rails/lib/quilt_rails/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# frozen_string_literal: true

module Quilt
class Configuration
attr_accessor :react_server_host, :react_server_protocol
require "active_support/ordered_options"

module Quilt
class Configuration < ActiveSupport::OrderedOptions
def initialize
ip = ENV['REACT_SERVER_IP'] || 'localhost'
port = ENV['REACT_SERVER_PORT'] || 8081
super
react_server_ip = ENV['REACT_SERVER_IP'] || "localhost"
react_server_port = ENV['REACT_SERVER_PORT'] || 8081

self.react_server_host = "#{react_server_ip}:#{react_server_port}"
self.react_server_protocol = ENV['REACT_SERVER_PROTOCOL'] || "http"
self.mount = true
end

@react_server_host = "#{ip}:#{port}"
@react_server_protocol = ENV['REACT_SERVER_PROTOCOL'] || 'http'
def mount?
mount
end
end

Expand Down
8 changes: 6 additions & 2 deletions gems/quilt_rails/lib/quilt_rails/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ module Quilt
class Engine < ::Rails::Engine
isolate_namespace Quilt

config.quilt = Quilt.configuration

initializer(:mount_quilt, before: :add_builtin_route) do |app|
app.routes.append do
mount(Quilt::Engine, at: '/') unless has_named_route?(:quilt)
if config.quilt.mount?
app.routes.append do
mount(Quilt::Engine, at: '/') unless has_named_route?(:quilt)
end
end
end
end
Expand Down
7 changes: 4 additions & 3 deletions gems/quilt_rails/lib/quilt_rails/header_csrf_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def fallback_handler

class NoSameSiteHeaderError < StandardError
def initialize
# rubocop:disable LineLength
super "CSRF verification failed. This request is missing the `x-shopify-react-xhr` header, or it does not have the expected value."
# rubocop:enable LineLength
super(<<~MSG.squish)
CSRF verification failed. This request is missing the
`x-shopify-react-xhr` header, or it does not have the expected value.
MSG
end
end
end
Expand Down
36 changes: 25 additions & 11 deletions gems/quilt_rails/lib/quilt_rails/performance/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,39 @@ class Report
attr_accessor :navigations
attr_accessor :connection

def self.from_params(params)
params.transform_keys! { |key| key.underscore.to_sym }
params[:connection] = { effectiveType: 'unknown' } if params[:connection].blank?
class << self
def from_params(params)
params.transform_keys! { |key| key.underscore.to_sym }
params[:connection] = { effectiveType: 'unknown' } if params[:connection].blank?

connection = Connection.from_params(params[:connection])
connection = Connection.from_params(params[:connection])

Report.new(
connection: connection,
navigations: (params[:navigations] || []).map do |navigation|
Report.new(
connection: connection,
navigations: build_navigations(params[:navigations], connection: connection),
events: build_events(params[:events], connection: connection),
)
end

private

def build_navigations(navigations_params, connection:)
navigations_params ||= []
navigations_params.map do |navigation|
navigation = Navigation.from_params(navigation)
navigation.connection = connection
navigation
end,
events: (params[:events] || []).map do |event|
end
end

def build_events(events_params, connection:)
events_params ||= []
events_params.map do |event|
event = Event.from_params(event)
event.connection = connection
event
end,
)
end
end
end

def initialize(events:, navigations:, connection:)
Expand Down
14 changes: 8 additions & 6 deletions gems/quilt_rails/lib/quilt_rails/react_renderable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@ def proxy(headers, data)

class ReactServerNoResponseError < StandardError
def initialize(url)
# rubocop:disable LineLength
super "Errno::ECONNREFUSED: Waiting for React server to boot up. If this error persists verify that @shopify/react-server is configured on #{url}"
# rubocop:enable LineLength
super(<<~MSG.squish)
Errno::ECONNREFUSED: Waiting for React server to boot up.
If this error persists verify that @shopify/react-server is configured on #{url}"
MSG
end
end

class DoNotIntegrationTestError < StandardError
def initialize
# rubocop:disable LineLength
super "Do not try to use Rails integration tests on your quilt_rails app. Instead use Jest and @shopify/react-testing to test your React application directly."
# rubocop:enable LineLength
super(<<~MSG.squish)
Do not try to use Rails integration tests on your quilt_rails app.
Instead use Jest and @shopify/react-testing to test your React application directly."
MSG
end
end
end
Expand Down
Loading