-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
don't override document.title if set to None #1343
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
66bb5d3
don't override document.title if set to None
chriddyp 2dcc00a
add clientside page title test
chriddyp e190cc9
fix logic
chriddyp f8216b9
fix test
chriddyp 104510e
rm comments
chriddyp 84266d7
add title to dash config & docstrings
chriddyp 5da53ce
update logic as per https://github.com/plotly/dash/pull/1343#discussi…
chriddyp 219a50b
pin isort to fix pylint tests
chriddyp e2a2911
add chained callback test case
chriddyp 8e80ad9
get title from config
chriddyp 5f36766
threading things through
chriddyp 864b1fb
rm undefined variable
chriddyp 09014a4
id selector
chriddyp 3a61fd4
fix a couple tests
chriddyp 710269d
fix tests
chriddyp 057dca7
update changelog
chriddyp 91a4aa5
keep app.title backwards compatibility and add test
chriddyp d587495
trim trailing whitespace
chriddyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,6 +227,15 @@ class Dash(object): | |
with a ``plug`` method, taking a single argument: this app, which will | ||
be called after the Flask server is attached. | ||
:type plugins: list of objects | ||
|
||
:param title: Default ``Dash``. Configures the document.title | ||
(the text that appears in a browser tab). | ||
|
||
:param update_title: Default ``Updating...``. Configures the document.title | ||
(the text that appears in a browser tab) text when a callback is being run. | ||
Set to None or '' if you don't want the document.title to change or if you | ||
want to control the document.title through a separate component or | ||
clientside callback. | ||
""" | ||
|
||
def __init__( | ||
|
@@ -252,6 +261,7 @@ def __init__( | |
prevent_initial_callbacks=False, | ||
show_undo_redo=False, | ||
plugins=None, | ||
title='Dash', | ||
update_title="Updating...", | ||
**obsolete | ||
): | ||
|
@@ -300,6 +310,7 @@ def __init__( | |
), | ||
prevent_initial_callbacks=prevent_initial_callbacks, | ||
show_undo_redo=show_undo_redo, | ||
title=title, | ||
update_title=update_title, | ||
) | ||
self.config.set_read_only( | ||
|
@@ -321,6 +332,9 @@ def __init__( | |
"via the Dash constructor" | ||
) | ||
|
||
# keep title as a class property for backwards compatability | ||
self.title = title | ||
|
||
# list of dependencies - this one is used by the back end for dispatching | ||
self.callback_map = {} | ||
# same deps as a list to catch duplicate outputs, and to send to the front end | ||
|
@@ -725,7 +739,9 @@ def index(self, *args, **kwargs): # pylint: disable=unused-argument | |
config = self._generate_config_html() | ||
metas = self._generate_meta_html() | ||
renderer = self._generate_renderer() | ||
title = getattr(self, "title", "Dash") | ||
|
||
# use self.title instead of app.config.title for backwards compatibility | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In principle we could make title into a |
||
title = self.title | ||
|
||
if self._favicon: | ||
favicon_mod_time = os.path.getmtime( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this allows the clientside callback to set the value, it seems to break existing tests / behavior. Would a better verification be to only revert back to
inititalTitle
if the value is equal toupdate_title
instead? Possibly the same chekc forupdate_title
- only update if the value is currentlyinitialTitle
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I totally misinterpreted what
update_title
meant. I believe e190cc9 is the logic we're looking forThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be safer to bail out entirely (before even the
props.isLoading
test) if!update_title
. Then this entire component would be a noop, as it should be in that case; callbacks can do whatever they want withdocument.title
and we won't interfere.When you do have an
update_title
, I may agree with @Marc-Andre-Rivet that there needs to be a test when we're reverting back to the non-updating title. Consider a callback chain, where the first callback changesdocument.title
, but we're still in a loading state soDocumentTitle
doesn't receive new props and we don't pick up the changed title intothis.state
. Then after the second callback we resetdocument.title
tothis.state.title
, losing the callback-provided title.Seems to me the logic you have right now is fine during loading, but when reverting to
this.state.title
below it would be better to do something like:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @alexcjohnson @Marc-Andre-Rivet ! I believe I have addressed your comments and added the appropriate tests now.