We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
On rerun, faded elements are becoming opaque one by one. Instead they become opaque all at once.
Steps to repro:
1. Run `examples/reference.py`
2. When done, rerun it.

**Expected:** on rerun, all elements fade out and then become opaque one by one even before the run is done.
**Actual:** on rerun, all elements fade out and only become opaque when the entire run is done.

I believe this bug was introduced with the Sidebar code.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/streamlit/watcher/LocalSourcesWatcher.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # Copyright 2018-2019 Streamlit Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import fnmatch
17 import os
18 import sys
19 import collections
20 
21 try:
22     # Python 2
23     import imp as importlib
24 except ImportError:
25     # Python 3
26     import importlib
27 
28 from streamlit import config
29 from streamlit import util
30 
31 from streamlit.logger import get_logger
32 
33 LOGGER = get_logger(__name__)
34 
35 try:
36     # If the watchdog module is installed.
37     from streamlit.watcher.EventBasedFileWatcher import (
38         EventBasedFileWatcher as FileWatcher,
39     )
40 except ImportError:
41     # Fallback that doesn't use watchdog.
42     from streamlit.watcher.PollingFileWatcher import PollingFileWatcher as FileWatcher
43 
44     if not config.get_option("global.disableWatchdogWarning"):
45         msg = "\n  $ xcode-select --install" if util.is_darwin() else ""
46 
47         LOGGER.warning(
48             """
49   For better performance, install the Watchdog module:
50   %s
51   $ pip install watchdog
52 
53         """
54             % msg
55         )
56 
57 
58 # Streamlit never watches files in the folders below.
59 DEFAULT_FOLDER_BLACKLIST = [
60     "**/.*",
61     "**/anaconda2",
62     "**/anaconda3",
63     "**/miniconda2",
64     "**/miniconda3",
65 ]
66 
67 
68 WatchedModule = collections.namedtuple("WatchedModule", ["watcher", "module_name"])
69 
70 
71 class LocalSourcesWatcher(object):
72     def __init__(self, report, on_file_changed):
73         self._report = report
74         self._on_file_changed = on_file_changed
75         self._is_closed = False
76 
77         self._folder_blacklist = config.get_option("server.folderWatchBlacklist")
78 
79         # Blacklist some additional folders, using glob syntax.
80         self._folder_blacklist.extend(DEFAULT_FOLDER_BLACKLIST)
81 
82         # A dict of filepath -> WatchedModule.
83         self._watched_modules = {}
84 
85         self._register_watcher(
86             self._report.script_path,
87             module_name=None,  # Only the root script has None here.
88         )
89 
90     def on_file_changed(self, filepath):
91         if filepath not in self._watched_modules:
92             LOGGER.error("Received event for non-watched file", filepath)
93             return
94 
95         wm = self._watched_modules[filepath]
96 
97         if wm.module_name is not None and wm.module_name in sys.modules:
98             del sys.modules[wm.module_name]
99 
100         self._on_file_changed()
101 
102     def close(self):
103         for wm in self._watched_modules.values():
104             wm.watcher.close()
105         self._watched_modules = {}
106         self._is_closed = True
107 
108     def _register_watcher(self, filepath, module_name):
109         wm = WatchedModule(
110             watcher=FileWatcher(filepath, self.on_file_changed), module_name=module_name
111         )
112         self._watched_modules[filepath] = wm
113 
114     def _deregister_watcher(self, filepath):
115         if filepath not in self._watched_modules:
116             return
117 
118         if filepath == self._report.script_path:
119             return
120 
121         wm = self._watched_modules[filepath]
122         wm.watcher.close()
123         del self._watched_modules[filepath]
124 
125     def update_watched_modules(self):
126         if self._is_closed:
127             return
128 
129         local_filepaths = []
130 
131         # Clone modules dict here because we may alter the original dict inside
132         # the loop.
133         modules = dict(sys.modules)
134 
135         for name, module in modules.items():
136             try:
137                 spec = getattr(module, "__spec__", None)
138 
139                 if spec is None:
140                     filepath = getattr(module, "__file__", None)
141                     if filepath is None:
142                         # Some modules have neither a spec nor a file. But we
143                         # can ignore those since they're not the user-created
144                         # modules we want to watch anyway.
145                         continue
146                 else:
147                     filepath = spec.origin
148 
149                 if filepath is None:
150                     # Built-in modules (and other stuff) don't have origins.
151                     continue
152 
153                 filepath = os.path.abspath(filepath)
154 
155                 if not os.path.isfile(filepath):
156                     # There are some modules that have a .origin, but don't
157                     # point to real files. For example, there's a module where
158                     # .origin is 'built-in'.
159                     continue
160 
161                 is_in_blacklisted_folder = any(
162                     _file_is_in_folder(filepath, blacklisted_folder)
163                     for blacklisted_folder in self._folder_blacklist
164                 )
165 
166                 if is_in_blacklisted_folder:
167                     continue
168 
169                 file_is_new = filepath not in self._watched_modules
170                 file_is_local = _file_is_in_folder(filepath, self._report.script_folder)
171 
172                 local_filepaths.append(filepath)
173 
174                 if file_is_local and file_is_new:
175                     self._register_watcher(filepath, name)
176 
177             except Exception:
178                 # In case there's a problem introspecting some specific module,
179                 # let's not stop the entire loop from running.  For example,
180                 # the __spec__ field in some modules (like IPython) is actually
181                 # a dynamic property, which can crash if the underlying
182                 # module's code has a bug (as discovered by one of our users).
183                 continue
184 
185         # Clone dict here because we may alter the original dict inside the
186         # loop.
187         watched_modules = dict(self._watched_modules)
188 
189         # Remove no-longer-depended-on files from self._watched_modules
190         # Will this ever happen?
191         for filepath in watched_modules:
192             if filepath not in local_filepaths:
193                 self._deregister_watcher(filepath)
194 
195 
196 def _file_is_in_folder(filepath, folderpath_glob):
197     # Strip trailing slash if it exists
198     if folderpath_glob.endswith("/"):
199         folderpath_glob = folderpath_glob[:-1]
200 
201     file_dir = os.path.dirname(filepath)
202     return fnmatch.fnmatch(file_dir, folderpath_glob)
203
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lib/streamlit/watcher/LocalSourcesWatcher.py b/lib/streamlit/watcher/LocalSourcesWatcher.py
--- a/lib/streamlit/watcher/LocalSourcesWatcher.py
+++ b/lib/streamlit/watcher/LocalSourcesWatcher.py
@@ -194,9 +194,13 @@
 
 
 def _file_is_in_folder(filepath, folderpath_glob):
-    # Strip trailing slash if it exists
-    if folderpath_glob.endswith("/"):
-        folderpath_glob = folderpath_glob[:-1]
-
-    file_dir = os.path.dirname(filepath)
+    # Make the glob always end with "/*" so we match files inside subfolders of
+    # folderpath_glob.
+    if not folderpath_glob.endswith("*"):
+        if folderpath_glob.endswith("/"):
+            folderpath_glob += "*"
+        else:
+            folderpath_glob += "/*"
+
+    file_dir = os.path.dirname(filepath) + "/"
     return fnmatch.fnmatch(file_dir, folderpath_glob)

{"golden_diff": "diff --git a/lib/streamlit/watcher/LocalSourcesWatcher.py b/lib/streamlit/watcher/LocalSourcesWatcher.py\n--- a/lib/streamlit/watcher/LocalSourcesWatcher.py\n+++ b/lib/streamlit/watcher/LocalSourcesWatcher.py\n@@ -194,9 +194,13 @@\n \n \n def _file_is_in_folder(filepath, folderpath_glob):\n-    # Strip trailing slash if it exists\n-    if folderpath_glob.endswith(\"/\"):\n-        folderpath_glob = folderpath_glob[:-1]\n-\n-    file_dir = os.path.dirname(filepath)\n+    # Make the glob always end with \"/*\" so we match files inside subfolders of\n+    # folderpath_glob.\n+    if not folderpath_glob.endswith(\"*\"):\n+        if folderpath_glob.endswith(\"/\"):\n+            folderpath_glob += \"*\"\n+        else:\n+            folderpath_glob += \"/*\"\n+\n+    file_dir = os.path.dirname(filepath) + \"/\"\n     return fnmatch.fnmatch(file_dir, folderpath_glob)\n", "issue": "On rerun, faded elements are becoming opaque one by one. Instead they become opaque all at once.\nSteps to repro:\r\n1. Run `examples/reference.py`\r\n2. When done, rerun it.\r\n\r\n**Expected:** on rerun, all elements fade out and then become opaque one by one even before the run is done.\r\n**Actual:** on rerun, all elements fade out and only become opaque when the entire run is done.\r\n\r\nI believe this bug was introduced with the Sidebar code.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# Copyright 2018-2019 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport fnmatch\nimport os\nimport sys\nimport collections\n\ntry:\n    # Python 2\n    import imp as importlib\nexcept ImportError:\n    # Python 3\n    import importlib\n\nfrom streamlit import config\nfrom streamlit import util\n\nfrom streamlit.logger import get_logger\n\nLOGGER = get_logger(__name__)\n\ntry:\n    # If the watchdog module is installed.\n    from streamlit.watcher.EventBasedFileWatcher import (\n        EventBasedFileWatcher as FileWatcher,\n    )\nexcept ImportError:\n    # Fallback that doesn't use watchdog.\n    from streamlit.watcher.PollingFileWatcher import PollingFileWatcher as FileWatcher\n\n    if not config.get_option(\"global.disableWatchdogWarning\"):\n        msg = \"\\n  $ xcode-select --install\" if util.is_darwin() else \"\"\n\n        LOGGER.warning(\n            \"\"\"\n  For better performance, install the Watchdog module:\n  %s\n  $ pip install watchdog\n\n        \"\"\"\n            % msg\n        )\n\n\n# Streamlit never watches files in the folders below.\nDEFAULT_FOLDER_BLACKLIST = [\n    \"**/.*\",\n    \"**/anaconda2\",\n    \"**/anaconda3\",\n    \"**/miniconda2\",\n    \"**/miniconda3\",\n]\n\n\nWatchedModule = collections.namedtuple(\"WatchedModule\", [\"watcher\", \"module_name\"])\n\n\nclass LocalSourcesWatcher(object):\n    def __init__(self, report, on_file_changed):\n        self._report = report\n        self._on_file_changed = on_file_changed\n        self._is_closed = False\n\n        self._folder_blacklist = config.get_option(\"server.folderWatchBlacklist\")\n\n        # Blacklist some additional folders, using glob syntax.\n        self._folder_blacklist.extend(DEFAULT_FOLDER_BLACKLIST)\n\n        # A dict of filepath -> WatchedModule.\n        self._watched_modules = {}\n\n        self._register_watcher(\n            self._report.script_path,\n            module_name=None,  # Only the root script has None here.\n        )\n\n    def on_file_changed(self, filepath):\n        if filepath not in self._watched_modules:\n            LOGGER.error(\"Received event for non-watched file\", filepath)\n            return\n\n        wm = self._watched_modules[filepath]\n\n        if wm.module_name is not None and wm.module_name in sys.modules:\n            del sys.modules[wm.module_name]\n\n        self._on_file_changed()\n\n    def close(self):\n        for wm in self._watched_modules.values():\n            wm.watcher.close()\n        self._watched_modules = {}\n        self._is_closed = True\n\n    def _register_watcher(self, filepath, module_name):\n        wm = WatchedModule(\n            watcher=FileWatcher(filepath, self.on_file_changed), module_name=module_name\n        )\n        self._watched_modules[filepath] = wm\n\n    def _deregister_watcher(self, filepath):\n        if filepath not in self._watched_modules:\n            return\n\n        if filepath == self._report.script_path:\n            return\n\n        wm = self._watched_modules[filepath]\n        wm.watcher.close()\n        del self._watched_modules[filepath]\n\n    def update_watched_modules(self):\n        if self._is_closed:\n            return\n\n        local_filepaths = []\n\n        # Clone modules dict here because we may alter the original dict inside\n        # the loop.\n        modules = dict(sys.modules)\n\n        for name, module in modules.items():\n            try:\n                spec = getattr(module, \"__spec__\", None)\n\n                if spec is None:\n                    filepath = getattr(module, \"__file__\", None)\n                    if filepath is None:\n                        # Some modules have neither a spec nor a file. But we\n                        # can ignore those since they're not the user-created\n                        # modules we want to watch anyway.\n                        continue\n                else:\n                    filepath = spec.origin\n\n                if filepath is None:\n                    # Built-in modules (and other stuff) don't have origins.\n                    continue\n\n                filepath = os.path.abspath(filepath)\n\n                if not os.path.isfile(filepath):\n                    # There are some modules that have a .origin, but don't\n                    # point to real files. For example, there's a module where\n                    # .origin is 'built-in'.\n                    continue\n\n                is_in_blacklisted_folder = any(\n                    _file_is_in_folder(filepath, blacklisted_folder)\n                    for blacklisted_folder in self._folder_blacklist\n                )\n\n                if is_in_blacklisted_folder:\n                    continue\n\n                file_is_new = filepath not in self._watched_modules\n                file_is_local = _file_is_in_folder(filepath, self._report.script_folder)\n\n                local_filepaths.append(filepath)\n\n                if file_is_local and file_is_new:\n                    self._register_watcher(filepath, name)\n\n            except Exception:\n                # In case there's a problem introspecting some specific module,\n                # let's not stop the entire loop from running.  For example,\n                # the __spec__ field in some modules (like IPython) is actually\n                # a dynamic property, which can crash if the underlying\n                # module's code has a bug (as discovered by one of our users).\n                continue\n\n        # Clone dict here because we may alter the original dict inside the\n        # loop.\n        watched_modules = dict(self._watched_modules)\n\n        # Remove no-longer-depended-on files from self._watched_modules\n        # Will this ever happen?\n        for filepath in watched_modules:\n            if filepath not in local_filepaths:\n                self._deregister_watcher(filepath)\n\n\ndef _file_is_in_folder(filepath, folderpath_glob):\n    # Strip trailing slash if it exists\n    if folderpath_glob.endswith(\"/\"):\n        folderpath_glob = folderpath_glob[:-1]\n\n    file_dir = os.path.dirname(filepath)\n    return fnmatch.fnmatch(file_dir, folderpath_glob)\n", "path": "lib/streamlit/watcher/LocalSourcesWatcher.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# Copyright 2018-2019 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport fnmatch\nimport os\nimport sys\nimport collections\n\ntry:\n    # Python 2\n    import imp as importlib\nexcept ImportError:\n    # Python 3\n    import importlib\n\nfrom streamlit import config\nfrom streamlit import util\n\nfrom streamlit.logger import get_logger\n\nLOGGER = get_logger(__name__)\n\ntry:\n    # If the watchdog module is installed.\n    from streamlit.watcher.EventBasedFileWatcher import (\n        EventBasedFileWatcher as FileWatcher,\n    )\nexcept ImportError:\n    # Fallback that doesn't use watchdog.\n    from streamlit.watcher.PollingFileWatcher import PollingFileWatcher as FileWatcher\n\n    if not config.get_option(\"global.disableWatchdogWarning\"):\n        msg = \"\\n  $ xcode-select --install\" if util.is_darwin() else \"\"\n\n        LOGGER.warning(\n            \"\"\"\n  For better performance, install the Watchdog module:\n  %s\n  $ pip install watchdog\n\n        \"\"\"\n            % msg\n        )\n\n\n# Streamlit never watches files in the folders below.\nDEFAULT_FOLDER_BLACKLIST = [\n    \"**/.*\",\n    \"**/anaconda2\",\n    \"**/anaconda3\",\n    \"**/miniconda2\",\n    \"**/miniconda3\",\n]\n\n\nWatchedModule = collections.namedtuple(\"WatchedModule\", [\"watcher\", \"module_name\"])\n\n\nclass LocalSourcesWatcher(object):\n    def __init__(self, report, on_file_changed):\n        self._report = report\n        self._on_file_changed = on_file_changed\n        self._is_closed = False\n\n        self._folder_blacklist = config.get_option(\"server.folderWatchBlacklist\")\n\n        # Blacklist some additional folders, using glob syntax.\n        self._folder_blacklist.extend(DEFAULT_FOLDER_BLACKLIST)\n\n        # A dict of filepath -> WatchedModule.\n        self._watched_modules = {}\n\n        self._register_watcher(\n            self._report.script_path,\n            module_name=None,  # Only the root script has None here.\n        )\n\n    def on_file_changed(self, filepath):\n        if filepath not in self._watched_modules:\n            LOGGER.error(\"Received event for non-watched file\", filepath)\n            return\n\n        wm = self._watched_modules[filepath]\n\n        if wm.module_name is not None and wm.module_name in sys.modules:\n            del sys.modules[wm.module_name]\n\n        self._on_file_changed()\n\n    def close(self):\n        for wm in self._watched_modules.values():\n            wm.watcher.close()\n        self._watched_modules = {}\n        self._is_closed = True\n\n    def _register_watcher(self, filepath, module_name):\n        wm = WatchedModule(\n            watcher=FileWatcher(filepath, self.on_file_changed), module_name=module_name\n        )\n        self._watched_modules[filepath] = wm\n\n    def _deregister_watcher(self, filepath):\n        if filepath not in self._watched_modules:\n            return\n\n        if filepath == self._report.script_path:\n            return\n\n        wm = self._watched_modules[filepath]\n        wm.watcher.close()\n        del self._watched_modules[filepath]\n\n    def update_watched_modules(self):\n        if self._is_closed:\n            return\n\n        local_filepaths = []\n\n        # Clone modules dict here because we may alter the original dict inside\n        # the loop.\n        modules = dict(sys.modules)\n\n        for name, module in modules.items():\n            try:\n                spec = getattr(module, \"__spec__\", None)\n\n                if spec is None:\n                    filepath = getattr(module, \"__file__\", None)\n                    if filepath is None:\n                        # Some modules have neither a spec nor a file. But we\n                        # can ignore those since they're not the user-created\n                        # modules we want to watch anyway.\n                        continue\n                else:\n                    filepath = spec.origin\n\n                if filepath is None:\n                    # Built-in modules (and other stuff) don't have origins.\n                    continue\n\n                filepath = os.path.abspath(filepath)\n\n                if not os.path.isfile(filepath):\n                    # There are some modules that have a .origin, but don't\n                    # point to real files. For example, there's a module where\n                    # .origin is 'built-in'.\n                    continue\n\n                is_in_blacklisted_folder = any(\n                    _file_is_in_folder(filepath, blacklisted_folder)\n                    for blacklisted_folder in self._folder_blacklist\n                )\n\n                if is_in_blacklisted_folder:\n                    continue\n\n                file_is_new = filepath not in self._watched_modules\n                file_is_local = _file_is_in_folder(filepath, self._report.script_folder)\n\n                local_filepaths.append(filepath)\n\n                if file_is_local and file_is_new:\n                    self._register_watcher(filepath, name)\n\n            except Exception:\n                # In case there's a problem introspecting some specific module,\n                # let's not stop the entire loop from running.  For example,\n                # the __spec__ field in some modules (like IPython) is actually\n                # a dynamic property, which can crash if the underlying\n                # module's code has a bug (as discovered by one of our users).\n                continue\n\n        # Clone dict here because we may alter the original dict inside the\n        # loop.\n        watched_modules = dict(self._watched_modules)\n\n        # Remove no-longer-depended-on files from self._watched_modules\n        # Will this ever happen?\n        for filepath in watched_modules:\n            if filepath not in local_filepaths:\n                self._deregister_watcher(filepath)\n\n\ndef _file_is_in_folder(filepath, folderpath_glob):\n    # Make the glob always end with \"/*\" so we match files inside subfolders of\n    # folderpath_glob.\n    if not folderpath_glob.endswith(\"*\"):\n        if folderpath_glob.endswith(\"/\"):\n            folderpath_glob += \"*\"\n        else:\n            folderpath_glob += \"/*\"\n\n    file_dir = os.path.dirname(filepath) + \"/\"\n    return fnmatch.fnmatch(file_dir, folderpath_glob)\n", "path": "lib/streamlit/watcher/LocalSourcesWatcher.py"}]}