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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add optional polyfill for crypto.randomUUID #8109

Merged
merged 3 commits into from
Aug 12, 2022
Merged

fix: add optional polyfill for crypto.randomUUID #8109

merged 3 commits into from
Aug 12, 2022

Conversation

runspired
Copy link
Contributor

resolves #8097
resolves #8106

To use the polyfill:

let app = new EmberApp(defaults, {
  '@embroider/macros': {
    setConfig: {
      '@ember-data/store': {
        polyfillUUID: true
      },
    },
  },
});

@runspired runspired requested a review from ef4 August 9, 2022 08:30
@runspired runspired added 🎯 beta PR should be backported to beta 🎯 release PR should be backported to release 🎯 canary PR is targeting canary (default) 🏷️ bug This PR primarily fixes a reported issue labels Aug 9, 2022
@law-rence
Copy link
Contributor

Thank you very much for the quick solution!

Copy link
Contributor

@ef4 ef4 left a comment

Choose a reason for hiding this comment

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

This looks good to me.

It's also possible for @ember-data/store to set its own macro config based off it's own decisions, like checking for the presence of a package or some other ember-data-specific configuration. But exposing the macros config directly to users is also supported and avoids the need for a lot of extra code.

@github-actions
Copy link

Asset Size Report for 9993d55

Modern Builds

☑️ EmberData has not changed in size

If any packages had changed sizes they would be listed here.

Changeset



Full Asset Analysis (Modern)

Asset Size Report
=================


Library: EmberData
┌────────────┬─────────────┐
│  (index)   │   Values    │
├────────────┼─────────────┤
│   bytes    │ '167.62 KB' │
│ compressed │ '35.12 KB'  │
│  packages  │      8      │
│  modules   │     44      │
└────────────┴─────────────┘

Package: @ember-data/model
┌──────────────┬────────────┐
│   (index)    │   Values   │
├──────────────┼────────────┤
│    bytes     │ '45.74 KB' │
│  compressed  │ '9.58 KB'  │
│ % Of Library │   '27.3'   │
└──────────────┴────────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	@ember-data/model/-private                        | 45.26 KB  | 9.48 KB    | 99.0          | 27.0
	@ember-data/model/index                           | 486.00 B  | 101.82 B   | 1.0           | 0.3

Package: @ember-data/store
┌──────────────┬────────────┐
│   (index)    │   Values   │
├──────────────┼────────────┤
│    bytes     │ '43.39 KB' │
│  compressed  │ '9.09 KB'  │
│ % Of Library │   '25.9'   │
└──────────────┴────────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	@ember-data/store/-private                        | 42.39 KB  | 8.88 KB    | 97.7          | 25.3
	@ember-data/store/index                           | 1022.00 B | 214.12 B   | 2.3           | 0.6

Package: @ember-data/record-data
┌──────────────┬────────────┐
│   (index)    │   Values   │
├──────────────┼────────────┤
│    bytes     │ '24.05 KB' │
│  compressed  │ '5.04 KB'  │
│ % Of Library │   '14.4'   │
└──────────────┴────────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	@ember-data/record-data/-private                  | 24.05 KB  | 5.04 KB    | 100.0         | 14.4

Package: @ember-data/serializer
┌──────────────┬────────────┐
│   (index)    │   Values   │
├──────────────┼────────────┤
│    bytes     │ '20.42 KB' │
│  compressed  │ '4.28 KB'  │
│ % Of Library │   '12.2'   │
└──────────────┴────────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	@ember-data/serializer/json                       | 7.36 KB   | 1.54 KB    | 36.0          | 4.4
	@ember-data/serializer/-private                   | 5.60 KB   | 1.17 KB    | 27.4          | 3.3
	@ember-data/serializer/json-api                   | 3.79 KB   | 813.14 B   | 18.6          | 2.3
	@ember-data/serializer/rest                       | 2.87 KB   | 614.72 B   | 14.0          | 1.7
	@ember-data/serializer/index                      | 611.00 B  | 128.01 B   | 2.9           | 0.4
	@ember-data/serializer/transform                  | 215.00 B  | 45.04 B    | 1.0           | 0.1

Package: @ember-data/adapter
┌──────────────┬────────────┐
│   (index)    │   Values   │
├──────────────┼────────────┤
│    bytes     │ '15.93 KB' │
│  compressed  │ '3.34 KB'  │
│ % Of Library │   '9.5'    │
└──────────────┴────────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	@ember-data/adapter/rest                          | 7.88 KB   | 1.65 KB    | 49.5          | 4.7
	@ember-data/adapter/-private                      | 3.79 KB   | 812.09 B   | 23.8          | 2.3
	@ember-data/adapter/error                         | 1.82 KB   | 390.96 B   | 11.4          | 1.1
	@ember-data/adapter/index                         | 1.41 KB   | 302.96 B   | 8.9           | 0.8
	@ember-data/adapter/json-api                      | 1.03 KB   | 221.87 B   | 6.5           | 0.6

Package: ember-data
┌──────────────┬───────────┐
│   (index)    │  Values   │
├──────────────┼───────────┤
│    bytes     │ '8.66 KB' │
│  compressed  │ '1.81 KB' │
│ % Of Library │   '5.2'   │
└──────────────┴───────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	ember-data/index                                  | 2.11 KB   | 452.35 B   | 24.4          | 1.3
	ember-data/-private                               | 1.75 KB   | 374.82 B   | 20.2          | 1.0
	ember-data/adapters/errors                        | 1.19 KB   | 254.98 B   | 13.7          | 0.7
	ember-data/setup-container                        | 368.00 B  | 77.10 B    | 4.2           | 0.2
	ember-data/relationships                          | 318.00 B  | 66.62 B    | 3.6           | 0.2
	ember-data/serializers/embedded-records-mixin     | 274.00 B  | 57.40 B    | 3.1           | 0.2
	ember-data/serializers/json-api                   | 251.00 B  | 52.58 B    | 2.8           | 0.1
	ember-data/adapters/json-api                      | 245.00 B  | 51.33 B    | 2.8           | 0.1
	ember-data/serializers/json                       | 243.00 B  | 50.91 B    | 2.7           | 0.1
	ember-data/serializers/rest                       | 243.00 B  | 50.91 B    | 2.7           | 0.1
	ember-data/transform                              | 241.00 B  | 50.49 B    | 2.7           | 0.1
	ember-data/adapters/rest                          | 237.00 B  | 49.65 B    | 2.7           | 0.1
	ember-data/serializer                             | 232.00 B  | 48.60 B    | 2.6           | 0.1
	ember-data/adapter                                | 226.00 B  | 47.35 B    | 2.5           | 0.1
	ember-data/model                                  | 222.00 B  | 46.51 B    | 2.5           | 0.1
	ember-data/store                                  | 222.00 B  | 46.51 B    | 2.5           | 0.1
	ember-data/attr                                   | 218.00 B  | 45.67 B    | 2.5           | 0.1
	ember-data/version                                | 161.00 B  | 33.73 B    | 1.8           | 0.1

Package: ember-inflector
┌──────────────┬───────────┐
│   (index)    │  Values   │
├──────────────┼───────────┤
│    bytes     │ '6.67 KB' │
│  compressed  │ '1.40 KB' │
│ % Of Library │   '4.0'   │
└──────────────┴───────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	ember-inflector/lib/system/inflector              | 2.96 KB   | 635.67 B   | 44.4          | 1.8
	ember-inflector/lib/system/inflections            | 1.59 KB   | 340.88 B   | 23.8          | 0.9
	ember-inflector/lib/system                        | 471.00 B  | 98.68 B    | 6.9           | 0.3
	ember-inflector/index                             | 379.00 B  | 79.40 B    | 5.6           | 0.2
	ember-inflector/lib/helpers/pluralize             | 369.00 B  | 77.31 B    | 5.4           | 0.2
	ember-inflector/lib/utils/make-helper             | 332.00 B  | 69.55 B    | 4.9           | 0.2
	ember-inflector/lib/system/string                 | 318.00 B  | 66.62 B    | 4.7           | 0.2
	ember-inflector/lib/helpers/singularize           | 296.00 B  | 62.01 B    | 4.3           | 0.2

Package: @ember-data/debug
┌──────────────┬────────────┐
│   (index)    │   Values   │
├──────────────┼────────────┤
│    bytes     │ '2.77 KB'  │
│  compressed  │ '593.56 B' │
│ % Of Library │   '1.7'    │
└──────────────┴────────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	@ember-data/debug/index                           | 2.27 KB   | 487.75 B   | 82.2          | 1.4
	@ember-data/debug/setup                           | 505.00 B  | 105.80 B   | 17.8          | 0.3

Modern Builds (No Rollup)

☑️ EmberData has not changed in size

If any packages had changed sizes they would be listed here.

Changeset



Full Asset Analysis (Modern)

Asset Size Report
=================


Library: EmberData
┌────────────┬──────────┐
│  (index)   │  Values  │
├────────────┼──────────┤
│   bytes    │ '0.00 B' │
│ compressed │ '1.00 B' │
│  packages  │    0     │
│  modules   │    0     │
└────────────┴──────────┘

@github-actions
Copy link

Performance Report for 9993d55

Scenario - materialization: ☑️ Performance is stable

☑️ duration
phase no difference [-14ms to 15ms]
☑️ Phase [navigationStart] => [start-find-all]
phase no difference [-3ms to 4ms]
☑️ Phase [start-find-all] => [start-materialization]
phase no difference [-6ms to 7ms]
☑️ Phase [start-materialization] => [end-materialization]
phase no difference [-3ms to 5ms]
☑️ Phase [end-materialization] => [Test End]
phase no difference [0ms to 0ms]

Scenario - unload: ☑️ Performance is stable

☑️ duration
phase no difference [-12ms to 32ms]
☑️ Phase [navigationStart] => [start-push-payload]
phase no difference [-9ms to 18ms]
☑️ Phase [start-push-payload] => [start-unload-records]
phase no difference [-5ms to 17ms]
☑️ Phase [start-unload-records] => [end-unload-records]
phase no difference [-4ms to 2ms]
☑️ Phase [end-unload-records] => [Test End]
phase no difference [0ms to 0ms]

Scenario - destroy: ☑️ Performance is stable

☑️ duration
phase no difference [-32ms to 16ms]
☑️ Phase [navigationStart] => [start-push-payload]
phase no difference [-18ms to 9ms]
☑️ Phase [start-push-payload] => [start-destroy-records]
phase no difference [-13ms to 8ms]
☑️ Phase [start-destroy-records] => [end-destroy-records]
phase no difference [-3ms to 5ms]
☑️ Phase [end-destroy-records] => [Test End]
phase no difference [0ms to 0ms]

Scenario - add-children: ☑️ Performance is stable

☑️ duration
phase no difference [-21ms to 8ms]
☑️ Phase [navigationStart] => [start-push-initial-payload]
phase no difference [-15ms to 13ms]
✅ Phase [start-push-initial-payload] => [start-push-update-payload]
phase estimated improvement -4ms [-7ms to -1ms] OR -1.66% [-3.07% to -0.56%]
☑️ Phase [start-push-update-payload] => [end-push-update-payload]
phase no difference [-3ms to 0ms]
☑️ Phase [end-push-update-payload] => [Test End]
phase no difference [0ms to 0ms]

Scenario - unused-relationships: ☑️ Performance is stable

☑️ duration
phase no difference [-8ms to 26ms]
☑️ Phase [navigationStart] => [start-push-payload]
phase no difference [-8ms to 19ms]
☑️ Phase [start-push-payload] => [end-push-payload]
phase no difference [-2ms to 10ms]
☑️ Phase [end-push-payload] => [Test End]
phase no difference [0ms to 1ms]

@runspired runspired merged commit 3fcb2e8 into master Aug 12, 2022
@delete-merged-branch delete-merged-branch bot deleted the fix/uuid branch August 12, 2022 08:47
@runspired runspired changed the title add optional polyfill fix: add optional polyfill for crypto.randomUUID Aug 12, 2022
runspired added a commit that referenced this pull request Aug 23, 2022
@jrjohnson jrjohnson removed the 🎯 release PR should be backported to release label Aug 25, 2022
@luxzeitlos
Copy link
Contributor

Shouldnt this be the default? IMHO removing the support for insecure contexts without a changed configuration is kinda a breaking change 🤔

At least we should have a better error message, helping how to avoid this issue.

@runspired
Copy link
Contributor Author

@luxferresum opened #8301 for this ^

@gzurbach
Copy link

I spent a couple hours this morning trying to enable the polyfill as described above, until I realized that I needed to install @embroider/macros as well in my app:

npm i @embroider/macros --save-dev

It may seem obvious to some, but not to me. So I am adding this here for anyone else encountering the same issue :)

@runspired
Copy link
Contributor Author

@gzurbach yeah, you only need to do that if we don't forward the config (which we should do). Haven't had time to work on that but if you do it would be hugely appreciated, shouldn't be too complicated we already forward the configs for near everything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎯 beta PR should be backported to beta 🎯 canary PR is targeting canary (default) 🏷️ bug This PR primarily fixes a reported issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

_crypto.randomUUID is not a function uuid generation broken for insecure contexts
6 participants