Skip to content

Commit 8ec04f8

Browse files
committed
Allow react pages with no data
This allows for a plain react page that doesn't need data when `use_jsx_rendering` is enabled. ``` views/about - index.jsx ```
1 parent 70e9729 commit 8ec04f8

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

test/dummy/app/controllers/jsx_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ def bad_single
3333
def bad_pair
3434
end
3535

36+
def no_json_template
37+
end
38+
39+
def no_html_template
40+
end
41+
3642
def render_does_not_exist
3743
render :does_not_exist
3844
end

test/render_test.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,37 @@ class RenderTest < ActionController::TestCase
146146
assert_equal "application/json", @response.media_type
147147
end
148148

149+
test "rendering props with a non existant template still renders the layout" do
150+
get :no_json_template, format: :json
151+
152+
assert_response 200
153+
rendered = <<~HTML
154+
{"data":{}}
155+
HTML
156+
157+
assert_equal rendered, @response.body
158+
assert_equal "application/json", @response.media_type
159+
end
160+
161+
test "rendering an action without a HTML template renders the fallback application/superglue" do
162+
get :no_html_template, format: :html
163+
164+
assert_response 200
165+
rendered = <<~HTML
166+
<html>
167+
<body>
168+
<script type="text/javascript">
169+
window.SUPERGLUE_INITIAL_PAGE_STATE={"data":{}};
170+
</script>
171+
172+
<div id="app"></div> </body>
173+
</html>
174+
HTML
175+
176+
assert_equal rendered, @response.body
177+
assert_equal "text/html", @response.media_type
178+
end
179+
149180
test "non existant template" do
150181
exception = assert_raise(ActionView::MissingTemplate, match: /extension JSX or TSX/) {
151182
get :render_does_not_exist

test/views/jsx/no_html_template.jsx

Whitespace-only changes.

0 commit comments

Comments
 (0)