Skip to content

Commit 851b113

Browse files
committed
Fix render loop bug
1 parent f0b21c7 commit 851b113

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/reactpy_django/forms/components.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ def _django_form(
4242
top_children: Sequence,
4343
bottom_children: Sequence,
4444
):
45-
# TODO: Implement form restoration on page reload. Maybe this involves creating a new setting called
46-
# `form_restoration_method` that can be set to "URL", "CLIENT_STORAGE", "SERVER_SESSION", or None.
47-
# Perhaps pre-rendering is robust enough already handle this scenario?
48-
# Additionally, "URL" mode would limit the user to one form per page.
4945
# TODO: Test this with django-colorfield, django-ace, django-crispy-forms
5046
uuid_ref = hooks.use_ref(uuid4().hex.replace("-", ""))
5147
top_children_count = hooks.use_ref(len(top_children))
@@ -86,7 +82,9 @@ async def render_form():
8682
await database_sync_to_async(initialized_form.save)()
8783
set_submitted_data(None)
8884

89-
set_rendered_form(await database_sync_to_async(initialized_form.render)(form_template))
85+
new_form = await database_sync_to_async(initialized_form.render)(form_template)
86+
if new_form != rendered_form:
87+
set_rendered_form(new_form)
9088

9189
def _on_change(_event):
9290
if on_change:

tests/test_app/forms/forms.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from django import forms
2-
from django.forms import ModelForm
32

43
from .. import models
54

@@ -45,15 +44,14 @@ class BasicForm(forms.Form):
4544
model_multiple_choice_field = forms.ModelMultipleChoiceField(
4645
label="model multiple choice field", initial="1", queryset=models.TodoItem.objects.all()
4746
)
48-
4947
# Currently unsupported fields
5048
# multi_value_field = MultiValueField(label="multi value", initial="[email protected]")
5149
# split_datetime_field = forms.SplitDateTimeField(label="split datetime")
5250
# file_field = forms.FileField(label="file")
5351
# image_field = forms.ImageField(label="image")
5452

5553

56-
class DatabaseBackedForm(ModelForm):
54+
class DatabaseBackedForm(forms.ModelForm):
5755
class Meta:
5856
model = models.TodoItem
5957
fields = "__all__"

0 commit comments

Comments
 (0)