Skip to content

Build and load annotator bundle as a non-module script #4353

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

Merged
merged 2 commits into from
Mar 28, 2022

Conversation

robertknight
Copy link
Member

@robertknight robertknight commented Mar 25, 2022

Safari does not support loading module scripts in XHTML pages that are served
with the "application/xhtml" mime type [1]. This is very rare on the open web (XHTML
is rare and XHTML documents served with "application/xhtml" as opposed to
"text/html" as the MIME type are rarer still [2]) but more common in ebooks.

There is open issue for Chrome that says it has the same issue, yet in practice it seems that the client does load properly in Chrome and Firefox on an XHTML page. See #4350 (comment) for some test pages.

[1] https://bugs.webkit.org/show_bug.cgi?id=227469
[2] https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/XHTML#xhtml_document


TODO:

@robertknight
Copy link
Member Author

This change may annoyingly get in the way of lazily loading annotator functionality via dynamic import. I need to test whether that is affected by this issue or not.

@lyzadanger lyzadanger self-requested a review March 28, 2022 13:53
Safari does not support loading module scripts in XHTML pages that are served
with the "application/xhtml" mime type [1]. This is very rare on the open web (XHTML
is rare and XHTML documents served with "application/xhtml" as opposed to
"text/html" as the MIME type are rarer still [2]) but more common in ebooks.

This partly fixes #4350.

[1] https://bugs.webkit.org/show_bug.cgi?id=227469
[2] https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/XHTML#xhtml_document
As noted in [1], much (most?) XHTML content on the web is actually
served with the "text/html" mime type, including the existing documens in the
dev server which declare themselves to be XHTML. However serving an
XHTML document with the correct "application/xhtml+xml" mime type alters
various browser behavior, so we need a page that tests this.

[1] https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/XHTML#xhtml_document
@robertknight robertknight force-pushed the load-annotator-bundle-as-classic-script branch from 233f348 to a898c4c Compare March 28, 2022 14:40
@robertknight
Copy link
Member Author

I added a test page at http://localhost:3000/document/xhtml-test. Visit this page in Safari, Firefox and Chrome and verify that the client loads and the adder appears when text is selected.

@codecov
Copy link

codecov bot commented Mar 28, 2022

Codecov Report

Merging #4353 (a898c4c) into master (ac9bf46) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #4353      +/-   ##
==========================================
- Coverage   99.17%   99.16%   -0.02%     
==========================================
  Files         225      225              
  Lines        8588     8596       +8     
  Branches     2030     2028       -2     
==========================================
+ Hits         8517     8524       +7     
- Misses         71       72       +1     
Impacted Files Coverage Δ
src/boot/boot.js 98.63% <100.00%> (-1.37%) ⬇️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

bundleConfig({ name: 'annotator', entry: 'src/annotator/index.js' }),
bundleConfig({
name: 'annotator',
entry: 'src/annotator/index.js',
Copy link
Contributor

Choose a reason for hiding this comment

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

OK, this makes sense. Only the annotator bundle needs to be iife as we have control over the sidebar frame's MIME- and document-types.

Copy link
Contributor

@lyzadanger lyzadanger left a comment

Choose a reason for hiding this comment

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

This works in Safari, FireFox and Chrome in the test page provided. I had one question about forceReload.

* in case it has been loaded in the same document previously.
* @param {object} options
* @param {boolean} [options.esModule] - Whether to load the script as an ES module
* @param {boolean} [options.forceReload] - Whether to force re-evaluation of an ES module script
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not seeing this option actually used (i.e. set to true) anywhere anymore? Is it still relevant?

Copy link
Member Author

Choose a reason for hiding this comment

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

forceReload is not actually used anywhere currently. I was on the fence about removing it. On the one hand it is not currently used. On the other it is a useful reminder of how to force a module script reload if needed.

@robertknight robertknight merged commit 41f123a into master Mar 28, 2022
@robertknight robertknight deleted the load-annotator-bundle-as-classic-script branch March 28, 2022 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants