Skip to content

[rustdoc] Fix storage usage when disabled - #61462

Merged
bors merged 1 commit into
rust-lang:masterfrom
GuillaumeGomez:fix-local-storage
Jul 12, 2019
Merged

bors merged 1 commit into
rust-lang:masterfrom
GuillaumeGomez:fix-local-storage

Conversation

@GuillaumeGomez

Copy link
Copy Markdown
Member

Fixes #61239.

@starblue: Can you give a try to this change please? I tried on chrome and firefox and both worked so if you're using another web browser, that might be useful. :)

r? @Manishearth

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 2, 2019
@starblue

starblue commented Jun 3, 2019

Copy link
Copy Markdown

I'm using Firefox 67.0.
I tried to build Rust, but stage 1 compilation of compiler artifacts failed, I can see that it was killed.
(I suppose that was by the OOM killer due to lack of memory, as the machine only has 8GB of which about 4GB are free. I've had similar problems before with a large svd2rust-generated crate.)
So I'll wait until the fix is in nightly and check that.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Hum, that's not very ideal. This fix is pretty simple but it'd have been nice to have a confirmation before actually merging it in case it was useless or not solving your issue.

@starblue

starblue commented Jun 3, 2019

Copy link
Copy Markdown

I finally managed to build it with -j 1, and I can report that the issue is indeed fixed. Thanks!

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Perfect, thanks! Just waiting for someone to review now.

cc @rust-lang/rustdoc

Comment thread src/librustdoc/html/static/storage.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the typeof window !== 'undefined' check for?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I'll update the code soon.

@ollie27

ollie27 commented Jun 4, 2019

Copy link
Copy Markdown
Contributor

It looks like this is actually quite tricky to get right. How about borrowing the code from https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#Testing_for_availability instead?

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

This code seems quite long to run (to be confirmed!). Saving its state should be enough though.

@ishitatsuyuki

Copy link
Copy Markdown
Contributor

Pro tip: when letting others test a build, you can @bors try then ask them to use https://github.com/kennytm/rustup-toolchain-install-master.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@ollie27: The code sample you linked checks too many things for us (like if the localStorage is full, which we don't really care in our case considering how little we use it). Checking if the localStorage exists is enough normally so I'll just fix the error you noticed.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@ishitatsuyuki Thanks for the tip!

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Updated.

@QuietMisdreavus

Copy link
Copy Markdown
Contributor

@ollie27: The code sample you linked checks too many things for us (like if the localStorage is full, which we don't really care in our case considering how little we use it). Checking if the localStorage exists is enough normally so I'll just fix the error you noticed.

According to the MDN page they linked, we may still get errors about localStorage being full, even with our relatively light usage of it:

One example of that is Safari, which in Private Browsing mode gives us an empty localStorage object with a quota of zero, effectively making it unusable.

Also, couldn't we move the final return line into the try block? It could even replace the current contents, since we're still accessing window.localStorage which would throw the exception.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Interesting. I'll check on safari to see its behaviour.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Also, couldn't we move the final return line into the try block? It could even replace the current contents, since we're still accessing window.localStorage which would throw the exception.

Excellent idea! I did it.

According to the MDN page they linked, we may still get errors about localStorage being full, even with our relatively light usage of it:
...

I tried on safari, both private and "normal" modes worked fine (I could set settings everything just fine).

@Dylan-DPC-zz

Copy link
Copy Markdown

ping from triage @Manishearth waiting for your review on this

@Manishearth

Copy link
Copy Markdown
Member

@bors r+

(note for triage: i'm helping out with rustdoc reviews, but please don't block rustdoc reviews on me)

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Nothing happened apparently? I'll close then reopen and give it another try.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@bors: r=Manishearth

@bors

bors commented Jul 12, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit 4eb19d1 has been approved by Manishearth

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 12, 2019
@bors

bors commented Jul 12, 2019

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 4eb19d1 with merge 71f9384...

bors added a commit that referenced this pull request Jul 12, 2019
[rustdoc] Fix storage usage when disabled

Fixes #61239.

@starblue: Can you give a try to this change please? I tried on chrome and firefox and both worked so if you're using another web browser, that might be useful. :)

r? @Manishearth
@bors

bors commented Jul 12, 2019

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-azure, checks-travis, status-appveyor
Approved by: Manishearth
Pushing 71f9384 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 12, 2019
@bors
bors merged commit 4eb19d1 into rust-lang:master Jul 12, 2019
@GuillaumeGomez
GuillaumeGomez deleted the fix-local-storage branch July 12, 2019 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust documentation doesn't show implementations when cookies / storage are disabled

9 participants