Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved hasNativeStartsWith check #4130

Merged
merged 1 commit into from Jul 16, 2023
Merged

Conversation

apolakipso
Copy link
Contributor

@apolakipso apolakipso commented Jun 13, 2023

There are JS environments where String.startsWith exists but doesn't support the position parameter (e.g. in the taskpane of Outlook web add-ins). This commit adds a test for proper handling of position to the polyfill check.

Note: Turns out this broken polyfill comes with Microsoft's Office JS API in https://ajax.aspnetcdn.com/ajax/3.5/MicrosoftAjax.js 馃槺

Here's a regular Chrome dev console:

image
image

Here's the behavior in the dev console of an Outlook add-in:

image
image

This is how it breaks formatjs in an Outlook add-in taskpane:

A simple message with tags:

<FormattedMessage id="test" defaultMessage="<b>test</b>" />

The broken startsWith implementation breaks the parser. parseTag() throws INVALID_TAG because startsWith used in bumpIf() requires a proper handling of the position parameter (this.offset() in this case).

utils.js:20  Error: [@formatjs/intl Error FORMAT_ERROR] Error formatting default message for: "test", rendering default message verbatim
MessageID: test
Default Message: <b>test</b>
Description: undefined

Locale: en


INVALID_TAG
SyntaxError: INVALID_TAG (at error.js:58:1)
    at Function.parse [as __parse] (index.js:33:1)
    at new IntlMessageFormat (core.js:137:1)
    at utils.js:110:1
    at variadic (index.js:33:1)
    at formatMessage (message.js:69:1)
    at formatMessage (provider.js:46:18)
    at FormattedMessage (message.js:21:1)
    at renderWithHooks (react-dom.development.js:16305:1)
    at mountIndeterminateComponent (react-dom.development.js:20074:1)
    at beginWork (react-dom.development.js:21587:1)
    at MessageFormatError.IntlFormatError [as constructor] (error.js:58:1)
    at new MessageFormatError (error.js:68:1)
    at formatMessage (message.js:73:1)
    at formatMessage (provider.js:46:18)
    at FormattedMessage (message.js:21:1)
    at renderWithHooks (react-dom.development.js:16305:1)
    at mountIndeterminateComponent (react-dom.development.js:20074:1)
    at beginWork (react-dom.development.js:21587:1)
    at beginWork$1 (react-dom.development.js:27426:1)
    at performUnitOfWork (react-dom.development.js:26560:1)

There are JS environments where String.startsWith() exists but doesn't support the `position` parameter (e.g. in the taskpane of Outlook web add-ins). This check ensures a version of startsWith() is present that *does* support the position parameter.
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Jul 15, 2023
@longlho longlho merged commit 75d60b5 into formatjs:main Jul 16, 2023
1 check passed
@longlho
Copy link
Member

longlho commented Jul 16, 2023

Thanks a lot for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants